Twilio PHP SDK,拨打电话,接收用户输入的 DTMF 并重定向电话
Twilio PHP SDK, make outbound call, receive DTMF input from user and redirect call
我正在尝试使用 Twilio PHP SDK 从 Twilio 进行出站呼叫。但我无法弄清楚如何从该调用中获取 DTMF 输入,然后根据该输入执行一些操作,例如如果按 1,则将被叫号码连接到另一个号码。
这是我的外呼代码:
$call = $client->calls->create(
$phone, "+1xxxx",
array(
"url" => "http://demo.twilio.com/docs/voice.xml",
"method" => "GET",
"statusCallbackMethod" => "POST",
"statusCallback" => "http://xxxx.com/twilio/call_xxx",
"statusCallbackEvent" => array(
"answered"
)
)
);
以及处理 webhook 请求的代码:
//Use the Twilio PHP SDK to build an XML response
$response = new Twiml();
//If the user entered digits, process their request
if(array_key_exists('Digits', $_POST)) {
switch ($_POST['Digits']) {
case 1:
$dial = $response->dial();
$dial->number($phone);
break;
default:
$response->say('Goodbye.');
}
} else {
//If no input was sent, use the <Gather> verb to collect user input
$gather = $response->gather(array('numDigits' => 1));
// use the <Say> verb to request input from the user
$gather->say("This is xxx. $name just requested a voucher. Press 1 to connect with them now.");
// If the user doesn't enter input, loop
$response->redirect('/twilio/call_xxxx');
}
//Render the response as XML in reply to the webhook request
header('Content-Type: text/xml');
echo $response;
我哪里出错了?
根据您的代码,您在这里犯了一个错误:
"url" => "http://demo.twilio.com/docs/voice.xml",
"method" => "GET",
真的应该是:
"url" => "http://xxxx.com/twilio/call_xxx",
"method" => "POST",
获取调用流程的 TwiML 并传递您要查找的 Digits
。
至于 statusCallback
,如果需要,您必须使用不同的代码创建另一个端点(与跟踪呼叫状态有关)。
我建议,先让它在没有 statusCallback 的情况下工作(您可以暂时删除 statusCallback... 行)。
我正在尝试使用 Twilio PHP SDK 从 Twilio 进行出站呼叫。但我无法弄清楚如何从该调用中获取 DTMF 输入,然后根据该输入执行一些操作,例如如果按 1,则将被叫号码连接到另一个号码。
这是我的外呼代码:
$call = $client->calls->create(
$phone, "+1xxxx",
array(
"url" => "http://demo.twilio.com/docs/voice.xml",
"method" => "GET",
"statusCallbackMethod" => "POST",
"statusCallback" => "http://xxxx.com/twilio/call_xxx",
"statusCallbackEvent" => array(
"answered"
)
)
);
以及处理 webhook 请求的代码:
//Use the Twilio PHP SDK to build an XML response
$response = new Twiml();
//If the user entered digits, process their request
if(array_key_exists('Digits', $_POST)) {
switch ($_POST['Digits']) {
case 1:
$dial = $response->dial();
$dial->number($phone);
break;
default:
$response->say('Goodbye.');
}
} else {
//If no input was sent, use the <Gather> verb to collect user input
$gather = $response->gather(array('numDigits' => 1));
// use the <Say> verb to request input from the user
$gather->say("This is xxx. $name just requested a voucher. Press 1 to connect with them now.");
// If the user doesn't enter input, loop
$response->redirect('/twilio/call_xxxx');
}
//Render the response as XML in reply to the webhook request
header('Content-Type: text/xml');
echo $response;
我哪里出错了?
根据您的代码,您在这里犯了一个错误:
"url" => "http://demo.twilio.com/docs/voice.xml",
"method" => "GET",
真的应该是:
"url" => "http://xxxx.com/twilio/call_xxx",
"method" => "POST",
获取调用流程的 TwiML 并传递您要查找的 Digits
。
至于 statusCallback
,如果需要,您必须使用不同的代码创建另一个端点(与跟踪呼叫状态有关)。
我建议,先让它在没有 statusCallback 的情况下工作(您可以暂时删除 statusCallback... 行)。