botkit icon indicating copy to clipboard operation
botkit copied to clipboard

cant handle conversations in Facebook messenger

Open liornaar opened this issue 10 years ago • 4 comments

Hello, First I want to say thank you for this platform, its amazing. I'm encountering some issues when trying to initiate a conversation in facebook messenger. I took the code from the documentation here:

controller.hears(['pizzatime'], 'message_received', function(bot,message) {
    var askFlavor = function(err, convo) {
      convo.ask('What flavor of pizza do you want?', function(response, convo) {
        convo.say('Awesome.');
        askSize(response, convo);
        convo.next();
      });
    };
    var askSize = function(response, convo) {
      convo.ask('What size do you want?', function(response, convo) {
        convo.say('Ok.')
        askWhereDeliver(response, convo);
        convo.next();
      });
    };
    var askWhereDeliver = function(response, convo) {
      convo.ask('So where do you want it delivered?', function(response, convo) {
        convo.say('Ok! Good bye.');
        convo.next();
      });
    };

    bot.startConversation(message, askFlavor);
});

when I send "pizzatime" in facebook messenger, the debugger shows the following:

debug: HANDLING MESSAGE IN CONVO { text: 'pizzatime',
  user: '1180150065384201',
  channel: '1180150065384201',
  timestamp: 1476799156870,
  seq: 611,
  is_echo: undefined,
  mid: 'mid.1476799156870:501cb0eb62',
  sticker_id: undefined,
  attachments: undefined,
  quick_reply: undefined }

But I get no response. I'm not running locally and my webhook is configured properly.

in facebook developers on Messenger tab it shows:

Selected events: conversations, message_deliveries, message_echoes, message_reads, messages, messaging_optins, messaging_postbacks

Any ideas? if more details are needed please let me know! Thanks!

liornaar avatar Oct 18 '16 14:10 liornaar

Hi, I'm facing the similar problem with start conversation

imraansarwar avatar Oct 19 '16 06:10 imraansarwar

I figured im not the only one facing this issue, It looks like some people were facing the same issue but with no luck in the discussions here.. I hope someone who did make conversations work in FB Messenger would shine a light on this.

liornaar avatar Oct 19 '16 06:10 liornaar

Well, I solved my problem by subscribing to page events as below: note the controller.startTicking() function. see below:

`request.post('https://graph.facebook.com/me/subscribed_apps?access_token=' + process.env.FACEBOOK_PAGE_TOKEN, function (err, res, body) { if (err) { controller.log('Could not subscribe to page messages') } else { controller.log('Successfully subscribed to Facebook events:', body) console.log('Botkit activated')

  // start ticking to send conversation messages
  controller.startTicking()
}

} )`

Note that I'm using botkit FB with express server

imraansarwar avatar Oct 19 '16 09:10 imraansarwar

Works like a charm! my problem i guess was that i'm using my own express server too thank you so much!!!

liornaar avatar Oct 19 '16 10:10 liornaar