1

I'm struggling to find proper documentation on how to fetch the recordingURL, or even the recording SID. Twilio's documentation isn't very clear, can someone help me out on this? Specifically in PHP, but any help is appreciated.

1 Answers1

1

When you set a recordingStatusCallback URL on a call that you are recording, Twilio will send you webhook requests to that URL as the recording goes through various statuses (in-progess, completed, or absent).

The request will be like other Twilio voice webhook requests, it is sent in the format application/x-www-form-urlencoded and includes a number of request parameters that tell you about the call or recording in this case. The recording request parameters are listed here. They include RecordingSid and RecordingUrl which you can use to download the media.

That recording URL may have a .json extension. If you remove the extension or replace it with .wav then you will get the recording in WAV format. If you replace the extension with .mp3 then you will get an MP3 file. You can see more about this in the docs on fetching a recording media file.

With that URL you should then be able to download the file with PHP.

philnash
  • 70,667
  • 10
  • 60
  • 88
  • Thanks for the reply. From my understanding, I can set `recordingStatusCallback = '/recordings/index.php'`. where `/recordings` is a subdirectory. In that `index.php`, can I just make a variable like `$url = $_POST['RecordingURL'];`? – RecursiveRuby Jun 01 '22 at 17:25
  • Yes, that should work! – philnash Jun 01 '22 at 20:50
  • Awesome, thanks!! That worked perfectly for me. One more thing, do you know what format the RecordingURL is? `$response->say($url);` throws an error, so I don't know if RecordingURL is in a string or not. – RecursiveRuby Jun 01 '22 at 21:05
  • Like I said in the answer you need to make sure that the extension is correct, add a `.wav` or `.mp3` extension (and remove the `.json` if it is there) and you will get WAV or MP3. I'd recommend logging out the URL so that you can see what's going on with it too. I will also note that the `recordingStatusCallback` is sent asynchronously to the rest of the call, so you can't respond directly to that webhook to influence the call. – philnash Jun 01 '22 at 23:55
  • Yeah, I understand the extension part. My reasoning for trying to say `$url` was because I thought it wasn't possible to log Twilio PHP. How can you view the log of the URL? Also, can you specify what your last sentence means? Can I not GET/POST specific parts of recordingStatusCallback? – RecursiveRuby Jun 02 '22 at 15:40
  • Why is not possible to log the parameter. The webhook is just an HTTP request to your application with a bunch of parameters in the request. There's no reason you can't log out one or all of the parameters to inspect them. Also, if you're using ngrok to tunnel to your local you could use the ngrok dashboard to inspect the incoming requests. – philnash Jun 02 '22 at 23:20