twilio - Twilio:在收到先前响应的记录后响应呼叫者
问题描述
我正在尝试使以下流程起作用:
- 来电者拨打 twilio #
- 我们问来电者一个问题,他们通过说话来回应
- 收到成绩单(不是音频文件)后,我们会向他们提出另一个问题来回应……这会持续 2-3 个问题
我遇到的问题是对主 webhook 处理程序的调用和转录处理程序的分离。
我让主呼叫处理程序响应第一个问题,如下所示:
<!-- [/ handler] initial response, with the first question -->
<Response>
<Say voice="alice">What is your favorite color? Press any key when done.</Say>
<Record transcribe="true" transcribeCallback="/transcript" maxLength="60"/>
</Response>
然后,当录制完成时,我们会收到对主调用处理程序的第二个请求。我还不能回答另一个问题(业务需求),所以我们用一个模糊的确认来回答:
<!-- [/ handler] vague confirmation response
<Response>
<Say voice="alice">Got it. Give me a couple seconds to write that down.</Say>
</Response>
然后我收到一个/transcript
带有成绩单的处理程序,我对此作出回应:
<!-- [/transcript handler] Second question -->
<Response>
<Say voice="alice">What is the air-speed velocity of an unladen swallow? Press any key when done.</Say>
<Record transcribe="true" transcribeCallback="/transcription" maxLength="60"/>
</Response>
但显然你不能用 TWiML 响应那个处理程序?在处理程序的第二次响应后,调用者被挂断/
。
关于如何实现这一点的任何想法?我不认为我真的可以让用户在响应第二个/
处理程序请求之前安静地等待......
解决方案
当您收到您/transcript handler
的请求时,您在请求中包含callSid
( CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
) 以及其他参数。
有了这个callSid
,您可以修改“正在进行的呼叫”,我向 Twilio 发出请求并传递一个新的 TwiML。
不确定您在服务器端使用什么语言,但在 Node.js 中看起来像这样:
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);
client.calls('CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
.update({twiml: '<Response>
<Say voice="alice">What is the air-speed velocity of an unladen swallow? Press any key when done.</Say>
<Record transcribe="true" transcribeCallback="/transcription" maxLength="60"/>
</Response>'})
.then(call => console.log(call.to));
文档:(https://www.twilio.com/docs/voice/tutorials/how-to-modify-calls-in-progress-node-js)
推荐阅读
- reactjs - 在不重新启动服务器的情况下,Webpack bundle.js 更改不会显示在 Spring 应用程序中?
- c++ - 如何覆盖子类中的抽象类构造函数
- angular - 基于 Angular 令牌的身份验证,获取和存储用户配置文件,最佳实践
- java - 如何过滤具有子列表的父对象和具有孙子列表的子对象并通过匹配孙子的属性
- python - 在读取 csv 文件时向数据框添加一列 [pandas]
- r - 从 R 数据框中过滤掉时间数据
- sql - 以升序对 MMM-YYYY 文本数据进行排序的 SQL 查询
- c++ - 如何让 Chrome 开发工具显示 JavaScript 源代码
- java - 为什么@Secured 在 Tapestry 5.4.0 中不起作用?
- php - WooCommerce 中的产品存档描述,带有阅读更多标签