Skip to content

Instantly share code, notes, and snippets.

@zabirauf
Last active June 15, 2016 05:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zabirauf/af4cb9318d99007132528f45c170df01 to your computer and use it in GitHub Desktop.
Save zabirauf/af4cb9318d99007132528f45c170df01 to your computer and use it in GitHub Desktop.
Messages controller that receives message from user and sends it to Wit. Complete project at https://github.com/zabirauf/witai_elixir_weather_bot
defmodule EchoBot.MessagesController do
use MicrosoftBot.Phoenix.Controller
alias ExMicrosoftBot.Models.Message
def message_received(conn, %Message{} = message) do
session_id = message.conversationId
spawn fn ->
%{from: from, to: to, id: msgId} = message
context = %{"session" => %{
"from" => from,
"to" => to,
"msgId" => msgId}}
Wit.run_actions(get_wit_access_token, session_id, EchoBot.WeatherConversationAction, message.text, context, 10)
end
resp(conn, 200, "")
end
defp get_wit_access_token() do
Application.get_env(:koinbot, :wit_access_token)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment