Proactive action with multiples messages


Hi guys!
I need send a proactive action with multiples messages, but I have a problem. The messages don’t are sent in order, because, looks like that sendToUser is an asynchronous function.

I tested with:

const {
} = require('util');
const sendToUserPromise = promisify(bp.renderers.sendToUser);
if(arrayOfElementsId != null && Array.isArray(arrayOfElementsId)){
            arrayOfElementsId.forEach(async function(elem){
              promises.push(sendToUserPromise(userId, elem));
             /*Others custom actions*/
            return promises.reduce((p, fn) => p.then(fn), Promise.resolve())

I tested with Promise.all and await too, but don’t worked.

In all cases, the elements are sent, but unordered.

For example, I sent three elements:
1 - a Text.
2 - A Carousel
3 - A Text with Quick replies

The second element is a carousel, with API request and slower, then it is displayed as the last element.

Thanks in advance!


Yes, I had to rewrite a bunch of code to add synchronization. The issues are all over the place

This is available in my Botpress fork and you can compare it to the official branch via the largest pull request you can see in the repo…


Sorry @dmk23, I requested delete this post, but is not deleted yet. Finally, this was not a problem from botpress. The problem was in my code.

Anyway, thanks for your cooperation.