简体   繁体   English

启用机器检测的Twilio语音api调用url和statusCallback的顺序

[英]Twilio Voice api order of calling url and statusCallback with machine detection enabled

While making twilio calls, we have a url and a statusCallback parameter like this: 在进行twilio调用时,我们有一个url和一个statusCallback参数,如下所示:

client.calls
  .create({
     method: 'GET',
     statusCallback: 'https://www.myapp.com/events',
     statusCallbackMethod: 'POST',
     statusCallbackEvent: ['completed', 'answered'],
     url: 'http://demo.twilio.com/docs/voice.xml',
     to: '+14155551212',
     from: '+18668675310'
   })
  .then(call => console.log(call.sid))
  .done();

(From here ) (从这里

I am having a hard time figuring out whether the url is called before the statusCallback or vice versa? 我很难弄清楚是否在statusCallback之前调用了url反之亦然?

I see that when machineDetection is enabled in a call (as given here ) if Answered_by is machine_start then the statusCallback is called before the url (that supplies the twiml). 我看到,当machineDetection在呼叫启用(给出这里 )如果Answered_bymachine_start那么statusCallback之前被称为url (即供应twiml)。

While in one case I found out that if machineDetection enabled and Answered_by was human (ie. it detected a human picking up the call), I saw the url called first. 在一种情况下,我发现如果启用了machineDetectionAnswered_byhuman (即它检测到有人接听了电话),则我看到该url首先被调用。

So what is the expected order of invoking url and statusCallback ? 那么,调用urlstatusCallback的预期顺序是什么? (Assuming that I have setup statusCallback to be called for an in progress call) (假设我有一个setup statusCallback被正在进行的呼叫调用)

Twilio developer evangelist here. Twilio开发人员布道者在这里。

From the documentation on calls , here's some other detail about the statusCallback : 调用文档中 ,这是有关statusCallback其他一些详细信息:

A URL that Twilio will send asynchronous webhook requests to on every call event specified in the StatusCallbackEvent parameter. Twilio将在StatusCallbackEvent参数中指定的每个呼叫事件上将异步Webhook请求发送到的URL。 If no event is specified, Twilio will send completed by default. 如果未指定事件,则默认情况下Twilio将发送完成

The StatusCallbackEvent parameter can be set to any or multiple of initiated, ringing, answered, and completed. 可以将StatusCallbackEvent参数设置为启动,响铃,应答和完成的任何一个或多个。

Since you don't have an event setup, you are using the default completed event. 由于您没有事件设置,因此您使用的是默认的completed事件。 This event should be fired once the call is over. 通话结束后应触发此事件。 If you are seeing it fire before your URL is called, are you using other events? 如果在调用URL之前看到它触发了,您是否正在使用其他事件?

The other thing is that these events are fired asynchronously to the call. 另一件事是这些事件与调用异步触发。 Even if the ringing event is fired, by the time your web server responds to it, the call may be over. 即使触发了ringing事件,在您的Web服务器响应它时,呼叫也可能已经结束。 So I would program defensively for the state of the call, not assume that the call is definitely in progress. 因此,我将为通话状态进行防御性编程,而不是假设通话肯定正在进行中。

More clearly: The events fire asynchronously, so you cannot guarantee that the answered callback will be fired before or after the url param is fetched. 更清楚的是:这些事件是异步触发的,因此您不能保证在获取url参数之前或之后都会触发answered回调。

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

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