Facebook Messenger bot not sending messages in order

后端 未结 11 2095
遥遥无期
遥遥无期 2021-01-01 21:00

I\'m playing around with building a simple Facebook Messenger chatbot and I\'m having trouble sending messages in sequence.

In the example above, it should

11条回答
  •  情书的邮戳
    2021-01-01 21:28

    I added a messageId counter to the app that resets to 0 on every start of messagehandling. Then I delay with that number * 100 ms. This way I can add intentional delays as well with code like messageDelay += 15

    receivedMessage(event) {
      messageDelay = 0;
      //...
    

    sendMessage extend:

    function sendTextMessage(recipientId, messageText) {
    //...
      setTimeout(function() {
        callSendAPI(messageData);
      }, messageDelay++ * 100)    
    }
    

提交回复
热议问题