问题描述
用户 A 回答并说“foo”或“bar”
如果用户 A 说 "foo" -> c.calls(callSid).update(status="complete")
如果用户 A 说 "bar" -> twilio.update('press the number 2')
我该如何实施?
我正在使用 Python 帮助程序库并尝试过这个。
call = c.calls(callSid).update(twiml="<Play digits='2'/>")
但应用程序出错。
解决方法
在您的出站呼叫中,使用 TwiML 要求用户说出“foo”或“bar”,然后提供一个可被调用以处理响应的网络钩子,即:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Gather input="speech" timeout="5" action="<your webhook>">
<Say>Please say foo or bar.</Say>
</Gather>
</Response>
Twilio 将对 POST
中的指定 webhook 执行 action
,并且用户答案将与 SpeechResult
中的置信度分数一起存储在 Confidence
中。然后,您可以按照您概述的方式继续处理您的业务逻辑。
有关 Gather
的更多信息,请查看 TwiML documentation。