Hubot Messenger Platform Adapter
Facebook has just announced its new platform for messenger. This is a hubot adapter for the new bot api.
Installation
npm install --save hubot-messenger-platform
Requirement
- For this to work you'll need the following:
- Facebook page.
- Facbook Group.
- Reverse proxy with SSL setup ( i.e Nginx + letsencrypt ).
Steps
- Create the facebook page if you don't have one.
- Create the facebook app if you don't have one.
- Generate a random verification token of any length and note it with you.
- From the facebook app's setting, go to the new messenger tab. In the token generation part, choose your page and note the page access token.
- Start your bot with
HUBOT_MESSENGER_VERIFICATION_TOKEN=<verification_code> HUBOT_MESSENGER_PAGE_ACCESS_TOKEN=<page_access_code> ./bin/hubot -a messenger-platform -n ""
. - In the messenger's tab webhook section, add a new webhook. The endpoint should be
https://<your_domain>/webhook
. Choose all the events and verify. - Execute
curl -ik -X POST "https://graph.facebook.com/v2.6/me/subscribed_apps?access_token=<page_access_token>"
to subscribe your app to get updates from this page.
And Done. Now whenever you send a message to your bot's page inbox, hubot will process it and send the response back.
For more info, check facebook's official guide.
Configuartions
- The FB API supports only 320 chars per message. The adapter truncates the message and appends
...
by default. If you want the adapter to split the message into several lines
Important Notes
- The server should be running a reverse proxy that forwards the https traffic after SSL termination to
http://localhost:8080
assuming that the reverse proxy is running on the same host as hubot. If you started hubot specifying thePORT
env var, this will override the default8080
port. - Self signed certificates won't be accepted by facebook. Letsencrypt certificates works perfectly.
- The
-n ""
flag when starting hubot, doesn't give the bot a name. So instead of sendingHubot ping
to it, you'll just sendping
. - The FB API supports only 320 chars responses. . If you want hubot to split the long message on
Contributions
Your contributions are welcome through pull requests or issues.