Skip to content
This repository has been archived by the owner on Nov 26, 2019. It is now read-only.

Channel Messenger

Floren Henri edited this page Dec 5, 2016 · 11 revisions

Set up your Facebook page

Start by creating your page.

alt text

  • Choose the category of your page
  • Fill out the Facebook requirements step by step

alt text

Set up your Facebook account

  • Log on to your Facebook Developers account
  • Create a new Facebook app

alt text

  • Get your app secret and ID from the Dashboard

alt text

alt text

Start Connector in local

  • Clone and install Connector
$ git clone https://github.com/RecastAI/bot-connector.git
$ cd bot-connector
$ yarn install
$ yarn start-dev
  • Create your bot
$ curl -X POST "http://localhost:8080/bots/" --data "url=YOUR_BOT_URL"
  • Create you channel
$ curl -X  POST \
  --data "slug=YOUR_CHANNEL_SLUG" --data "isActivated=true" --data "type=messenger" \
  --data "apiKey=YOUR_API_KEY" --data "webhook=YOUR_NGROK_URL" --data "token=YOUR_MESSENGER_TOKEN" \
  "http://localhost:8080/bots/:bot_id/channels"

Ngrok

  • Download the appropriate version of Ngrok.
  • Open a new tab in your terminal:
./ngrok http 8080
  • Copy past the https://*******ngrok.io you get, you will need it for the next step.
  • Leave your Ngrok serveur running.

Config webhook

  • go back to the Facebook Developer page and add a new webhook.

alt text

  • Subscribe your page to the webhook you just created.
  • Your token is the slug of your bot.

alt text

Your bot

  • A small bot example:
 import express from 'express'
 import bodyParser from 'body-parser'
 import request from 'superagent'
 
 const app = express()
 app.set('port', process.env.PORT || 5000)
 app.use(bodyParser.json())
 
 const config = { url: 'http://localhost:8080', botId: 'yourBotId' }
 
   /* Get the request from the connector */
 
   app.post('/', (req, res) => {
     const conversationId = req.body.message.conversation
       const messages = [{
         type: 'text',
         content: 'my first message',
       }]
 
     /* Send the message back to the connector */
     request.post(`${config.url}/bots/${config.botId}/conversations/${conversationId}/messages`)
       .send({ messages, senderId: req.body.senderId })
       .end((err, res) => {
         if (err) {
           console.log(err)
         } else {
           console.log(res)
         }
       })
   })
 
 app.listen(app.get('port'), () => {
   console.log('Our bot is running on port', app.get('port'))
 })
Clone this wiki locally