Twilio Autopilot with Whatsapp wrong message order

245 views Asked by At

I am using Twilio Autopilot + Functions to build a chat bot. If I use Whatsapp i have an issue with the order of my messages if I send a URL. I assume this is because Whatsapp is processing the URL, which takes more time than the next message. I tried to build in a delay but than the two message i send arrives after the delay together and in a wrong order. Any idea how to send two message separately and give time for WA to process the URL? This is my code:

Funcation 1 response:

responseObject = {
      "actions": [
        {
          "say": `Please find information about ${shareLink}`
        },
        {
          "redirect": "task://anything_else"
        }
      ]
    };
return callback(null, responseObject);

Function 2 (redirect from Function 1 points here via Autopilot) (task://anything_else)

exports.handler = function (context, event, callback) {

    let delayInMs = 5000;

    let respsoneObject = {
        "actions": [
            {
                "collect": {
                    "name": "anything_else",
                    "questions": [
                        {
                            "question": "Can I help you with anything else?",
                            "name": "need_help",
                            "type": "Twilio.YES_NO"
                        }
                    ],
                    "on_complete": {
                        "redirect": "task://goodbye"
                    }
                }
            }
        ]
    };

    let timerUp = () => {
        return callback(null, respsoneObject);
    };

    setTimeout(timerUp, delayInMs);
};

My problem is that the "Can I help you with anything else?" question appears before the message which shares more information. However i would expect the link first.

I also tried to merge the two messages in the same response by adding say and collect to the action array, the result is the same.

Thank you for any help.

0

There are 0 answers