Twilio基本和呼叫转移 [英] Twilio basic and call forwarding
问题描述
我对twilio极为陌生,我在twilio上创建了一个测试帐户,他们给了我一个电话号码.
I am extremely new to twilio, I created a test account on twilio, they gave me a number.
现在,我想将给定呼叫(由twilio给定)转发到任何其他号码.我可以从twilio的网站上做到这一点.
Now I want to forward call coming to that given(given by twilio) to any other number. I am able to do this from twilio's website.
但是,我想通过我的应用程序实现这一点, 1.一方面,有我的电话号码, 2.在另一侧,有一个文本框,我将在其中提供转接电话的号码 和 3.一个保存按钮,它将保存更改,按此按钮后,只要有人呼叫twilio给定的号码,该来电就会被转接到文本框中指定的号码
But, I want to make this happen through my application, where 1. On one side, there is my number and 2. one other side, there is a textbox, in which I will give the number, on which the calls will be forwarded and 3. a save button, which will save the changes, after pressing which, whenever someone calls on the number given by twilio, that incoming call will be forwarded to the number specified in textbox
我想通过PHP实现此功能
I want to achieve this functionality through PHP
但是twilio完全不知道.
But am totally unknown to twilio.
希望获得帮助.
任何帮助将不胜感激.
预先感谢您的帮助.
推荐答案
$success_flag = false;
$phone_number_array = "";
$phone_number_array = json_decode($_POST['phone_number_array'], true);
$phone_number_array=array_map('trim',$phone_number_array);
$forward_number_array = "";
$forward_number_array = json_decode($_POST['forward_number_array'], true);
$forward_number_array=array_map('trim',$forward_number_array);
$arrResponse = $forward_number_array;
try {
for ($counter=0; $counter < count($phone_number_array); $counter++) {
foreach ($client->account->incoming_phone_numbers->getIterator(0, 50, array(
"PhoneNumber" => $phone_number_array[$counter]
)) as $number
) {
$voice_url = "http://twimlets.com/forward?PhoneNumber=" . $forward_number_array[$counter];
$number->update(array(
"VoiceUrl" => $voice_url,
));
$success_flag = true;
}
}
} catch (Exception $e) {
$success_flag = false;
$error = "\n\nError in forward numbers : " . $e;
file_put_contents("debug_file.txt", print_r($error, true), FILE_APPEND);
}
if($success_flag==false){
$response = "no records found";
echo $response;
}else{
$response = "Changes saved successfully";
echo $response;
}
这篇关于Twilio基本和呼叫转移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!