Facebook Messenger Chat Bot Tutorial - AI powered by wit.ai

Facebook has provided interesting way to allow you to build a chat bot for your FB page. I will guide you step by step to build this chat bot.

This chat bot essentially is something that will receive the fb messages send to your page, process them and send back response.

To start with, we need an app that would receive fb messages.
To know how to step up a free app: click here

Once we have setup your app and its up and running, we need to goto FB Developers .
Signin using the same FB account that is an admin to the required FB page we are setting up our BOT.

After signin, create a new appId. Screen looks like:

Fill up and create the app.

Post app creation, we need to goto the app and click "Add Product" at the bottom left corner and select "Messenger" from the options.

After adding messenger, we need to setup Webhook.
Click "Add Product" again and select Webhook, it should come under your products list now.

Click on webhook, following screen appears:


Click on New Scubscription and select "Page":

Selection Page renders below screen:



Now, Callback URL is nothing but the webhook, a url that fb will use for authentication and verification. It should always be up as FB keeps on monitoring this url periodically.

Your webhook url, in case you have created the app from above link will be something like:
https://<your app name here>.herokuapp.com/webhook/
that is, your webhook url is simply your app name followed by /webhook

Now, you need to configure your app to respond to this webhook. We also need to create a verify token. Verify token is just your aunthentication text that FB will send and your webhook should respond with "challenge" for that particular token. Add below webhook code to your app.js or index.js:

app.get('/webhook/', function (request, response) {
  if (request.query['hub.verify_token'] === 'Nobroker_Labs') {
    response.send(request.query['hub.challenge'])
  }
  response.send('Error, wrong token')
})




Comments

Popular posts from this blog

JMeter – Working with JSON

Existence: Absolute & Relative

How to create an XML Log file in Java using JAXB (Customized)