首页 > 解决方案 > Twilio:在收到先前响应的记录后响应呼叫者

问题描述

我正在尝试使以下流程起作用:

  1. 来电者拨打 twilio #
  2. 我们问来电者一个问题,他们通过说话来回应
  3. 收到成绩单(不是音频文件)后,我们会向他们提出另一个问题来回应……这会持续 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 响应那个处理程序?在处理程序的第二次响应后,调用者被挂断/

关于如何实现这一点的任何想法?我不认为我真的可以让用户在响应第二个/处理程序请求之前安静地等待......

标签: twiliotwilio-apitwilio-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


推荐阅读