PhoenixFacebookMessenger
Phoenix Facebook Messenger is a library that easy the creation of facebook messenger bots.
Installation
def deps do
[{:phoenix_facebook_messenger, "~> 0.2.0"}]
endRequirements
-
a Phoenix App with phoenix
1.1and up
Usage
With Phoenix
You need to have a working phoenix app to use phoenix_facebook_messenger.
To create an echo back bot, do the following:
Create a new controller web/controller/test_controller.ex
defmodule TestController do
use FacebookMessenger.Phoenix.Controller
def message_received(msg) do
text = FacebookMessenger.Response.message_texts(msg) |> hd
sender = FacebookMessenger.Response.message_senders(msg) |> hd
FacebookMessenger.Sender.send(sender, text)
end
end
Add the required routes in web/router.ex
defmodule YourApp.Router do
use YourApp.Web, :router
# Add these two lines
use FacebookMessenger.Phoenix.Router
facebook_routes "/api/webhook", TestController
end
This defines a webhook endpoint at:
http://your-app-url/api/webhook
Go to your config/config.exs and add the required configurations
config :facebook_messenger,
facebook_page_token: "Your facebook page token",
challenge_verification_token: "the challenge verify token"
To get the facebook_page_token and challenge_verification_token follow the instructions here
For the webhook endpoint use http://your-app-url/api/webhook
With plug
If you use plug in your project, then you need the plug version of facebook_messenger this can be found at found here.
Sample
- A sample facebook echo bot with plug can be found here. https://github.com/oarrabi/plug_facebook_echo_bot
- For the phoenix echo bot, https://github.com/oarrabi/phoenix_facebook_echo_bot