Closed paulbraam closed 4 years ago
Approach is okay, but use Promise.all()
instead of bluebird.
A simple example would be:
const textMessage = bot.sendMessage(chatId, 'hello');
const image = bot.sendPhoto(chatId, 'someImageUrl');
const anotherTextMessage = bot.sendMessage(chatId, 'world');
Promise.all([textMessage, image, anotherTextMessage]).then((res) => {
console.log('messages sent');
});
This does not guarantee order in which the messages are sent. You can ensure ordered sending with something like Array.reduce()
. Here is an article on it.
So you would do something like:
return [textMessage, image, anotherTextMessage]
.reduce((promiseChain, currentTask) => {
return promiseChain.then((chainResults) =>
currentTask.then((currentResult) => [...chainResults, currentResult])
);
}, Promise.resolve([]))
.then((arrayOfResults) => {
console.log(arrayOfResults);
});
There are more hipster approaches to reduce lines of code to send out sequentially. You could google them.
Hi,
I was using the code from #192 like this:
But what if I would like to send multiple messages that contain not only text, but also audio and photo updateSubTypes?
Here's what I tried to do, but it didn't work:
Please suggest how to implement this.