Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Order of messages from multiple bot.replyWithTyping() is not correct in Messenger .. #543

Closed
ajith007 opened this issue Dec 10, 2016 · 4 comments

Comments

@ajith007
Copy link

Hello,

I'm trying to display multiple messages using bot.replyWithTyping() as follows -

      bot.replyWithTyping(message,'First!');
      bot.replyWithTyping(message,'Second!');
      bot.replyWithTyping(message,'Third!');

The result I see in the Messenger App is as below -

First!
Third!
Second!

Any idea why the order is messed up? I also tried using bot.reply() but no luck.

@PierreMarieRiviere
Copy link

PierreMarieRiviere commented Dec 10, 2016

Node JS is asynchronous, so it displays which ever parts of the code loads first. I guess "second!" comes after "first!" because there is one more letter.

Botkit has a nice conversation feature that deals with the issue. Try:

bot.startConversation(message, test);

test = function(response, convo) {
  convo.say('first!');
 convo.say('second!');
 convo.say('third!');
};

This should be enough to deal with text messages. If you want to avoid this issue when sending heavier messages to the users (eg: images attachment), consider reading about the {require_delivery: true} option detailed in the readme-facebook.md file.

@ajith007
Copy link
Author

ajith007 commented Dec 10, 2016

Thanks devhaoy for the quick response.

You are right, it was the number of characters in the message determining the order. Good catch. :)

convo.say() is displaying the messages in the correct order. I need to display a message with attachment(that has buttons) after displaying the text messages. I'm trying as below, but the message with attachment(bot.reply()) gets displayed first and then the convo.say() messages in the correct order.

bot.startConversation(message,function(err,convo) {
     convo.say('First!');
     convo.say('Second!');
     convo.say('Third!');
 });

 bot.reply(message,{
     attachment: replyWithButtons
 );

I have added {require_delivery: true} . Is there a way we could send heavier message using convo.say()? If so, what is the syntax? Thank you!

@PierreMarieRiviere
Copy link

Try this

bot.startConversation(message, welcome);

welcome = function(response, convo) {
  convo.ask({
            attachment: {
                'type': 'template',
                'payload': {
                    'template_type': 'button',
                    'text': "Gin Martini 007?",
                    'buttons': [
                        {
                            'type': 'postback',
                            'title': 'button1',
                            'payload': 'payload1',
                        },
                        {
                            'type': 'postback',
                            'title': 'button2',
                            'payload': 'payload2',
                        },
                    ]  
                }
            }
        }, function(response, convo) { 
    switch(response.text) {
        case 'payload1':
        aTopic(response, convo);
        break;
        case 'payload2':
        anotherTopic(response, convo);
        break;
        default:
        aDefaultTopic(response, convo);
    }
    convo.next();
  });
};

var aTopic = function(response, convo) { // etc. etc.

You don't need to enable require_delivery for these kind of attachment, I'd just keep it false as long as you don't need it.

Note that the switch statement system above is one of many ways of handling the buttons. There is a built-in Threads function in Botkit that is widely use, you should refer to past issues and the readme files to learn more about it.

@ajith007
Copy link
Author

Thanks devhaoy!

The below code worked fine -

                        bot.startConversation(message, function(err, convo) {
				convo.say('First!');
				convo.say('Second!');
				convo.say('Third!');
				convo.ask({
						attachment: msgMenu
					}, function(response, convo) {
						convo.next();
				});
			});

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants