1
votes

When sending a response to a Twilio Autopilot bot, I want to split the message in several "blocks", like in the sample image below:

Is it possible to do that?

I tried adding two Say actions, but it didn't work: I got an Invalid Autopilot Actions JSON: Invalid Autopilot Action `

{
  "actions": [
    {"say": "Hello, World!},
    {"say": "Hello, World!},    
    {"listen":true}
  ]
}

Or in the other hand, if that's not possible, how can I add new lines to the message, so that the message is in paragraphs.

I tried sending this message but I also got an Invalid Autopilot Actions JSON: Invalid Autopilot Action

{
  "actions": [
    {"say": "Hello, World!

More text!"},
    {"listen":true}
  ]
}

Any help will be appreciated.


I accepted the answer as it technically answers my question. Although not in the way I wanted.

I still wonder if it's possible to add new lines "\n" on the Say actions.

1
Sorry for not adding a comment - I don't have enough points 🙄. I'd also like to know if this is resolvable in a more efficient manner - I suppose the issue is compounded by the fact that the simulator does show each "say" action as a separate message, but not in a real environment. Could adding a listen: false or some other otherwise-redundant statement between each say action work in this case? – user1522563

1 Answers

0
votes

Twilio developer evangelist here.

You can use a Redirect Action pointed at a Twilio Function to send two response messages, or one message split into separate block. The first message would be sent from the JSON task bin and the second would be sent from your Twilio Function. Your task bin would contain this JSON:

{
    "actions": [
        {
            "say": "Hello World"
        },
        {
            "redirect": "https://REPLACE-WITH-YOUR-TWILIO-FUNCTION-URL.twil.io/sotest"
        }
    ]
}

And then your Twilio Function would have

exports.handler = function(context, event, callback) {
    let respObj = {
        "actions": [
            {
                "say": "hello world"
            },
            {
            "listen": true
            }
        ]
    };
    callback(null, respObj);    
};

Let me know if this helps at all!