收到来电时,我需要让来电者录制留言。然后拨打一个号码,并在接收者接听电话时播放录制的信息。
这可能吗?
答案 0 :(得分:4)
注意:用您的值替换帐户SID,验证令牌,电话号码,网站地址。
第1步。
接听来电和录音留言(http://somewebsite.xyz/recordMessage.php
)
<?php
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<Response>
<Say>
Please leave a message at the beep.
Press the star key when finished.
</Say>
<Record
action="http://somewebsite.xyz/makeOutgoingCall.php"
maxLength="60"
timeout="10"
finishOnKey="*"
/>
<Say>I did not receive a recording</Say>
</Response>
https://www.twilio.com/docs/api/twiml/record
录制完成后,Twilio将向“操作”网址发出请求,并将记录的网址作为名为RecordingUrl
($_REQUEST['RecordingUrl']
)的参数传递
第2步。
拨打电话(http://somewebsite.xyz/makeOutgoingCall.php
)
<?php
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<Response>
<Say>Thank you for your message. Goodbye.</Say>
<Hangup/>
</Response>
<?php
// Include the Twilio PHP library
require 'Services/Twilio.php';
// Twilio REST API version
$version = "2010-04-01";
// Set our Account SID and AuthToken
$sid = 'AC123';
$token = 'abcd';
// A phone number you have previously validated with Twilio
$phonenumber = '4151234567';
$recordingUrl = urlencode($_REQUEST['RecordingUrl']);
// The URL Twilio will request when the call is answered
$twilioRequestUrl = "http://somewebsite.xyz/playRecordedMessage.php?RecordingUrl=".$recordingUrl;
// Instantiate a new Twilio Rest Client
$client = new Services_Twilio($sid, $token, $version);
try {
// Initiate a new outbound call
$call = $client->account->calls->create(
$phonenumber, // The number of the phone initiating the call
'5101234567', // The number of the phone receiving call
$twilioRequestUrl
);
//echo 'Started call: ' . $call->sid;
} catch (Exception $e) {
//echo 'Error: ' . $e->getMessage();
}
https://www.twilio.com/docs/libraries/php
https://www.twilio.com/docs/quickstart/php/rest/call-request
第3步。
播放录制的讯息(http://somewebsite.xyz/playRecordedMessage.php
)。
<?php
// and play the recording back, using the URL that Twilio posted
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<Response>
<Say>Take a listen to your message.</Say>
<Play><?php echo $_REQUEST['RecordingUrl']; ?></Play>
<Say>Goodbye.</Say>
</Response>
https://www.twilio.com/docs/quickstart/php/twiml/play-mp3-for-caller