This repo contains a node app that can be the baseline for enhancing your Twilio Autopilot with extra Facebook Messenger features like Cards, Quick Replies, Postbacks and Images. It is basically a middleware that analyses the incoming payload and decides what type of element was sent in the chat. It can be enhanced to manage more payloads and channels.
The main structure is as follows:
- app.js : the main file that starts the server
- config/express.js : the middleware app with the webhooks needed
- payload/payload.js: Takes the payload from the Twilio integration point and decides the type of the message
- handlers/handlers.js: Takes the output from payload.js and depending on the type of message takes appropriate action (functions here should be defined based on business needs)
- tests/tests.js: Code that generates cards carrousel and quick replies
HOW TO RUN:
npm install //Installs the dependencies
npm start //Starts the app
- ngrok on port 4000 (default or set yours)
- Set the ngrok path as "NGROK_URL/webhook" on Twilio-Messenger callback URL (under your project Channels https://www.twilio.com/console/channels)
- Create the webhook on developers.facebook.com for the Messenger page you have created for the bot Verify URL will be "NGROK_URL/messenger/webhook" and the token is defined in your .env (copy and paste it there)
- On your webhook on developers.facebook.com subscribe only to the messages_postbacks to avoid getting 2 payloads for simple text messages (both from the integration and facebook directly)
Here you can find the relevant blog post that describes the install process and the expected results: https://www.twilio.com/blog/autopilot-facebook-messenger-enhancements-node