Not getting callback after task reservation fails - twilio

I'm using the Twilio TaskRouter. A call comes into our number, Twilio makes an API call to our incoming call endpoint. I send the following response:
<Response>
<Say voice="woman">Thank you for calling</Say>
<Enqueue waitUrl="/Call/HoldMusic" workflowSid="WW..."/>
</Response>
The call is successfully enqueued and my workflow kicks off. I get the workflow assignment callback and respond with the following JSON:
{
"instruction": "dequeue",
"to": "+18885551213",
"timeout": 10,
"status_callback_url": "/Workflow/Changed",
"status_callback_events": "initiated,ringing,answered,completed",
"from": "+18885551212"
}
The outbound call is successfully made to my "to" number. If I accept the call, I get the reservation.accepted event to my task router callback endpoint. If I don't accept the call (let it timeout), I don't get a notification. Because I don't get a notification the dequeue failed, I can't cancel the reservation and have the call ring down through the queue.
I also changed the workflow assignment callback to return a "call" instruction and set the "status_callback_url" but again I only receive a callback if the call is answered, not if the call times out.
Is there something I'm doing wrong, or something fundamental I'm not understanding?

To answer my own question. If you don't include the "status_callback_events" value, then Twilio will send an event for all events. The missing event was no-answer. I'm marking this as answered so that future people can see the list of Twilio events for the dequeue and call instruction.
Current known list of dequeue and call events:
queued
no-answer
initiated
ringing
answered
completed
in-progress
busy
canceled
failed

Related

Twilio voice callback

