Coder Social home page Coder Social logo

bootbot's People

Contributors

charca avatar chr0m1ng avatar datafile4 avatar devalnor avatar hkalexling avatar joshes avatar learts avatar lehainam-dev avatar mraaroncruz avatar rmattos avatar tom-sherman avatar udokah avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bootbot's Issues

Closing webview and resuming the conversation

Hey,

I have a simple webview that lets the user to pick date and time, but once the user selects it I want to close the webview, pass the data back to the conversation and continue from where we left.

Is it possible?

Postback doesn't work for example in your example (threads-example.js) it should give you saying response if you click on help or sittings but it didn't

`bot.setPersistentMenu([
{
type: 'postback',
title: 'Help',
payload: 'PERSISTENT_MENU_HELP'
},
{
type: 'postback',
title: 'Settings',
payload: 'PERSISTENT_MENU_SETTINGS'
},
{
type: 'web_url',
title: 'Go to Website',
url: 'http://yostik.io'
}
]);

bot.on('postback:PERSISTENT_MENU_HELP', (payload, chat) => {
chat.say(I'm here to help!);
});

bot.on('postback:PERSISTENT_MENU_SETTINGS', (payload, chat) => {
chat.say(Here are your settings: ...);
});`

Error: The parameter user_id is required

Hi,
I'm using bot with conversation as bellow

  bot.on('postback:QUIZ_TEST', function(payload, chat) {
    chat.say("Let' do quiz test", {typing: true}).then(function() {
      chat.conversation(askQuiz)
    })
  })

Then I faced this kind of error.

Error sending message: FetchError: request to https://graph.facebook.com/v2.6/me/messages?access_token=xxx failed, reason: getaddrinfo ENOTFOUND graph.facebook.com graph.facebook.com:443

When I query by this url via browser I got a message from response of FB

{
error: {
message: "(#100) For field 'messages': The parameter user_id is required",
type: "OAuthException",
code: 100,
fbtrace_id: "BQLNcgIP4cd"
}
}

It's seem like chat or convo which I used was missing recipient_id (user_id).
I can explicit pass it by using only bot.say(userId, ...) but it's inconvenience.

Thanks in advance.

Account Linking

Is it possible to use account linking feature with bootbot?

composer_input_disabled not working

Hi, I'm trying to disable user input in my bot, but it doesn't seams to work. Here is my persistent menu setup code:

bot.setPersistentMenu(
[
    {
      "locale":"default",
      "call_to_actions":[
        {
          "type":"postback",
          "title":"Español",
          "payload":"ES"
        },
		{
          "type":"postback",
          "title":"English",
          "payload":"EN"
        }
      ]
    },
    {
      "locale":"zh_CN",
      "composer_input_disabled":false
    }
  ]
, true);

All the bot interaction will be made with quickreplies and the persistent menu to set the language.

Regards

Signature validation error.

I want my bot to accept HTTP requests as well so for now what I'm doing something like this

