Proactive action with multiples messages


#1

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 {
    promisify
} = 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!