Giter Site home page Giter Site logo

nbransby / dialogue-builder-example Goto Github PK

View Code? Open in Web Editor NEW
3.0 4.0 1.0 24 KB

Example of using https://github.com/nbransby/dialogue-builder

JavaScript 48.18% TypeScript 51.82%
bot-builder messenger-bot facebook-messenger dialogue-builder typescript

dialogue-builder-example's Introduction

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

dialogue-builder-example's People

Contributors

nbransby avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

neerdavid

dialogue-builder-example's Issues

lambdaContext does not exist on type 'Request'

> tsc && serverless deploy function -f pointless-bot -l


10         apiRequest.lambdaContext.callbackWaitsForEmptyEventLoop = true;
                      ~~~~~~~~~~~~~

bot.ts(10,20): error TS2339: Property 'lambdaContext' does not exist on type 'Request'.

function name choice

I'm curious about the function name choice, right now it's webhook.... is there a convention as to this? and what's its relations to the service name which is defined up front.

bot crash at start with typeError

TypeError: this.state.filter is not a function at TypeError: this.state.filter is not a function
    at State.stateChanged (/var/task/node_modules/dialogue-builder/dialogue-builder.js:304:32)
    at new State (/var/task/node_modules/dialogue-builder/dialogue-builder.js:301:31)
    at new Dialogue (/var/task/node_modules/dialogue-builder/dialogue-builder.js:170:22)
    at module.exports.builder.platforms (/var/task/bot.js:44:24)
    at /var/task/node_modules/claudia-bot-builder/lib/bot-builder.js:29:55

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.