How to send several messages using Twilio Autopilot?

十年热恋 提交于 2020-02-23 04:29:27

问题


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:


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!



来源:https://stackoverflow.com/questions/58651590/how-to-send-several-messages-using-twilio-autopilot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!