Twilio twiml record action returns empty recording and callback returns empty caller parameter

二次信任 提交于 2019-12-23 03:16:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!