bot.app.get('/', (req, res) => { //Some other stuff });

Now when I'm trying to do POST request with JSON data I was getting "Couldn't validate the request signature." error so for this I had to remove the middleware.

bot.app._router.stack = bot.app._router.stack.slice(0,2)

What I propose is in _verifyRequestSignature check for webhook if it is not let it go as a normal web request.

chat.sendGenericTemplate() is not completing

hello, i am trying to send a generic template but it starts sending and never completes! what is wrong with what i am doing?

  `bot.on('postback:yes-order', (payload, chat) => {
chat.sendGenericTemplate({

    elements:[
      {
        title:"Cold Subs",
        image_url:"https://www.jerseymikes.com/media/static/category-photos/cold-subs.jpg",
        subtitle:"Great cold fast and ready with a smile",
            buttons:[
          {
            type:"postback",
            title:"SELECT",
            payload:"cold-subs"
          }              
        ]
      },
      {
        title:"Hot Subs",
        image_url:"https://www.jerseymikes.com/media/static/category-photos/hot-subs.jpg",
        subtitle:"Fresh grilled and mouth watering goodness",
        buttons:[

          {
            type:"postback",
            title:"SELECT",
            payload:"hot-subs"
          }              
        ]
      },
      {
       title:"Wraps",
        image_url:"https://www.jerseymikes.com/media/static/category-photos/wraps.jpg",
        subtitle:"Wraps wrapped to perfect prefection",
        buttons:[

          {
            type:"postback",
            title:"SELECT",
            payload:"cold-subs"
          }              
        ]
      }
    ]

});`

can @Charca or anyone else show me the right way? thanks!

webhooks failing on heroku app

hello, my webhooks seem to be failing. facebook is sending me alerts saying my webhooks are failing when using this framework. i am hosting node js on heroku. could someone point me in the right direction as far as getting it working? thanks!

How to communicate with different pages with the same app

I want to make generic bot the can communicate with different pages knowing from which page the message received and response to the user in that specific page.

For knowing which page I think It can be done easily from the recipient attribute like this

bot.on('message', (payload, chat) => {
switch(payload.recipient) {
  case '12334784': //page id
    // do something
    break;
  case '9877654': //page id
    // do something
    break;
}
});

But in the first place BootBot accept only one page access token

const bot = new BootBot({
  accessToken: 'PAGE_ACCESS_TOKEN',
  verifyToken: 'FB_VERIFY_TOKEN',
  appSecret: 'FB_APP_SECRET'
});

What is the best way to accomplish such thing? How to accept messages from different pages?

Conversation: multiple answers

I faced with problem that users sometimes answers to same question in few messages.
Any ideas how to workaround this?

Are you using BootBot in production?

Hey folks,

I'm planning on adding a section to the repo's documentation featuring bots built using BootBot that are already in production for people to try out. I just found out that the amazing Game of Thrones chatbot GoTBot uses this framework, and I thought it'd be pretty cool to showcase other users.

So if you have a chatbot built with BootBot that you'd like to showcase on the repo, please drop a link in this issue. Thanks!

Initialize Bootbot without needing app secret [Feature Request]

It would be good to find a way to do initialize Bootbot without needing app secret. I'm finding a way where I can put my code that uses Bootbot in github.

In Messenger bot setup it says nodejs needs a GET method for Facebook verification. I'm not sure if inside Bootbot constructor we can just setup an app.get('/webhook/', function (req, res)... method. Is this possible? Some samples use something like this:

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

Allow account_linking type event to propagate from webhook to allow handling

First of all thanks for the awesome library!! Nicely written and architected!

Facebook's latest Webhook reference (https://developers.facebook.com/docs/messenger-platform/webhook-reference/account-linking) supports account linking process to Link Messenger account to 3rd party accounts. It will be nice If Bootbot will allow account_linking type event to propagate.

This is a one line change, that I will be happy to submit, or feel free to add it or let me know if it does not make any sense.

In Bootbot.js in _initWebhook function:

if (event.optin) {
......
} else { console.log('Webhook received unknown event: ', event); }

before the final else add a new line

if (event.optin) {
....
} else if (event.read) {
this._handleEvent('read', event);
}else if (event.account_linking){ // Add this to support account linking
this._handleEvent('account_linking', event); // Add this to support account linking
} else {
console.log('Webhook received unknown event: ', event);
}

Thanks in advance

Cannot read property 'filter' of undefined

Sometimes when I send message in messenger, I receive this error

TypeError: Cannot read property 'filter' of undefined
    at Conversation.respond (/Users/iurisouz4/Documents/Julien/Projects/facebook_bootbot/node_modules/bootbot/lib/Conversation.js:61:53)
    at _conversations.forEach.convo (/Users/iurisouz4/Documents/Julien/Projects/facebook_bootbot/node_modules/bootbot/lib/BootBot.js:344:22)
    at Array.forEach (native)
    at BootBot._handleConversationResponse (/Users/iurisouz4/Documents/Julien/Projects/facebook_bootbot/node_modules/bootbot/lib/BootBot.js:341:25)
    at BootBot._handleMessageEvent (/Users/iurisouz4/Documents/Julien/Projects/facebook_bootbot/node_modules/bootbot/lib/BootBot.js:291:14)
    at entry.messaging.forEach (/Users/iurisouz4/Documents/Julien/Projects/facebook_bootbot/node_modules/bootbot/lib/BootBot.js:377:20)
    at Array.forEach (native)
    at data.entry.forEach (/Users/iurisouz4/Documents/Julien/Projects/facebook_bootbot/node_modules/bootbot/lib/BootBot.js:370:27)
    at Array.forEach (native)
    at app.post (/Users/iurisouz4/Documents/Julien/Projects/facebook_bootbot/node_modules/bootbot/lib/BootBot.js:368:18)
    at Layer.handle [as handle_request] (/Users/iurisouz4/Documents/Julien/Projects/facebook_bootbot/node_modules/express/lib/router/layer.js:95:5)
    at next (/Users/iurisouz4/Documents/Julien/Projects/facebook_bootbot/node_modules/express/lib/router/route.js:131:13)
    at Route.dispatch (/Users/iurisouz4/Documents/Julien/Projects/facebook_bootbot/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/Users/iurisouz4/Documents/Julien/Projects/facebook_bootbot/node_modules/express/lib/router/layer.js:95:5)
    at /Users/iurisouz4/Documents/Julien/Projects/facebook_bootbot/node_modules/express/lib/router/index.js:277:22
    at Function.process_params (/Users/iurisouz4/Documents/Julien/Projects/facebook_bootbot/node_modules/express/lib/router/index.js:330:12)

After that, I receive this error :

Error sending message: FetchError: request to https://graph.facebook.com/v2.6/me/messages?access_token=EAAPBAL6ZBQEkBAMIblP8n6wISEjVJVaea4B54zghnwvy87ZAiCE1uexYSt8KipGqBQjzTeCG71hyWoB3wBZBHo33wX9ozH8x1cmgM7VxntkNy01ZABlpKp8Xp0zZC1vgxjIgFBzDQ58EzakeW0IMC58ZAnhGLbI0YKMfuRUKa4g2GUrzAOmlZAL failed, reason: connect ETIMEDOUT 31.13.73.1:443

But this second error don't appear everytime.

Actually I'm using ngrok for tunneling it. Do you think that is my problem? Or is it a bug? Because sometimes I have delay too, both in my project and in your examples.

Add other webhooks

I am trying to use the api.ai webhook but i am getting an error.

Error: Couldn't validate the request signature.
at BootBot._verifyRequestSignature (F:\Bot\Plan_Arvana\node_modules\bootbot\lib\BootBot.js:445:13)
at F:\Bot\Plan_Arvana\node_modules\body-parser\lib\read.js:100:9
at invokeCallback (F:\Bot\Plan_Arvana\node_modules\raw-body\index.js:262:16)
at done (F:\Bot\Plan_Arvana\node_modules\raw-body\index.js:251:7)
at IncomingMessage.onEnd (F:\Bot\Plan_Arvana\node_modules\raw-body\index.js:307:7)
at emitNone (events.js:86:13)
at IncomingMessage.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)

anyhelp??

Persistent menu problem

Hi there! I wrote a comment on the issue #24 thinking that my problem had some sort of connection with that bug but I was wrong.
Randomly whenever it wants, my app won't respond to any persistent menu button even for hours sometime, but will work on bot.on('message') callback.

My app is hosted on heroku and it seems that the problem doesn't respond to any logic, it happens really in a random way, there are no constants to consider (like the problem may appear at the resume of the heroku dyno from sleeping) and the bad news is that when this happen, my bot doesn't log anything, it's like Facebook is not calling the webhook in that situation.
So I don't even know how to debug this problem (probably it is caused by the library because other bots don't act like this).

