简体   繁体   English

Twilio Flex - 拒绝后发送呼叫到 IVR

[英]Twilio Flex - Send Call To IVR After Reject

Using this plugin as a reference, I have Flex configured to be able to send a call to a Twilio Studio IVR, after an agent has accepted a call.使用 此插件作为参考,我将 Flex 配置为能够在座席接受呼叫后向 Twilio Studio IVR 发送呼叫。

I'd like to be able to send an incoming call back to Studio when an agent rejects a call (ie as soon as they click the reject button).我希望能够在座席拒绝呼叫时(即他们一单击拒绝按钮)将来电发送回 Studio。 I'm trying to do this by adding a listener to the plugin's init method:我试图通过向插件的init方法添加一个侦听器来做到这一点:

flex.Actions.addListener("afterRejectTask", async (payload, abortFunction) => {
    let url: string = payload.task.attributes.transferToIvrUrl;
    let menu: string = 'hangup';
    await request(url, { CallSid: payload.sid, menu });
});

See here for the full context -- I'm pretty much using that exact code, with the addition of this listener.有关完整上下文,请参见此处——我几乎使用了那个确切的代码,并添加了这个侦听器。

I'm getting this error message, and the call is not transferred anywhere.我收到此错误消息,并且呼叫未转移到任何地方。

twilio-flex.unbundled-react.min.js:1574 Error on afterRejectTask: SyntaxError: Unexpected token < in JSON at position 0

Here's additional context from the console, if that's helpful:如果有帮助,这是来自控制台的其他上下文:

来自控制台的额外上下文

Additional info:附加信息:

The url being requested is a Twilio function, which successfully returns a response like this:被请求的 url 是一个 Twilio function,成功返回这样的响应:

<Response>
  <Enqueue workflowSid="WWcc1a650e4175089538d754a6c2e15a98">
    <Task>{"transferToIvrUrl": "https://my-twilio-function-service.twil.io/studio-flex-transfer-helper"}</Task>
  </Enqueue>
</Response>

Any advice would be appreciated.任何意见,将不胜感激。

Ah, ok, so looking at that plugin I found the example Twilio Function that works with it .啊,好吧,所以看着那个插件,我找到了可以使用它的示例 Twilio Function From what I can tell, this function is intended to be used in two places, either in Studio to transfer the call to Flex (though I'm not sure it's needed for that) or from Flex to transfer the call back to Studio.据我所知,这个 function 旨在用于两个地方,要么在 Studio 中将呼叫转接到 Flex(尽管我不确定是否需要这样做),要么从 Flex 将呼叫转回 Studio。 The thing that triggers the different response is whether you pass an argument called transferToIVRMenu with the request.触发不同响应的是您是否在请求中传递了一个名为transferToIVRMenu的参数。

Your current request is not passing that argument, you currently have:您当前的请求未传递该参数,您目前拥有:

    await request(url, { CallSid: payload.sid, menu });

which looks similar to the original plugin's request:这看起来类似于原始插件的请求:

    await request(transferToIvrUrl, { CallSid: call_sid, transferToIVRMenu });

The difference is in the second property in the object. When you just pass the name of the variable in an object, it expands to call the property the same name as the variable and set the value to the value within the variable.不同之处在于 object 中的第二个属性。当您仅在 object 中传递变量名称时,它会扩展为调用与变量同名的属性并将值设置为变量内的值。 So the original request expands out to:因此,原始请求扩展为:

    await request(transferToIvrUrl, { CallSid: call_sid, transferToIVRMenu: transferToIVRMenu });

but your request only expands to:但您的要求仅扩展为:

    await request(url, { CallSid: payload.sid, menu: menu });

So you are passing a parameter called menu not transferToIVRMenu and that triggers the Function on the back end to return TwiML and not to update the call.因此,您传递的参数不是transferToIVRMenu ,而是一个名为menu的参数,它会触发后端的 Function 返回 TwiML 而不是更新调用。

To fix this, you can update your plugin code to send the transferToIVRMenu parameter, like:要解决此问题,您可以更新插件代码以发送transferToIVRMenu参数,例如:

flex.Actions.addListener("afterRejectTask", async (payload, abortFunction) => {
    let url: string = payload.task.attributes.transferToIvrUrl;
    let menu: string = 'hangup';
    await request(url, { CallSid: payload.sid, transferToIVRMenu: menu });
});

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

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