问题
The following twiml used to work a few years ago for recording calls:
<?php
header("content-type: text/xml");
?>
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say voice="woman" language="en-gb">This call may be recorded for quality assurance.</Say>
<Dial record='true' action='https://URL.TLD/TWIML/record.php' method='post'>+15555555555</Dial>
</Response>
Now it returns an empty recording link. Revisiting the Twilio documentions lead me to this which says the recording may not be ready right away and to use recordingStatusCallback
<Dial record='true' action='https://URL.TLD/TWIML/do-something.php' recordingStatusCallback = 'https://the-url-thats-supposed-to-do-something-with-the-actual-recording.php' method='post'>+15555555555</Dial>
The problem I'm having is that recordingStatusCallback
doesn't say what number the call came from. I tried saving it to a $_SESSION
variable, but Twilio isn't passing the session ID when it requests the callback url.
Twilio does pass a CallSid
, which could be written to a file or database, and then subsequently pulled, matching on the Sid to the caller's phone number, but isn't there some other way to tie the caller's phone number to the actual recording being made?
回答1:
The solution was slow to come to my mind. I could simply pass the caller ID in as a GET parameter in the recordingStatusCallback as follows:
<Dial record='true' action='https://URL.TLD/TWIML/do-something.php' recordingStatusCallback = 'https://the-url-thats-supposed-to-do-something-with-the-actual-recording.php?caller=<?=$_REQUEST['Caller']?>' method='post'>+15555555555</Dial>
(In mycase it's php, but it doesn't matter what language you're generatign the Twiml in.)
I didn't use to have to do this. Twilio use to respect session cookies, and at one point would send a ready recording URL to the action URL.
回答2:
You will need to use the Calls resource along with the CallSID to obtain the callers number.
Fetch a Call resource
来源:https://stackoverflow.com/questions/59082022/twilio-twiml-record-action-returns-empty-recording-and-callback-returns-empty-ca