Facebook Messenger bot not sending messages in order

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

    You can achieve QUEUING by promises.

    function delay(time) {
      return new Promise(function(resolve, reject) {
        setTimeout(resolve, time);
      });
    }
    
    delay(2000).then(() => {
      console.log('hi');
      delay(2000).then(() => {
        console.log('hello');
        delay(2000).then(() => {
          console.log('welcome');
        })
      })
    })

提交回复
热议问题