I'll post the code ASAP and I must try to run it locally and tunnel it in order to consider or not heroku as a problem. Currently I'm running it with nodemon.
Sometimes refreshing the Facebook page on the browser and deleting the conversation on the android app solve the problems, sometimes not!

Ps: is it normal that the bot logs four or five POST requests for only one message sent?

Doubt about workflow using the bootbot-cli.

Hello, I am a beginner in chatbots development and a friend recommended me the bootbot framework, I really liked it! I also found this CLI, but I am in doubt about how I will develop using it.

I need to run bootbot start every time I change a file?
I need to run bootbot start together with nodemon index.js?
I need to run set up my webhook URLs every time I start developing?

I'm asking these questions because I ran the project using both ways, but sometimes I felt a delay between the commands on my machine and noticed the bot working in Messenger, so I could not identify where the errors were and even know If there was any mistake or the project was not online.

And congratulations for the brilliant work! @Charca @pferdefleisch

wit.ai

Hi,
I think it would be great if there was an example for integrating wit.ai with bootbot, among other nlp service providers out there. Since ultimately most users would want to do more that give straight hard-coded responses from their bot. This would totally speed up things when you working with bootbot.
This is not entirely not limiting to wit, but luis and others out there

Add support for content_type: "location" and "image_url" on Quick Replies

