@mloubser I’m currently using Elixir code to run a Phoenix HTTP server. As seen below, I’m creating the proper structure to be returned and JSON encoding it.
Here are the outputs from my code:
Struct: %{events: [], responses: [%{text: "Hello world from server"}]}
Json string: "{\"responses\":[{\"text\":\"Hello world from server\"}],\"events\":[]}"
chat_action
is the entry point of the HTTP request
def chat_action(conn, body = _params) do
case Rasa.handle_action(body) do
nil ->
send_resp(conn, 400, "error")
result ->
response = Poison.encode!(result)
put_resp_header(conn, "content-type", "application/json")
send_resp(conn, 200, response)
end
end
def handle_action(message) do
case Map.get(message, "next_action") do
nil ->
Logger.error("[rasa] no action")
nil
"action_test" ->
%{
responses: [construct_response("Hello world from server")],
events: []
}
end
end
def construct_response(text) do
%{
text: text
}
end