This repository was archived by the owner on Nov 26, 2019. It is now read-only.
-
Couldn't load subscription status.
- Fork 93
Channel Messenger
René Springer edited this page Jan 24, 2019
·
11 revisions
Create a new Facebook page using this link.
Create a new Facebook app using this link.
On the left menu, add a new product and select Messenger.


Go on the dashboard tab, show and copy your App secret.

Now go on the Messenger menu and click on the Setup Webhook button.

In this webhook section, select your page in the drop down menu, and click on subscribe.
- 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"- Download the appropriate version of Ngrok.
- Open a new tab in your terminal:
./ngrok http 8080
- Copy past the
https://*******ngrok.ioyou get, you will need it for the next step. - Leave your Ngrok serveur running.
- go back to the Facebook Developer page and add a new webhook.

- Subscribe your page to the webhook you just created.
- Your token is the slug of 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'))
})


