在自动驾驶仪的收集动作中添加新行

时间:2020-05-01 15:07:05

标签: twilio

我要问机器人用户一系列问题,其中一些问他们回答李克特式的问题。当我提供答案选项时,将项目放在新行上会很有帮助。

category_id

理想情况下,这将返回一条短信:

{
    "actions": [
        {
            "collect": {
                "name": "q1",
                "questions": [
                    {
                        "question": "How much does this bother you?\\n\\n1 = not at all\\n2 = somewhat\\n3 = moderately\\n4 = quite a bit",
                        "name": "q1_score",
                        "type": "Twilio.NUMBER"
                    }
                ],
                "on_complete": {
                    "redirect": "task://question_2"
                }
            }
        }
    ]
}

但实际上返回的是:

How much does this bother you?
1 = not at all
2 = somewhat
3 = moderately
4 = quite a bit

我是否转义How much does this bother you?\n\n1 = not at all\n2 = somewhat\n3 = moderately\n4 = quite a bit 无关紧要(即\\n均未返回期望的结果)。尝试使用URL编码的版本\\n也不起作用。

在此先感谢您提供的见解。

2 个答案:

答案 0 :(得分:1)

这里是Twilio开发人员的传播者。

您在使用模拟器吗?我相信模拟器不会显示新行,但是使用\n如下所示应该会生成您想要的文本:

"questions": [
                    {
                        "question": {
                            "say": "How much does this bother you? \n 1 = not at all \n 2 = somewhat \n3 = moderately \n4 = quite a bit"
                        },
                        "name": "num",
                        "type": "Twilio.NUMBER"
                    },
...

得到了

this SMS

让我知道这是否有帮助!

答案 1 :(得分:-1)

以下工作:

{
    "actions": [
        {
            "collect": {
                "name": "collect_comments",
                "questions": [
                    {
                        "question": "How much does this bother you?\n\n1 = not at all\n2 = somewhat\n3 = moderately\n4 = quite a bit",
                        "name": "comments",
                        "type": "Twilio.NUMBER"
                    }
                ],
                "on_complete": {
                    "redirect": {
                        "method": "POST",
                        "uri": "https://example.com/collect"
                    }
                }
            }
        }
    ]
}

enter image description here