For my Twilio number I have TwiML App and I am using Flask as a backend to handle URL for incoming calls. My goal is to create behavior that for every incoming call it hangs up (and send sms, but this is not so relevant at the moment)
so far I used:
Twiml Response with Hangup ends with "busy signal"
Twiml Response with Reject ends with message "number you are calling is not available"
using twilio rest client (like in Twilio's example) client.calls.update("CAe1644a7eed5088b159577c5802d8be38", status="completed") also results in "busy signal"
twilio rest client: client.calls.hangup(twilio_call_sid) also results in "busy signal"
so I am running out of ideas and I can't believe that it's not possible to finished incoming call (without answering) clearly with no busy signal, or I am probably missing something.
I would appreciate any help
Realize this is coming way late, but if you want to simply respond to incoming calls with an SMS you can use the <Sms> TwiML verb to do so.
And then from the users perspective, gracefully end the call with <Hangup>.
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Sms from="+14105551234" to="+14105556789" action="URL_TO-HANGUP_TWIML">Say hello StackOverflow.</Sms>
</Response>
Related
I am writing an application in which we would like to receive an incoming call and stream it.
To achieve this we have configured the following twiml
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Start>
<Stream url='wss://<URL>/api/twilio/audio/stream' />
</Start>
<Say language='en-US'>Hello</Say>
<Gather method='Get' action='http://<URL>/api/twilio/incoming/response' input='speech'/>
</Response>
The idea is to start the streaming as soon as the call is connected, and then make the call continue using gather. The gather action would respond back with another gather. The call will be disconnected once the necessary actions are done.
What we are observing is that the stream starts, but the call gets disconnected post that and the gather action is never called.
Would appreciate if someone can point out what I am doing wrong and how to resolve the issue.
Finally figured out what the issue was, with some help from Twilio support
In this case the request was being sent to http:///api/twilio/incoming/response
The response from the /incoming/response API was a Twmil, but the content type was text/plain;charset=UTF-8
This made Twilio just play out the string.
Modified it to text/xml and that fixed the issue.
I have an application where I need to delay answering the incoming call while I ring multiple agents in parallel, and then connect the incoming call to one selected agent. Note that for this application it is not an option to answer the call and play a MP3 that mimics a phone ringing - the calling system is an automated system that recognizes when the call has been answered and immediately looks for an agent to respond.
If I want to forward to a single agent's phone, <Dial> + answerOnBridge works perfectly.
I have not been able to come up with a solution for ringing multiple agents in parallel. My issue is holding off the incoming call from being answered. I've tried:
Delay responding to incoming webhook while I locate an agent (Twilio times out)
Respond to the incoming webhook with short duration <Pause> only. Twilio re-sends the incoming webhook after the timeout (with a new CallSid which complicates things). This might work (I can bridge the call on a later retry once I locate an agent), but unfortunately some carriers seem to not handle this <Pause> only - I see Call Failed.
Respond to the incoming webhook with long duration <Pause> + <Hangup>. Then when an agent answers, redirect the incoming call with client.calls().update(). This fails with:
TwilioRestException: HTTP 400 error: Unable to update record: Call is not in-progress. Cannot redirect.
NOTE: the update() works if I respond in a way that answers the incoming call ... but that doesn't work for me.
Is there some other way to keep the incoming call ringing / truly not answered while I broadcast call a few agents, and then connect the incoming caller to one selected agent? Conceptually I'd like something that does a <Enqueue> + answerOnBridge, but I'm running out of ideas for how this can be done...
Twilio developer evangelist here.
Have you tried using multiple <Number>s within your original <Dial answerOnBridge="true">? That would dial each number until one is picked up, connecting the agent who answered and cancelling the other calls.
Something like:
<Response>
<Dial answerOnBridge="true">
<Number>FIRST_NUMBER</Number>
<Number>SECOND_NUMBER</Number>
</Dial>
</Response>
Let me know if that helps.
Do Play verb with loop 0 value cause the music to play till the call is connected?
https://www.twilio.com/docs/api/twiml/play
Twilio developer evangelist here.
Effectively in this situation you are looking to put your user in a queue while you dial your agents. This is how you'd do it:
First up, when you receive the incoming call you can respond with <Enqueue> that directs a user into a queue. You can set a waitUrl attribute that allows you to define either a music file or TwiML that will play while the user waits for the call to be answered.
<Response>
<Enqueue waitUrl='/wait-music'>incoming</Enqueue>
</Response>
While your incoming caller is waiting, you can then start making calls to your agents using the REST API. Once an agent connects and accepts the whisper you would then join the calls by dialling the <Queue>.
<Response>
<Dial><Queue>incoming</Queue></Dial>
</Response>
With this method you'd need to maintain whether your user has been answered yet and manually handle whether to redirect their call from the queue to more TwiML to <Record> a voicemail.
There is a more robust way to set all this up. It still requires enqueueing in the first place, but you should take a look at TaskRouter. It's an automated call distribution service with configurable workflows. There's a bit more setup involved on the Twilio side, but TaskRouter will handle directing calls to your agents and allow you to define rules for how to handle a user who's been waiting too long. I recommend you check out the TaskRouter documentation and then take a look at the quickstart guide as an example.
Let me know if that helps at all.
My Twilio server has 3 pages
/listener
Sets up a <dial> and <Conference statusCallback="/gather" statusCallbackEvent="speaker start"> and appends caller to said conference. In the conference, the events request should be sent on any user speaking and conference starting (starting is just used for debugging in case it's something wrong with speaking alone, but the starting request won't be sent as well).
/gather
Uses gather to listen to speech with action='/parse'
/parse
Parses the message.
Right now, when I set the webhook to /gather, I could see 2 POST requests to /gather and /parse no problem. But when I set it to /listener, only 1 POST request per call would appear and no subsequent requests would be sent on conference start or people speaking. Can anyone possibly tell me any example of statusCallbackEvent working with gather or provide any workarounds?
Twilio developer evangelist here.
It looks to me like you are trying to use speech detection on the ongoing conference call via events?
If that is the case, then I'm afraid that is not what statusCallbacks in <Conference> do. statusCallback events during calls are asynchronous callbacks, your response to them will not affect the ongoing call. Responding to a statusCallback event with TwiML will have no effect.
Subsequently, it's not possible to simultaneously continue a <Conference> and use <Gather> on the participants.
For Outbound Calls From An App to a Number,
There are two legs - One between my browser and Twilio and the other between Twilio and the number to be dialled
Can I set a webhook to trigger, on each callstatus value change (especially when the Call Status is in-progress) of the second leg and How?
This is necessary so that I can start the timer and show hold button only after the customer picks up the phone
Any other idea to achieve this also Welcome. Thanks in advance.
Twilio developer evangelist here.
When you dial out from Twilio Client you can send parameters into the request, such as the number, then Twilio will send your application a webhook with those parameters to find out what to do next. To dial a number, you would use the <Dial> verb and nest a <Number> within it.
With a <Number> you can register for webhook callbacks when certain events take place. You do so by setting a statusCallback attribute to the URL that will receive the callback. By default the statusCallback URL will only receive the completed event when the call finishes, however you can register for more events using the statusCallbackEvent attribute.
The event you want to subscribe too is called "answered" and the TwiML you need is:
<Response>
<Dial>
<Number statusCallback="http://example.com/calls/callback" statusCallbackEvent="answered">
NUMBER TO DIAL
</Number>
</Dial>
</Response>
Let me know if that helps at all.