我想我一定错过了一些简单的东西。我正在尝试找到一种在任务中创建条件收集语句的方法。
我创建了一个简单的 Autopilot 任务,要求提供礼物金额 (gift_amount)。在训练屏幕中,我将其中一个短语设置为“Give {gift_amount}”。因此,有人应该能够说“给予”,然后它就会要求一定的金额。或者,他们可以说“给 10”,它应该跳过询问金额。即使我在灵态中给出,它似乎总是要求金额。这是我创建的任务代码。
{
"actions": [
{
collect": {
"name": "gift_amount",
"questions": [
{
"question": "Thank for your generosity. How much would you like to give?",
"name": "gift_amount",
"type": "Twilio.NUMBER"
}
],
"on_complete": {
"redirect": {
"method": "POST",
"uri": "https://webhook.site"
}
}
}
}
]
}
最佳答案
根据文档,格式与之前给出的答案不同。
https://www.twilio.com/blog/intelligent-coffee-order-system-with-twilio-autopilot
这就是有效的:
exports.handler = function(context, event, callback) {
let actions = [];
console.log(event.CurrentTask);
console.log(event.Field_gift_amount_Value);
let giftAmount = event.Field_gift_amount_Value;
const response = {
actions: []
}
if (giftAmount) {
response.actions.push({ "say": "Thanks for donating!"});
} else {
response.actions.push({ "say": "Cheapskate!"});
}
callback(null, response);
}
关于Twilio 自动驾驶仪字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57810088/