Skip to content

fczuardi/fbbotexample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Facebook Messenger Bot Example

This is a simple example of how to get a bot running on a Facebook page.

Install this demo

git clone https://github.com/fczuardi/fbbotexample.git
cd fbbotexample
npm install

Tutorial

1. Create a Facebook Page

Click the link to create a Facebook Page, choose a page type and click "Get Started".

createpage

Click a bunch of "Skip"s.

pagesetup

pagesetup2

pagesetup3

2. Create a Facebook App and generate a page token

Click the link to create a Facebook App, then click "Skip and Create App", and fill the form to get an App ID and procede to the dashboard page:

createfbapp

On the Dashboard page of your FB App, add the "Messenger" product:

addmessengerproduct

Click Settings, select the page and generate a page token

screen shot 2016-06-10 at 5 19 27 pm

3. Edit the index.js file and launch your bot server.

Edit the sample code file: paste your page token and type a random string as the verification token.

const myPageToken = 'PASTE_YOUR_PAGE_TOKEN_HERE';
const myVerifyToken = 'TYPE_ANY_RANDOM_STRING_HERE';
const myCallbackPath = '/webhook';
const myPort = 9091;

You can generate a random string in the command line with:

openssl rand -base64 36

screen shot 2016-06-11 at 12 13 14 am

Launch your server:

node index.js

4. Expose your machine to the world using ngrok

If you dont have it, download ngrok.

On a different terminal launch ngrok to tunnel the port your bot is running to a public HTTPS url:

ngrok http 9091

(your ngrok syntax may vary, this example uses version 2.0.25)

This will give you an https URL, to be used in the next step.

screen shot 2016-06-10 at 5 32 36 pm

5. Go back to your FB App Dashboard page and validate the webhook

On the dashboard page of you facebook app click "Setup Webhooks":

webhook1

Use the https url from ngrok with the callback path and the random string verify token to fill the form. Check all checkboxes:

webhook2

6. Say hello

Open your page and send a message to it. If you follow all steps you should have an echo bot running.

sayhello

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published