Giter Site home page Giter Site logo

oakbot-intro's Introduction

Beginner Chatbot Development

A guide to creating chatbots and conversational interfaces

Prerequisites

  • node.js

  • ngrok

    ngrok creates a secure public URL to a local webserver on your machine. Iterate quickly with immediate feedback without interrupting flow.

    npm install -g ngrok
    

    If your package manager of choice is Homebrew, install via brew install ngrok

    If it's your first time globally downloading a package using Node OR you're getting EACCES/permission denied you will need to update your permissions:

    https://docs.npmjs.com/getting-started/fixing-npm-permissions

Installation

Clone this repo and install dependencies

git clone https://github.com/devcfacebook/oakbot-intro
cd oakbot-intro
npm install

Getting started

Set up your environment variables

  • Create a .env file within the directory
  • Copy the contents from the .env.example into the .env file

These variables are necessary to have a functioning server. We will update the values later

Install npm modules to local file

npm install

Start up your app server

npm start

In the browser, navigate to the webhook route on your localhost

At this point, your browser should show a 'Forbidden' status and your server should output an error message stating: 'Failed validation. Validation token mismatch'

Start up the ngrok server within another terminal

ngrok http 5000

In the browser, navigate to your webhook route on the public url provided to you by ngrok, e.g. https://99fca400.ngrok.io/webhook

Confirm that you recieve the same status and log message as earlier

Now let's deploy our bot so we can start interacting with it!

Messenger Platform for Bots

To build a bot on the Messenger platform, the following items are necessary:

Facebook Page: A Facebook Page will be used as the identity of your bot. When people chat with your app, they will see the Page name and the Page profile picture

Facebook Developer Account: Your developer account is required to create new apps, which are the core of any Facebook integration

Facebook App: The Facebook app contains the settings for your Messenger bot, including access tokens

Webhook URL: Actions that take place in conversations with your bot, such as new messages are sent as events to your webhook

Create a FB page

https://www.facebook.com/pages/create

Create a FB developer account and a FB app

https://developers.facebook.com/apps/

Add messenger capabilities to FB app

Go to the App Dashboard and under Product Settings on the bottom left corner, click "Add Product" and select "Messenger"

Connect FB app with bot server

  • Within your file directory, update the VALIDATION_TOKEN in the .env file to any value you desire

  • On the Messenger page, browse to the Webhooks section, and select "Setup Webhooks"

  • Enter your ngrok url with the webhook route (e.g. https://99fca400.ngrok.io/webhook) into the callback url field

  • Enter the value of your VALIDATION_TOKEN into the verify token field

  • Within the subscription fields section, select the messages and messaging_postbacks option

Collect app secret

  • At the top of the dashboard, browse to the App Secret section and click on show
  • Copy the app secret and use it to set the APP_SECRET variable within your .env file

Collect page access token

  • Scroll to the Token Generation section and select your page
  • Copy the generated page access token and use as the value for the PAGE_ACCESS_TOKEN variable in your .env file

Link messenger app to page

Browse to the Webhooks section and select your page to forward the messaging and postback events to your the webhook route

enter image description here

Wrapping it up

Restart your bot server to begin receiving content from your FB messenger app

Send a message as a visitor to your FB page and watch the message be echoed back to you.

Follow these steps to quickly access your bot through Facebook:

  1. Navigate to your Facebook Page and click the 'add a username' under the profile picture.

  2. Add a username, preferrably the same name of your Bot

  3. You should now be given a link to your Bot. Navigate to that link, and send a message to your bot.

Deploying Your Bot

  1. Navigate to the following tutorial to deploy your Bot Server to Heroku.

  2. Once you go through those steps, make sure to do the following APP_SECRET, PAGE_TOKEN, AND VALIDATION_TOKEN to your config variables.

  3. You stopped running your instance of ngrok so that heroku can use the port

  4. Navigate to the Messenger Platform in your Browser and scroll down to WebHooks. Click on 'edit subscription' and update your WebHook link to point to your Heroku link + /webhook

oakbot-intro's People

Contributors

albreyb avatar ifed3 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.