LoginSignup
1
1

More than 5 years have passed since last update.

Elixirでドコモの雑談APIをワンライナーで叩く方法

Last updated at Posted at 2017-07-15

Elixirでドコモの雑談APIを叩く方法

ドコモの雑談API

コマンドライン呼び出し

iex -S mix

肝心のワンライナー

HTTPoisonのライブラリが使用されている場合に使用可能です。

HTTPoison.post "https://api.apigw.smt.docomo.ne.jp/dialogue/v1/dialogue?APIKEY=ドコモのAPIKeyを入力", "{\"utt\": \"こんにちは\", \"context\": \"s7e6x0JUIOihXrbNJ3qwSQ\" }", [{"Content-Type", "application/json"}

使用方法

uttの部分をこんにちは以外の文字列に変更して話をする。

下記のようなレスポンスが返ってきます。

 %HTTPoison.Response{body: "{\"utt\":\"こんにちはなでなで\",\"yomi\":\"こんにちはなでなで\",\"mode\":\"dialog\",\"da\":\"0\",\"context\":\"s7e6x0JUIOihXrbNJ3qwSQ\"}"

httpoisonのライブラリだけ使用する場合のmix.exs サンプル

mix.exs
defmodule Docomo.Mixfile do
  use Mix.Project

  def project do
    [app: :docomo,
     version: "0.1.0",
     elixir: "~> 1.4",
     build_embedded: Mix.env == :prod,
     start_permanent: Mix.env == :prod,
     deps: deps()]
  end

  # Configuration for the OTP application
  #
  # Type "mix help compile.app" for more information
  def application do
    # Specify extra applications you'll use from Erlang/Elixir
    [extra_applications: [:logger ,:httpoison]]
  end

  # Dependencies can be Hex packages:
  #
  #   {:my_dep, "~> 0.3.0"}
  #
  # Or git/path repositories:
  #
  #   {:my_dep, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
  #
  # Type "mix help deps" for more examples and options
  defp deps do
    [{:httpoison, "~> 0.12"}]
  end
end
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1