Skip to content

nbransby/dialogue-builder-example

Repository files navigation

dialogue-builder-example

A working example of a bot utilising dialogue-builder including persistence of dialogue state.

This example is written in TypeScript and consists of two files bot.ts and onboarding.ts, (bot.js and onboarding.js contain the transpiled TypeScript - not a pretty sight).

There is also bot.esnext.js and onboarding.esnext.js which is my attempt to implement the example without TypeScript but still using all the advanced JS syntax such as async/await and object destructuring. Although I haven't tried it myself, by using babel it should be possible to compile this down to es5 which is necessary to run on AWS Lambda.

Dialogue Builder depends on bot-builder by claudia.js who's command line tool supports deploying to AWS Lambda. But in this example we use the Serverless Framework for deployment as it also supports automated provisioning of DynamoDB instances which is used in this example to store the dialog state.

To deploy this example so you can test it in Facebook Messenger you will need to do the following:

  • #####Create a Facebook App

Create a new Facebook App or use an existing one. In the serverless.yml file, replace REPLACE_WITH_APP_SECRET with your Facebook App Secret

  • #####Create a Facebook Page

Create a new Page or use an existing one, then go to the App Dashboard and under Product Settings click "Add Product" and select "Messenger."

step1

In the Token Generation section, select your Page. A Page Access Token will be generated for you.

step3

In the serverless.yml file, replaceREPLACE_WITH_PAGE_ACCESS_TOKEN with your Page Access Token

  • #####Install serverless and setup your AWS account credentials on your machine

https://serverless.com/framework/docs/providers/aws/guide/installation/

Make sure to also follow these instructions on setting up AWS credentials

  • #####Run the following in the root of this directory and, once complete, copy the URL returned

      npm install
      serverless deploy
    
  • #####Setup the Webhook on Facebook with the URL as the Callback URL and SOMETHING_RANDOM as the verify token

In the Webhooks section, click "Setup Webhooks."

webhook

Enter a URL for a webhook, enter a Verify Token and select messages and messaging_postbacks under Subscription Fields.

subscription

  • #####Subscribe the App to the Page on Facebook

In the Webhooks section, you can subscribe the webhook for a specific page.

enter image description here

  • #####Try your new bot

Go to your Facebook Page and send a message to it. The bot should respond!

page