[英]Detecting when a Twilio REST API call is terminated
Using the Twilio REST API
and Conference
you can create a call between the caller and the rep that the rep can leave and re-enter by pressing * or 0. 使用Twilio REST API
和Conference
您可以在呼叫者和代表之间创建呼叫,代表可以离开并按*或0重新输入。
When the rep presses * within a Conference
the script on the reps end removes them from the Conference
and takes them to a backend where they can find out what the customer needs, leaving the caller in an empty Conference
until the rep re-joins by pressing 0. 当销售代表在Conference
按*时,销售代表端的脚本会将其从Conference
删除,并将其带到后端,在那里他们可以找到客户的需求,从而将呼叫者留在空的Conference
直到销售代表通过按来重新加入0。
If the rep hangs up within the Conference
, the callback " $_POST['CallStatus'] = completed
" is made. 如果代表在 Conference
挂断,则进行回调“ $_POST['CallStatus'] = completed
”。 This lets the script know to end all open Conference
s, thus redirecting any waiting callers to the main menu. 这使脚本知道结束所有打开的Conference
,从而将所有等待的呼叫者重定向到主菜单。
However if the rep hangs up while outside of the Conference
(using the backend, while a caller remains waiting) the same callback is not made. 但是,如果代表在Conference
之外(在使用后端,而呼叫者仍在等待时)挂断电话,则不会进行相同的回调。
What variables would indicate that the REST API
call to the rep has hung up? 哪些变量表明对代表的REST API
调用已挂起? I thought it was $_POST['CallStatus']
or $_POST['DialCallStatus']
but I've listened for both but have not been able to produce an on-disconnect callback for the rep's end. 我以为是$_POST['CallStatus']
或$_POST['DialCallStatus']
但我都听了,但未能为代表端建立断线回调。
The following variables are sent to Calls.xml
via the REST API
: 通过REST API
将以下变量发送到Calls.xml
:
From => $from
To => $to
Url => $script_url
StatusCallback => $callback_url
StatusCallbackEvent => array( "initiated", "ringing", "answered", "completed" )
$callback_url
works and detects $_POST['CallStatus'] = in-progress
but not completed
. $callback_url
有效并检测到$_POST['CallStatus'] = in-progress
,但未completed
。 (unless the rep hangs up within the conference, then it works as intended) (除非代表在会议中挂断,然后按预期工作)
CALL FUNCTION 通话功能
class Call
{
var $url = 'https://api.twilio.com/2010-04-01/Accounts/XXXXXX/Calls.xml';
var $from = '+1XXXXXX';
function dial( $number, $script, $callback = false )
{
$switch = 'http://XXXXXX.com/' . $script . '.php';
$post = array( 'From' => $this->from, 'To' => $number, 'Url' => $switch );
if ( $callback )
{
$post['StatusCallback'] = $callback;
$post['StatusCallbackEvent'] = array( "initiated", "ringing", "answered", "completed" );
}
$curl = curl_init();
curl_setopt( $curl, CURLOPT_URL, $this->url );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $curl, CURLOPT_VERBOSE, 1 );
curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, 0 );
curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, 1 );
curl_setopt( $curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC );
curl_setopt( $curl, CURLOPT_USERPWD, 'XXXXXX:XXXXXX' );
if ( $post )
{
$data = array();
foreach ( $post as $property => $value )
{
array_push( $data, $property . '=' . $value );
}
curl_setopt( $curl, CURLOPT_POST, 1 );
curl_setopt( $curl, CURLOPT_POSTFIELDS, implode( '&', $data ) );
}
$page = curl_exec( $curl );
curl_close( $curl );
return $page;
}
}
THE CALL 通话
$call = new Call;
$call->dial( $number, $script, $callback );
Twilio developer evangelist here. Twilio开发人员布道者在这里。
You get that callback with the completed
status when the rep hangs up during the call due to the nature of the action
attribute on the <Dial>
verb. 当呼叫由于<Dial>
动词上的action
属性的性质而在通话期间挂断时,您将获得具有completed
状态的回调。 However, once you are outside of a <Dial>
then you no longer have that. 但是,一旦您位于<Dial>
之外,就不再需要它了。
There is a way to do this though! 有办法做到这一点! You need to set up to receive call progress events. 您需要进行设置以接收呼叫进度事件。 You can register to receive webhooks for various events that a call goes through, from queued through to completed. 您可以注册以接收呼叫经过的各种事件(从排队到完成)的webhook。 You can register for these using the StatusCallback
and StatusCallbackEvent
parameters when generating a call from the REST API. 从REST API生成调用时,可以使用StatusCallback
和StatusCallbackEvent
参数为它们注册。 You can then get a webhook when the call is over, even when you outside of a <Dial>
. 通话结束后,即使您在<Dial>
之外,也可以获取一个Webhook。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.