Facebook Messenger bot not sending messages in order

后端 未结 11 2066
遥遥无期
遥遥无期 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:23

    You can try putting them inside a setTimeout function so each one goes after a certain period of time.

    So replace this:

    sendTextMessage(user, "Hello!");
    sendTextMessage(user, "1");
    sendTextMessage(user, "2");
    sendTextMessage(user, "3");
    

    With this:

    sendTextMessage(user, "Hello!");              
    
    // 1 second
    
    setTimeout(function() {
        sendTextMessage(user, "1");
    }, 1000)
    
    // 2 seconds
    
    setTimeout(function() {
        sendTextMessage(user, "2");
    }, 2000)
    
    // 3 seconds
    
    setTimeout(function() {
        sendTextMessage(user, "3");
    }, 3000)    
    

    And they should go one after another. You could also embed the functions inside each other if need be.

提交回复
热议问题