I want to create the following:
A line number, let's say 741-SUPPORT (just an example), where people can call.
When somebody calls, I want them to listen some text (I use <Say>) and then, forward their call to my number.
When I receive the call, I want to listen to a text that announces me that this call comes from that line, and allows me to press 0 to accept de call, or any other number to reject it.
In case that I accept, both calls get connected. Otherwise, the caller should be able to leave a message.
What I've done so far:
First TWIML used when the caller calls to 741-SUPPORT
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say voice="alice" language="en-US">
This call is being recorded.
Please hold on, your are being connected.
</Say>
<Dial action="CallEnded.php" timeout="15" timeLimit="600" callerId="+1741SUPPORT" record="record-from-answer">
<Number action="JoinCall.php">+PRIVATE NUMBER HERE</Number>
</Dial>
</Response>
JoinCall.php
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Gather timeout="10" numDigits="1" action="CallAccepted.php">
<Say voice="alice" language="en-US">
You have an incomming call from 741SUPPORT.
Press 0 to accept the call, press any other number to reject the call.
</Say>
</Gather>
</Response>
CallAccepted.php
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<?php if ($_POST['Digits'] == '0') { ?>
<Say voice="alice" language="en-US">
Call accepted.
This call is being recorded.
</Say>
<?php } else { ?>
<Say voice="alice" language="en-US">
Call will be rejected.
</Say>
<Hangup/>
<?php } ?>
</Response>
CallEnded.php
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say voice="alice" language="en-US">
<?php if ($_POST['DialCallStatus'] != 'completed') { ?>
We had issues connecting the call, please try again later.
<?php } else { ?>
Thanks for your call. Goodbye!
<?php } ?>
</Say>
</Response>
So I would like to know:
How can I play hold music on the caller's side while all the logic is performed?
How can I disconnect from the call and ask the caller to leave a message?
Consider using a Enqueue.
So the person dials in then send them to the queue specifying the waitUrl. (Use this to play music).
When u accept the call dial the queue and pick up the call.
Off the top of my head, if you reject the call then you will have to use the rest api to redirect the call to another url that then says thank you but no thank you.
Related
I have set-up a SIP Domain on twilio and I've configured with the following TwinML :
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial callerId="{{#e164}}{{From}}{{/e164}}">
{{#e164}}{{To}}{{/e164}}
</Dial>
</Response>
I would like to record all inbound and outbound calls coming on this number but it fails.
I have tried this code :
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial callerId="{{#e164}}{{From}}{{/e164}}">
{{#e164}}{{To}}{{/e164}}
</Dial>
<Dial record="record-from-ringing-dual"
recordingStatusCallback="https://sample.org/api/1.1/wf/twiliocalllog"
>
<Number>+339999999</Number>
</Dial>
</Response>
Can you tell me how can I handle this issue?
(For Inbound calls, I did it with Studio and it works properly, but for outbound calls, I can't find the best way).
For the outbound call you need to use the record attribute on the <Dial> that places the call. Like so:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial callerId="{{#e164}}{{From}}{{/e164}}" record="record-from-ringing-dual" recordingStatusCallback="https://sample.org/api/1.1/wf/twiliocalllog">
{{#e164}}{{To}}{{/e164}}
</Dial>
</Response>
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?
Trying to receive recordings of calls. I'm self hosting this twiml code.
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial timeout="40"
recordingStatusCallbackEvent="in-progress,completed"
recordingStatusCallback="http://server.com/recording/">
<Number
url="http://server.com/whisper/"
statusCallbackEvent="completed"
statusCallback="http://server.com/status/">
+12142142144
</Number>
</Dial>
</Response>
Everything works as expected except the recording url is never called. The call forwards, the whisper is spoken, the status url is called, but not the recording url.
Twilio Developer Evangelist here. 👋
It looks like you're missing the record attribute. (https://www.twilio.com/docs/voice/twiml/dial#record) If it's not set it's defaulting to do-not-record.
<Response>
<Dial record="record-from-ringing-dual"
recordingStatusCallback="www.myexample.com">
<Number>+15558675310</Number>
</Dial>
</Response>
Can you add it and give it a try? Happy to help if that's not the issue. :)
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.
Is there a way with twilio to stop the welcoming message (Say) once the caller input digits and then forward it to the next IVR tree without waiting the whole message ?
Thanks
You can use numDigits attribute in GATHER with a integer value.For example, one might set 'numDigits' to '5' and ask the caller to enter a 5 digit zip code. When the caller enters the fifth digit of '94117', Twilio will immediately submit the data to the 'action' URL.
Check detail on Twilio Docs.
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Gather timeout="10" numDigits="5">
<Say>Please enter your pin number and then press star.</Say>
</Gather>
</Response>
Actually I had the Gather after the Say. Instead I should've wraped the Gather around the say:
<Response>
<Say voice="alice" language="it-IT">...</Say>
<Gather method="POST" numDigits="1" action="/twilio/ServletHandleUserInput" finishOnKey="0">
</Gather>
</Response>
So I amended it alike :
<Response>
<Gather method="POST" numDigits="1" action="/twilio/ServletHandleUserInput" finishOnKey="0">
<Say voice="alice" language="it-IT">...</Say>
</Gather></Response>
Thanks Rubai