-
Notifications
You must be signed in to change notification settings - Fork 209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sending replies in sequential execution order #39
Comments
I'd try using a library like async, which allows you to do operations over an iterable like an array, but with callbacks so you can guarantee an order. For your use case, I'd do something like: let answers = currentQuestion.answer.split('\n');
async.eachSeries(answers, (answer, cb) => {
reply({ text: answer }, cb);
}, (err) => {
// this function is called either when all the answers have been sent, or if an error is thrown
if (err) {
// deal with err
}
}) |
I did the same with the Promise API, But it seems that the bug is coming from Facebook :) there is no queues in sending messages.
|
I prepare what I want to send in an array of strings, then call this:
This basically combines as many short strings from the array as possible and sends them out, pausing for 1/2 second between each. I usually send out between 1 and 3 messages. So far this has worked well. |
I am not good with Javascript but you can try this. Works well and also gives you the typing bubble so the user knows you are still typing
|
Hello everyone,
I am currently splitting my replies into an array, because the length is superior to 320, but I can't send them in order :
let answers = currentQuestion.answer.split("\n"); answers.forEach( (answer) => { reply({"text": answer}, (err) =>{ })
In Messenger, I'm receiving them in a random order, I looked a bit around Promises, is there any way I can use them ?
Thank you
The text was updated successfully, but these errors were encountered: