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

Channel Messenger

René Springer edited this page Jan 24, 2019 · 11 revisions

Set up your Facebook page

Create a Facebook page

Create a new Facebook page using this link. facebook page creation

Create a Facebook app

Create a new Facebook app using this link. facebook page creation

Get your page token

On the left menu, add a new product and select Messenger. facebook page creation Select your Facebook page and copy the token: facebook page creation Copy the Page token, you will need it later to create your channel.

Get your App Secret

Go on the dashboard tab, show and copy your App secret. facebook page creation Create your channel with the App Secret and the Page Token.

Set the Facebook callback URL

Now go on the Messenger menu and click on the Setup Webhook button. find facebook config webhook Set the Callback Url and the Verify Token with the ones we provide. find facebook config webhook

Activate your page

In this webhook section, select your page in the drop down menu, and click on subscribe. fill facebook config webhook

Start Connector in local

  • Clone and install Connector
$ git clone https://github.com/SAPConversationalAI/bot-connector.git
$ cd bot-connector
$ yarn install
$ yarn start-dev
  • Create your connector
$ curl -X POST "http://localhost:8080/connectors/" --data "url=bot_url"
  • Create your 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_PAGE_TOKEN" \
  "http://localhost:8080/connectors/:connector_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 example of bot:

 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', connectorId: 'yourConnectorId' }
 
   /* 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}/connectors/${config.connectorId}/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'))
 })