We need to refactor the _formatQuickReplies method to support an object with an open format. New types of quick replies format added since we implemented this methods are:

Location:

    {
        "content_type":"location",
    }

Text with Image:

    {
        "content_type":"text",
        "title":"Green",
        "payload":"DEVELOPER_DEFINED_PAYLOAD_FOR_PICKING_GREEN",
        "image_url":"http://petersfantastichats.com/img/green.png"
    }

But more formats will likely be added in the future so we should support whatever object the user sends (or auto-format like we do now if it's a string).

Facebook Docs: https://developers.facebook.com/docs/messenger-platform/send-api-reference/quick-replies

Nested conversation.ask() don't fire

Hello,

When i execute this code , the program get stucked on the second recursion of getResponse().
Both someFunctionWhoGenerateResponse and generateGreeting function return valid string and work perfectly.

`
const bot = new BootBot({
accessToken: config.get('accessToken'),
verifyToken: config.get('verifyToken'),
appSecret: config.get('appSecret')
});

function getResponse(txt, convo) {
var rps = someFunctionWhoGenerateResponse(txt);
convo.sendTypingIndicator();
convo.ask(rps, (payload, convo, data) => {
convo.say("hum");
getResponse(payload.message.text, convo);
});
}

function sendGreeting(response, convo) {
var init = generateGreeting();
convo.ask(init, (payload, convo, data) => {
getResponse(payload.message.text, convo);
});
}

bot.hear('hello', (payload, chat) => {
chat.conversation((convo)=> {
sendGreeting(payload.message.text, convo);
});
});
`

Error: Couldn't validate the request signature.

Hi,
Since today, I receive the error in console: Error: Couldn't validate the request signature.

The bot continue to work, but I think that's not good and in my research, I didn't find a solution for this.
Thanks!

Align on configuration variable names

I'm using the bootbot-cli tool and the config names are using underscores, whereas bootbot is using camelCase. I was going to put a PR together, but wasn't sure which one should change.

LMKWYT.

Trouble uploading code to heroku

Whenever I try to upload this code to heroku I get this error

Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch

I solved this problem by changing this line of code from BootBot.js (line 25)
this.app.set('port', port || 5000)

to this
this.app.set('port', process.env.PORT || 5000)

then it work like magic, because now heroku will be able to bind to it

Add `sendListTemplate` method

Support for List Template (docs)

Could be a copy of sendGenericTemplate that in addition to elements, also support top_element_style and buttons props.

clarification on where to get app developer keys

I have made an app project on Facebook and am only seemingly able to find an App Secret and an App ID.

I still do not know where to find the following

  1. access_token
  2. verify_token

I know this is not a product feature of Bootbot but rather of Facebook... but I was not able to find this information in their documentation.

It would be really helpful to include pointers/directions in the Getting Started section!

Thanks for the help and the cool project man 👍

postback with regex or wildcard or parameter

Hi,
First, thanks for this Awesome library.
I'm using it and enjoying every moment.

I brought up a pretty nice project of my own.
I now ran into an issue where I have a list of items with buttons.
I want to define a postback so that when the user presses one of the buttons I will arrive at the same function and handle same just with different parameter.
Can you help to recommend how to easily solve this?

Should I use postback with regex? If so, how?

Thanks.

postback while in conversation do nothing

Currently, when a user clicks on a button the bot doesn't respond on the first time, the user should click twice to execute the postback action

bot: what is your name?
user: Charca
bot: and your age?
user: <click on About button>
bot: (do nothing)
user: <click on About button>
bot: I am a bot that helps you order food

How to close the conversation and execute the postback function when a user clicks on a button?

bot: what is your name?
user: Charca
bot: and your age?
user: <click on About button>
bot: I am a bot that helps you order food

Passing arguments to events subscriptions

Hi!!

I have a question about how to pass information from a button event to the the button subscription..

I modified the bootbot source code to work something out, but I would to confirm if there is another way before I make a pull request. It is something like:

chat.say({
    text: 'Some product here',
    buttons: [
        { type: 'postback', title: 'More info', payload: 'INFO:product_id' }
    ]
});

bot.on('postback:INFO', (payload, chat, data, args) => {
    console.log(args); // should print "product_id"
});

How to trigger an event programmatically ?

Let's say I have an event like this

bot.on('postback:HELP', (payload, chat) => {
  chat.say('need help');
});

how to trigger this event when for example the user says "help"

bot.hear('help', (payload, chat) => {
  // trigger "postback:HELP"
});

How to see debug messages or logs?

When I send templates sometimes it didn't show in chat and I don't know what is the reason.

But after a long time trying I discover a syntax error in my template or my elements has more than the maximum allowed elements. This errors are easy to solve but sometimes hard to find.

So is there any logs that I can see? or any debug event?

Persistent menu action during a conversation

Hi,

From what I understand, bot.on and bot.hear are bypassed during a conversation.
Since callback from persistent menu are handled in bot.hear, how can we handle those events during a conversation ?

Middleware Support [Feature Request]

Hey @Charca , I saw your post about BootBot in the Bots Facebook group and after looking at the framework, I really want to try BootBot for my next Messenger bot. I've been using NLP services in most of my bots (specifically Wit.ai) however and would love it if BootBot had support for middleware to do additional processing when a message is received. I could use bot.on('message') to process messages with Wit.ai, but there wouldn't be a way to dispatch on these results using bot.hear(). My solution to this is allowing the BootBot to accept middleware, which are executed when a message is received and add a context which hear() can use to dispatch on. Here is some pseudocode of how it could be used:

'use strict';
const BootBot = require('bootbot');

const bot = new BootBot({
  accessToken: 'FB_ACCESS_TOKEN',
  verifyToken: 'FB_VERIFY_TOKEN',
  appSecret: 'FB_APP_SECRET'
});

// A middleware returns a promise that when resolved adds context
// that can be used to dispatch on hear messages
// hear callbacks are not executed until all middleware have been resolved
bot.addMiddleware((message) => fetchWitAiIntent(message).then(
  (witAiResult) => {witai: {intent: witAiResult.userIntent}}
));

// a predicate can be used to decide what response should be triggered by the bot
function userHungry(payload, middlewareContext) {
  return middlewareContext.witAi.intent === 'hungry';
}

// predicate used to determine if case should be executed
bot.hear(['food', userHungry], (payload, chat, middlewareContext) => {
  // Do something here.
});

I don't know if middleware is in the roadmap or not. Let me know what you think, and if you are fine with it I would love to implement it.

messages not getting delivered

for some reason my bot is not working with this framework. i have no reason why its not receiving messages? screen shot 2016-08-13 at 6 15 03 am
the code i am using

`const BootBot = require('bootbot');

const bot = new BootBot({
accessToken: process.env.access_token,
verifyToken: process.env.verify_token,
appSecret: process.env.app_secret
});

bot.hear('ask me something', (payload, chat) => {
chat.conversation((convo) => {
    askName(convo);
});

const askName = (convo) => {
    convo.ask(`What's your name?`, (payload, convo) => {
        const text = payload.message.text;
        convo.set('name', text);
        convo.say(`Oh, your name is ${text}`).then(() => askFavoriteFood(convo));
    });
};

const askFavoriteFood = (convo) => {
    convo.ask(`What's your favorite food?`, (payload, convo) => {
        const text = payload.message.text;
        convo.set('food', text);
        convo.say(`Got it, your favorite food is ${text}`).then(() => sendSummary(convo));
    });
};

const sendSummary = (convo) => {
    convo.say(`Ok, here's what you told me about you:
      - Name: ${convo.get('name')}
      - Favorite Food: ${convo.get('food')}`);
  convo.end();
};
});
bot.start();`

any clues as to why it is not sending? any help would be appreciated.

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.