Bot Orchestration Framework Built on Elixir/Phoenix

Who's Olivia?
I named the framework Olivia. Olivia was strongly inspired by Justus Eapen’s Virtuoso. Olivia is designed to support a conversation with IBM Watson Assistant or Wit. You can use Facebook Messenger, or a WebApp and connect using webhook or socket.
The source code you can find here.
Create a Project
First, you must create a new project. Let’s call it my_project.
mix phx.new <my_project>
cd <my_project> Add Olivia and Poison to your my_project project in the mix.exs file.
{:olivia, git: "https://github.com/marceloreichert/olivia.git"}
{:poison, "~> 3.1 }Update the dependencies: mix deps.get.
Setting Up Your Project
Olivia lets you use 3 different interface types: Facebook Messenger, a WebApp with webhook, and a WebApp with channels.
If you use Facebook Messenger, you need to include routes to webhook. The same webhook should be set up in your Facebook Messenger.
pipeline :webhook_fb_messenger do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_flash
plug :put_secure_browser_headers
endscope "/chat/messenger", OliviaWeb.Chat do
pipe_through :webhook_fb_messenger
get "/", MessengerController, :verify
post "/", MessengerController, :create
end
If you decide to use your own WebApp with webhook, add this webhook to router:
pipeline :webhook_webapp do
plug :accepts, ["json"]
end
scope "/chat/webapp", OliviaWeb.Chat do
pipe_through :webhook_webapp
post "/", WebAppController, :create
endIf you decide to use your own WebApp with channels, add socket config to endpoint:
scope "/chat/webapp", OliviaWeb.Chat do
pipe_through :webhook_webapp
post "/", WebAppController, :create
endNow, add new file /lib/<project_name>/orchestra.ex. In this file you can trap the message and manipulate without going through any NLP.
defmodule <MyProject>.Orchestra do
def run(impression) do
impression
end
endAt the end of the file config/dev.exs, add a call to add the environment variables.
# config/dev.exs...import_config "dev.secret.exs"
Now add the dev.secret.exs file. Note that you need to decide whether to use nlp :watson_assistant or :wit. And add the login data of your Facebook Messenger, Watson or Wit.
use Mix.Config
config :olivia,
fb_page_recipient_id: "",
fb_page_access_token: "",
wit_server_access_token: "",
watson_assistant_id: "",
watson_assistant_token: "",
watson_assistant_version: "",
default_nlp: :watson_assistant or :wit,
bot_name: <MyProject>Running
With everything set up, now just get our bot to work.
mix ecto.create
mix phx.serverHow it works?
The entry point is the entry.ex files in lib/olivia/chat/interface/ fb_messenger ou web_app. With the input data from the interface we go through processing phases until returning a response to the interface. We have the Translation, Conversation, Thinker andDispatcher modules.
Example:
payload
|> Translation.process_messages
|> Conversation.received_message
|> Thinker.run
|> Dispatcher.build_response(sender_id, token)Translation (Olivia.Chat.Interface.FbMessenger.Translation)
Receives raw message from Messenger or WebApp interface and stores it in a struct %Impression{}.
Conversation (Olivia.Chat.Conversation)
Uses GenServer to maintain conversation state.
Thinker (Olivia.Chat.Thinker)
Responsible for calling Olivia.Chat.Thinker.WatsonAssistant.Thinking, ou Olivia.Chat.Thinker.Wit.Thinking module and according to the interface configuration you are using. Send Watson the incoming message and get back the intention, the entities involved and the response.
Dispatcher (Olivia.Chat.Interface.FbMessenger.Dispatcher)
Handles POST requests that return the response to Facebook Messenger.
For everything to work you also need to have an IBM account, and Assistant is set up to answer your questions.
Now I need help adding tests and new interfaces and new NLPs.
See you next.