I'm having a tough time getting the Twilio Voice callback function to work properly, and would greatly appreciate any assistance in resolving this.
I have a working VOIP webapp using Python, twilio package and twilio voice SDK.
I need to get call status when a call is being made: answered, completed, ringing, in-progress and the likes.
is_record = fetch_recording_data_from_DB
handle_url = '/handle'
callback_url = '/events'
events = 'answered ringing initiated completed'
#incoming call
dial = Dial(timeout=15, record='record-from-ringing' if is_record else 'false', action=handle_url)
dial.client(
identity=contact_data['company_id'] or company_id,
status_callback_event = events,
status_callback = callback_url,
status_callback_method = 'POST'
)
return response.append(dial)
The handle_url is triggered after call ends or the 20s is exhausted with no answer to determine whether to make a call forwarding or play VM, this works fine. No error whatsoever, calls come in - I answer and talk for a while, if I don't, it goes to voicemail, records and hangs up. I see my recording, cost, duration and other data on the calls tab on Twilio console, under Monitor. All fine. I just can't get the status callback bit.
#status callback function
def stat_events():
return request.values, {'Content-Type': 'text/xml'}
.....
class StatEvents(Resource):
def post(self):
return stat_events()
Now, on the Twilio console, I can see the response and the other information (fromstate, sequencenumber,...) under Request Inspector (multiple times, as it should be) xdxxdxd.ngrok.io/events (POST, 200) regarding the call, but on my network tab (chrome) (when I make a call on the frontend) I check under the events network and see {} - empty
I tried console.log() on the events, nothing! so either I am not using this option well or there's something magical at play.
I need the status so I can save the call log to my DB (background task) when it's completed or no-answer.
data I want but it's only showing up on Twilio console and empty on network tab (apart from saving call log, I need this data to show the status on the front-end):
"Called": "+653xxxxxx",
"ParentCallSid": "CAd1ed07xxxxxxxxxxxxxxx",
"ToState": "",
"CallerCountry": "US",
"Direction": "outbound-dial",
"Timestamp": "Fri, 22 Jul 2022 08:58:56 +0000",
"CallbackSource": "call-progress-events",
"CallerState": "MI",
"ToZip": "",
"SequenceNumber": "0",
"CallSid": "CA3a39c6b1xxxxxxxxxxxxxx",
"To": "+653xxxxxxxx",
"CallerZip": "",
"ToCountry": "SG",
"CalledZip": "",
"ApiVersion": "2010-04-01",
"CalledCity": "",
"CallStatus": "initiated",
"From": "+194xxxxxxx",
"AccountSid": "ACb9f4fe8f52xxxxxxxxxxxxx",
"CalledCountry": "SG",
"CallerCity": "",
"ToCity": "",
"FromCountry": "US",
"Caller": "+1947xxxxxx",
"FromCity": "",
"CalledState": "",
"FromZip": "",
"FromState": "MI"
}```
```handle_url```'s function uses ```DialCallStatus``` in place of ```CallStatus```, as I read that this would be sent by Twilio request to the endpoint.
You describe that you are receiving requests to your /events webhook, but that you're not getting events in the browser.
When you register to receive events via a status_callback_url then those events are only sent as webhooks to your server.
However, if you have implemented the Twilio Voice SDK in JavaScript, then you can get call events by listening to events on the Twilio.Device object and on Twilio.Call objects. For example, the Twilio.Device will emit the incoming event when there is a new incoming call. And the Twilio.Call will emit accept events when an incoming call is accepted, and disconnect for when a call is over.
You can use these events to show call progress in your UI.
Events looks to be a list:
status_callback_event=['initiated', 'answered']

How to ensure Twilio returns the correct event callback?

My calls are connecting fine to the client app, and I can chat over it. However, the status of the call sent during callback events seems to be wrong.
Below is my TwiML.
response = Twilio::TwiML::VoiceResponse.new do |r|
r.dial do |d|
d.client(identity: 'xx#gmail.com',
status_callback_event: 'initiated ringing answered completed',
status_callback: 'https://example.com/twilio_callbacks/call_status',
status_callback_method: 'POST')
end
end
After the call is completed, I receive a callback with parameter CallStatus of no-answer, but checking the logs on Twilio, I was connected, and the call should have a status of completed instead.
What am I doing wrong?
Twilio developer evangelist here.
The completed statusCallback event may have many different statuses, from "no-answer", "busy", "completed", "failed" or "cancelled".
If, however, you believe the call status is wrong, then you should get the call SID and contact Twilio support who can look into what happened with the call.

How to collect the user input when make a call using Twilio API?

I am developing a simple application in C# which
Trigger a call using Twilio
receiver to press * after receiving the call and finish the call after pressing *
Provide the status completed if user pressed * otherwise provide different status.
I was able to make a call but not able to receive the user input Or status, I tried finishOnKey() but that didn't work, and it always provides status as completed. I didn't get much help from Twilio code sample, can someone redirect to correct article or provide the code to accomplish above.
Twilio developer evangelist here.
Once a call is answered successfully, it doesn't matter how the call is finished, the final status it reaches will be "completed". You can see more about Twilio call statuses in this documentation. You can see that the final call statuses could be:
completed: call was answered successfully and then finished
no-answer: Twilio dialled the number but there was no answer before the timeout
busy: Twilio dialled the number but received a busy signal
cancelled: The number was dialled, but the call was then cancelled using the API before answering
failed: the carrier couldn't connect the call
If you are using <Gather> to take the user input, you should ensure you have set the action attribute to a URL in your application. That URL will receive a new webhook request when the user presses a digit. For example:
<Response>
<Gather action="/gather_results" digits="1">
<Say>... your content goes here ...</Say>
</Gather>
</Response>
With the above TwiML a user would only have to press 1 key before the call is moved to the next stage and the webhook '/gather_results'.
The request to the /gather_results endpoint would include a body with a Digits parameter. If the user pressed "*" then the body of the request would include Digits=*, if the user pressed "1" then it would include Digits=1. You could then choose to do whatever you like with those results, including hanging up the call or recording the submitted digits.
Let me know if this helps at all.

Twilio implement a voicemail with javascript sdk

I am currently receiving a call with the use of dequeue command.
_onReservationCreated: (reservation) =>
reservation.dequeue(
null
null
'record-from-answer'
5
'https://myurl/webhooks/twilio/completed'
'completed'
"client:#{reservation.workerName}"
(error, r) =>
if error
console.log(error)
else
console.log(r)
)
I want to send the user to voicemail after the timeout.
on my rails code, I have the webhook which is successfully called.
def completed
message = 'We are currently not able to answer your call, please leave a message'
twiml = Twilio::TwiML::VoiceResponse.new do |response|
response.say(message: message)
response.record
response.hangup
end
render xml: twiml.to_xml
end
The above is not working, the webhook is been triggered but nothing happens.
Twilio developer evangelist here.
You have the webhook URL set up as the dequeueStatusCallbackUrl. Status Callback Webhooks like this are asynchronous, so you can't affect the call by returning TwiML.
The parameters of the callback should include the taskCallSid, so you can use that to call the TaskRouter REST API to update the task, move it to a different workflow or get the CallSid and redirect the call to an endpoint that does then set up the voicemail.

Twilio, How to transfer a in-progress call to another number

How to transfer a in-progress call to another number.The concept that I m using is to use the update method when the call is in in-progress and dial the number that I wanted To connect and It is working but the connection with the first caller is breaking/
Code for the process of transferring call-
1.process for dialing call-
<Response>
<Dial callerId="callerid">
<Number statusCallbackEvent="initiated ringing answered completed" statusCallback="urltohadlestatus">user_number</Number>
</Dial>
</Response>
2. process to process to transfer the call-
I have used the update method to transfer the call.
function update_call1($CallSid, $admin_no) {
$rr = array(
"url" => "trurl?admin_no=".$admin_no,
"method" => "POST"
);
$call = $this->client->calls($CallSid)->update($rr);
return $call->to;
}
and used this TwiML
<Response>
<Dial>admin_number_call_to_be_transfered</Dial>
</Response>
what this does is transfer the call but when admin receives it,It disconnects the call.
And what I need like when jack make call to jenny and now jack want to transfer the call to jhonny and when call is transferred to jhonny, jack shound be disconnected from the call.
Twilio developer evangelist here.
You have two options here. Once the call is transferred away, the other caller will drop if it has nothing else to do. There are two ways you can achieve this.
You can either put the callers in a <Conference>. Then when the caller is transferred the other call remains in the conference room. There is a good tutorial on warm transfers using this technique, which might help.
Alternatively, if the side of the call that is dropping out right now is the one that generated the call from the Twilio REST API you can add more TwiML below the <Dial> verb to have the call continue. For example:
<Response>
<Dial>OTHER_NUMBER</Dial>
<Say loop="0">You are still on the call.</Say>
</Response>
Will just keep saying "You are still on the call" once the other end is transferred away.
You can also achieve this with the action attribute for <Dial>. Using the action attribute means that Twilio will make a webhook request to the URL you specify and use the TwiML from that response to carry on the call.

Resources