简体   繁体   English

Twilio 发送并等待回复小部件

[英]Twilio Send & Wait for Reply widget

I'm using an incoming call flow that starts call recording, asks a bunch of questions, gathers responses, at the end of the call: stops recording and sends a sms to caller using send/wait for reply widget.我正在使用一个来电流程,它开始通话录音,提出一堆问题,收集响应,在通话结束时:停止录音并使用发送/等待回复小部件向呼叫者发送短信。 A response is expected and based on what's in the body of the incoming call, it calls a function.响应是预期的,并且根据来电正文中的内容,它调用 function。 All this works, except, I am not receiving a response back from the caller.所有这些都有效,除了我没有收到来电者的回复。

  1. My concurrent call setting =off我的并发通话设置 =off
  2. incoming trigger = incoming call来电触发 = 来电

the flow is tied to a phone number (voice)流程与电话号码(语音)相关联

I'm not sure how to get a reply back into the same flow.我不确定如何将回复回复到同一流程中。 Do I need to attach something to the message section of the phone number?我需要在电话号码的消息部分附加一些东西吗? Any guidance would be appreciated任何指导将不胜感激

A Studio flow execution represents one call, one SMS, or the incoming call trigger from the REST Trigger. Studio 流执行代表一个呼叫、一个 SMS 或来自 REST 触发器的来电触发器。 As the call initiates your flow, it will terminate when the call ends.当呼叫启动您的流程时,它将在呼叫结束时终止。

But you can work around this by using a function that gets invoked when the recording is done.但是您可以通过使用在录制完成时调用的 function 来解决此问题。 This function can then use the Twilio APIs to fetch contextual information from the call and trigger the REST API interface of the same flow (but with a different trigger). This function can then use the Twilio APIs to fetch contextual information from the call and trigger the REST API interface of the same flow (but with a different trigger).

I created a small example that does something similar:我创建了一个类似的小例子:

  1. The flow is triggered by a call, starts a recording, and gathers data流程由呼叫触发,开始录制并收集数据在此处输入图像描述

  2. There is a recording callback URL that points to my function有一个录音回调 URL 指向我的 function

// This is your new function. To start, set the name and path on the left.

exports.handler = function (context, event, callback) {

  console.log(`Recording ${event.RecordingSid} state changed to ${event.RecordingStatus}.`)

  if (event.RecordingStatus === "completed") {

    const client = context.getTwilioClient();

    return client.calls(event.CallSid).fetch()
      .then(call => {
        client.studio.v2.flows(<Flow ID>)
          .executions
          .create({
            to: call.from,
            from: <YOUR NUMBER>,
            parameters: {
              RecordingUrl: event.RecordingUrl,
            }
          })
          .then(execution => {
            console.log(`Triggered execution ${execution.sid}`)
            return callback(null, "OK");
          });
      })
      .catch(callback)
  }

  return callback(null, "OK");
};

You can find the ID of your flow in the console (or when you click on the root element and check the Flow Configuration ):您可以在控制台中找到您的流程 ID(或者当您单击根元素并检查Flow Configuration时): 在此处输入图像描述

  1. The REST API triggers a second flow execution that reads the parameter and uses them to send a text message: REST API 触发第二个流程执行,该流程读取参数并使用它们发送文本消息: 在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM