Last active
June 15, 2016 05:06
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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