Trigger say verb during live call between device client and caller - twilio

We have a use case where we need the device client, connected within the browser, to be able to trigger different Say verbs at any given time during the live call between the device client and the caller. Whatever is said needs to be heard for both client and caller and included in the recording.
I set up an API endpoint that takes the CallSid and updates twiml, however, the statement is only heard for the device client and the calls are immediately disconnected. From my understanding, this is intended due to how TwiML works, since there is no other command after Say, so it believes the call is complete.
return await client.calls(callId)
.update({ twiml: '<Response><Say>Ahoy there!</Say></Response>' });
I've considered using a Redirect which would put the caller into a new flow to hear the prompt, however, the device client then wouldn't hear it, and it wouldn't be part of the recording, so that will not work. Using a conference call, the statement is only played for the new call either before they join or after their call ends.
Is there any way to accomplish this?

Related

Twilio: Dial failover on busy signal

Scenario:
Person A calls my server. My server returns Twiml with Dial plus extra, connecting them to my client C. Sometimes C's phone is busy, and the extra just tells A they couldn't be connected, try texting.
I want to have a failover, where the same thing happens when C is not busy, but if C is busy, A is put in a queue, as are subsequent callers. When C's call ends, I try to connect A to C.
Is there a way of doing this with simple Twiml verbs, like dial.queue, and Redirect? So far I've failed: I can enqueue A when C is busy, hearing hold music and all, but I've utterly failed to get A off the queue and in touch with C. I suspect I'll need to create calls using the API, but figured I'd ask to see if the Twiml way should be doable.
I am aware that I could just throw all callers into a queue, but for business reasons I want to preserve the "ring and connect" behavior when the client is immediately available.
Twilio developer evangelist here.
The bit here is getting A to start a new call once they are done with the call they are on. You could, for example, send an SMS message to A to tell them that someone is waiting in the queue. Then, when they call their Twilio number back return TwiML that <Dial>s into the <Queue>.
When using the <Queue> TwiML, the caller will be connected to the person waiting at the front of the queue.
Alternatively, if you don't trust A to call the queue back, you could keep trying to periodically make calls to A using the REST API and once the call connects return the same TwiML to <Dial> into the <Queue>. If the caller hangs up and the queue becomes empty before A answers the call, you can stop calling and perhaps send a message to inform A that someone called and they can choose to call them back.

Twilio - determine if a number is already in a call before initiating

I have a somewhat peculiar situation for which I can't find documentation: I have an application that will use the Twilio API to initiate a voice call from phone number X (my number) to another one. The problem is that number X could already be in the middle of another call, one that was not initiated with Twilio (so my application wouldn't know about it). Would Twilio detect this, and send an error, or try to initiate the call anyway? If the former, what would the error be? I have found the error code for "callee busy", but nothing similar to "caller busy".
Alternatively, is there an API call I could make before initiating the call to make sure number X is available and not in another call?
Twilio numbers can have multiple calls associated with them, so there would be no error id the Phone X was on an existing call (since phone numbers can be routed however you choose). You can set the outbound CallerID to be another Twilio number or a verified callerID (but if they call that verified callerID back, it wont go back to Twilio but the carrier/business owning that number).
Once the dialed party answers after making the outbound API call, you tell Twilio how to route the other piece (who to connect the answering party to) via the URL parameter hosting the Twilio Markup Language (TwiML).
There is an API call and example for, Read multiple Call resources and filter by call status and phone number (Code Example), you could query before making your outbound call (assuming you always map inbound calls to the same endpoint) or routing your inbound call (which probably makes more sense if you want to re-route to another destination who can answer the call).
The status of this call. Can be: queued, ringing, in-progress, canceled, completed, failed, busy or no-answer.

Update an in-progress Twilio call from a hard phone

I have a soft phone system set up and all is good. A call comes in to my soft phone, and I can put it on hold, transfer the call, etc. by clicking a button and sending a request to Twilio's REST API, or my server, or whatever it may be.
My question is, is it possible to update an in progress call if I am called on my SIP hard phone? What I want to do is, for example, during an in-progress call enter *1 to put the call on hold. Because it's a hard phone, I can't simply hit a button to make a request to my server.
I know I can use Gather to accept my input, but if I am on an in-progress call, how would I even initiate the Gather?
Sorry this isn’t written all that well, doing on my phone.
It would be tough, as you need the callsid to initiate redirect. However, if you store your calls in Sync Lists, you could make a Function and have it either look up the phone number of the call and return the callsid to use in the redirect or enter the unique ID for the entry on the list.
Tie that function to a phone number, call via a your desk phone, put an if(event.digits) {obtain callsid from sync, then redirect, then callback() } else {do a gather() and don’t worry about the action url as you’ll just go to the top of this function but now you’ll have event.digits, then do your callback} do not do a callback here or you’ll skip all of your above code}

Use Record and Dial together in Twilio API

I am using Twilio to create call tracking phone numbers that redirect to another number using the Dial verb. I am also recording these calls. Here is an example of my TWIML
<Response><Dial record="true" action="http://example.com/PostCall">555-555-5555</Dial></Response>
I want to be able to terminate the call recording but not the call using something like the Record verb's finishOnKey option. Is this possible?
The reason is, a call comes in to a call center and is transferred to a lawyer. I want to record the call center part of the call but not the attorney/client part of the call. If pressing # during the call could stop the recording but keep the call active it would solve my problem.
Is there a way to stop recording without terminating the call?
Can the record verb be used in conjunction with the dial verb?
The <Record> TwiML verb is best if you want to record one person talking. I'm assuming you want to record both parties connected via <Dial> in the call center so you would rely on the record attribute as you have above.
Read the FAQ for the full breakdown on the difference in recording settings.
Is there a way to stop recording without terminating the call?
Depending on the flow of your call center you might modify the live call via the REST API and redirect the call to new TwiML where you set recording to "false".
call = client.calls.update("CALL_SID", url="https://example.com/no-record.xml",
method="POST")
Alternatively, you could add Twilio itself as a 3rd call leg in a <Conference> call, and let it handle recording. This way you can use the REST API to modify that leg without disrupting the primary 2 callers, including stopping recording of the call midway through while the other 2 callers are still live.

TwiML App: If the caller hangs up in the middle of the application process, does Twilio notify the app of a hang up?

I am trying to figure out a way to capture if the caller hangs up in the middle of TwiML instructions. If the caller hangs up (abandons the call) does twilio notify the application of such?
I see the status callback url setting but I just get a "completed" status. I was wondering if the caller was in a middle of a gather and hung up would twilio know the call hung up and report it? Or am I supposed to just see the "completed" status and at that time determine if the call actually successfully completed or not?
Twilio evangelist here.
To my knowledge we don't have a specific way of telling you that a caller hung up during the middle of a <Gather> other than the status callback passing you the CallStatus, which as you points out just tells you that the call was completed, not where within a TwiML document or a call flow the caller was.
If you want to know where within a call flow the call ends (for example the caller hangs up), I'm pretty sure that is something you would need to track in your own application. You could do that by storing the callSid of the phone call along with some meta data that helps your app know where in the flow the call is, and just updating each time Twilio makes a webhook request to your app.
Hope that helps.

Resources