How to Add Custom Parameters when Recording Twilio Call? - twilio

How would you recommend associating a Twilio call recording with the call?
Is there a parameter that shows which call the recording applies to? Here is the documentation: https://www.twilio.com/docs/api/twiml/record
Or is there a way to pass a custom parameter from my app such as "event_id" when setting up the recording below?
<Dial hangupOnStar="true">
<Conference record="record-from-start" eventCallbackUrl="/twilio/receive_recording_url">custom_conference_id from my app</Conference>
</Dial>

Twilio will pass the recording URL with its request to the "action" url
<?xml version="1.0" encoding="UTF-8"?>
<!-- page located at http://example.com/voicemail_record.xml -->
<Response>
<Say>
Please leave a message at the beep.
Press the star key when finished.
</Say>
<Record
action="http://foo.edu/handleRecording.php"
method="GET"
maxLength="20"
finishOnKey="*"
/>
<Say>I did not receive a recording</Say>
</Response>
http://foo.edu/handleRecording.php will receive via GET:
RecordingUrl: the URL of the recorded audio
RecordingDuration: the duration of the recorded audio (in seconds)

Related

Twilio - Use Gather DTMF with Stream

I am trying to build a system that captures my media stream when I call into a twilio inbound number. If the user presses the # key, I would like to disconnect the call.
In my nodejs code, I handled the answer call request as:
res.send(`
<Response>
<Say> Welcome to XYZ </Say>
<Gather input="dtmf" finishOnKey="#" timeout="60" action="/completed">
<Stream name="description" url="wss://${req.headers.host}/"/>
</Gather>
</Response>
`);
and my completed method is declared as:
app.get("/completed", (req, res) => res.send(`<Hangup />`));
But the call waits for 60 seconds and media doesn't streams to wss event, though disconnect on pressing # key. Whereas if I write
res.send(`
<Response>
<Say> Welcome to XYZ </Say>
<Start>
<Stream name="description" url="wss://${req.headers.host}/"/>
</Start>
<Pause length="15" />
<Gather input="dtmf" finishOnKey="#" timeout="60" action="/completed">
</Gather>
</Response>
`);
then, the media stream to wss connection but dtmf doesn't works. Any suggestion to solve this scenario?

Convert TWIML (Gather and Dial) to use API and VOIP

I'm currently looking at a basic example of create call https://www.twilio.com/docs/voice/api/call#create-a-call-resource.
The TWIML fetched in the url parameter uses the <Gather> verb to call a number via the action attribute then <Say> something on a loop. Once the DTMF input is detected it dials a second number:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Gather input="dtmf" action="/dial/john" method="POST">
<Say loop="0">Press a key to connect to John</Say>
</Gather>
</Response>
response at /dial/john:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial>415-123-4567</Dial>
<Hangup/>
</Response>
Now, my question is would it be possible to use the API to do the exact same and reduce costs? The cost per minute for each call is GBP0.0175 whereas I believe it could be lower using the API / SIP / VOIP?
TIA
Using you can tell Twilio you want to connect to a PSTN phone <Number>, a <Sip> endpoint, a <Client> ID or even a Twilio Programmable Wireless <Sim> card.
Depending on which if these you use they will have different costs.
Hope that helps.

Can I insert a variable into TwiML? In particular, to insert the phone number of the number called?

Is there a way to implement the following in TwiML? The goal is to produce a reasonably-sounding voicemail on Twilio.
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Pause length="15"/>
<Say voice ="woman">
You have reached the voice mail of ##The_Phone_Number_One_has_Called##.
Please leave a message at the beep.
</Say>
<Record
transcribe="true"
/>
</Response>
I have a bunch of Twilio numbers and would like to have the string "##The_Phone_Number_One_has_Called##" replaced by the number that the caller is calling. Please advice if I should deploy a dedicated TwiML for each phone number.
Using Templates with a TwiML Bin, and Polly voices, try something like this for the bin:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Pause length="15"/>
<Say voice="Polly.Joanna">
You have reached the voice mail of
<say-as interpret-as="telephone">{{To}}</say-as>.
Please leave a message at the beep.
</Say>
<Record
transcribe="true"
/>
</Response>
How to use templates with TwiML Bins
(https://support.twilio.com/hc/en-us/articles/230878368-How-to-use-templates-with-TwiML-Bins)
Amazon Polly
(https://www.twilio.com/docs/voice/twiml/say/text-speech#amazon-polly)
You could do it on your server's code. Just replace the "##The_Phone_Number_One_has_Called##" with the phone that the user called.
Remember that you get the number that the user dialed on the post param "To" on each of Twilio's requests to your server, so from your server you could return:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Pause length="15"/>
<Say voice ="woman">
You have reached the voice mail of $POST["To"].
Please leave a message at the beep.
</Say>
<Record
transcribe="true"
/>
</Response>
And your server will render a different phone each time, and Twilio's will say it. Just a heads up, the $POST["To"] has the format "+1XXXXXXXXXX", so you might want to remove the +1.

Twilio hangupOnStar not working

I'm really struggling to figure out what is wrong with my script. I'm trying to setup a conference call that can be muted when the user presses *6. I have the logic working on the server, but no matter what I do in the Twiml, the hangupOnStar doesn't work.
This is the initial twiml when the user has entered the correct pin to the conference;
<?xml version="1.0" encoding="UTF-8" ?>
<Response>
<Dial hangupOnStar="true">
<Conference muted="false">Conf Room 4</Conference>
</Dial>
<Gather action="/twilio/mute" numDigits="1" />
</Response>
I have connected to the conference with 2 phones, so the conference works. But if i press * on either phone, nothing happens, both phones are still in the conference. I tried removing the gather verb and added an action to another script. But pressing star does nothing, so I'm unable to even get to the Gather verb or disconnect myself from the call.
Any ideas?
Thanks

Twilio Gather, take user's input without delays

I am using gather verb to take user's input, but I play mp3 before user press a key.
The problem is I would like to post a user's input to action URL before mp3 file is finished to play.
My TwiML doesn't take any user's inputs until the mp3 file is finished to play.
I am not sure if there is a way to just post user's input right away when user press a key.
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Play>http://www.action.com/greeting.mp3?1925924752</Play>
<Play>http://www.action.com/selection.mp3?1925924752</Play>
<Gather NumDigits="1" Timeout="5" Method="GET" Action="Http://www.action.com/handler.Php?Repeated=1"/>
<Redirect Method="GET">http://www.action.com/handler.php?repeated=1</Redirect>
</Response>
Thank you.
Twilio evangelist here.
Just drop those <Play> verbs into your <Gather>:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Play>http://www.action.com/greeting.mp3?1925924752</Play>
<Gather NumDigits="1" Timeout="5" Method="GET" Action="Http://www.action.com/handler.Php?Repeated=1">
<Play>http://www.action.com/selection.mp3?1925924752</Play>
</Gather>
<Redirect Method="GET">http://www.action.com/handler.php?repeated=1</Redirect>
</Response>
Hope that helps.

Resources