Use Record and Dial together in Twilio API - twilio

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.

Related

Trigger say verb during live call between device client and caller

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?

Setting statusCallbackEvent on outbound calls with Voice SDK

Is there any way to change what events trigger the status callback? Normally you can use statusCallbackEvent but I can't seem to find a way to make this work for the Voice SDK's leg of the call. It works fine on the call leg of the outbound participant, but not the Voice SDK's call leg. I only get completed status event for this leg (and I also can get ringing from the called action url).
Things I tried without success:
Updating the call using the REST api to set statusCallbackEvent to initiated ringing answered completed when the outbound call starts
Setting statusCallbackEvent as an outbound parameter on the Voice SDK's token (in PHP you can set custom parameters using $clientToken->allowClientOutgoing(...) but it seems normal parameters cannot be modified)
I really wish you could set this on the TwiML Application so that any numbers calling out with that application set will just automatically use your set events. That or let me set the parameters on the client's token.
One way to fix this is just to poll for the information but that is an ugly hack and isn't real time.
Twilio developer evangelist here.
I don't think you can do what you're asking for here, but for good reason.
When you are placing the call from the Voice SDK, that call leg is then between the application and Twilio. You know the call was "initiated", because you started it. There is no "ringing" because Twilio is not a phone and won't ring. You know it is "answered" because a request is made to your voice URL defined by the TwiML app. And finally, you do get the "completed" event.
As you say, you do get the events for the outbound leg of the call from Twilio to another phone number.

Incoming Call Recording in Twilio with HOLD option

Suppose for an incoming call to a Twilio Number '+18XXXXXXXXXX' the call is forwarded to a client with name 'CLIENT'. Now there are two legs with Callsids 'CSid1' and 'CSid2'.
If the 'CLIENT' wants to hold the call, the Connection leg with Callsid 'CSid1' is redirected to a Music url. If the 'CLIENT' resumes the call, the call 'CSid1' is again redirected to the 'CLIENT' with new CallSid 'CSid3'.
Now, how to get the single recording url for the whole Incoming call (connection with CallSid 'CSid1').
Note: The recording url for connection with callsid 'CSid2' and 'CSid3' can be obtained by setting record verb in dial tag (Two recording urls).
Any other suggestions to achieve Incoming Call recording in Twilio with hold option is also welcome.
Twilio developer evangelist here.
If you want to record the whole call in one recording, including holds, then you may want to investigate using a <Conference>.
Once your original caller dials in, put them into a <Conference>, using <Dial> with the record attribute set. At the same time, use the REST API to make a phone call to the client which also lands them in the conference.
You can then use the Participants resource to hold and unhold the caller.
This would not redirect the caller, therefore giving you one recording URL.
Let me know if this helps.

Stop / Start call recording on Twilio

Is there an API that I can use to stop recording an ongoing call?
We have a feature here where you can record only pieces of a call. So you can click a button to stop recording, and then after some time you can click another button to start recording again.
How can I accomplish that on Twilio? I didn't find anything in their docs.
Twilio developer evangelist here.
There's no direct way to start and stop recording a call, however you could manage this using <Gather> and <Conference>.
The idea would be that callers would join a conference (even if there's just two of them) which recorded their call using the record attribute.
You would wrap that <Conference> in a <Gather> that was waiting for a caller to dial a particular digit which stops recording by redirecting the caller who pressed the digit to a new <Conference> without the record attribute set.
You will also need to redirect the other call to that conference too. When you get the webhook after the first caller pressed a digit to stop recording you can fire off a REST API call to redirect the second caller to the new non-recorded conference.
If you wrap this second <Conference> in a <Gather> too, you can reverse this process to start recording again.
Let me know if that helps at all.
[edit]
As a further consideration, I realised that you indicated you need a user to press a button to start or stop recording. I initially thought of this as a button on your phone, which is why I suggested using <Gather>. If, however, the user in control of recording is an agent in a call centre, for example, you could build an easier interface using Twilio Client to make or receive the calls.
Then, when the calls are connected into the initial conference you'd need to record both the Call SIDs.
You could then implement a button in your interface that when pressed transfers both calls from a recording conference to a non recording conference (or vice versa). Again, this would use the REST API to redirect the calls.

how to handle call transfer with twilio?

I'am using twilio to set up a call between 2 people
I'd like to manage call transfer asked from one side (like when a dtmf key is pressed). The other side could listen to a prompt who could be "please wait while your call is being transfered"
Any chance to do that properly with twilio?
When both parties are connected, Twilio blocks execution of further verbs until the caller or called party hangs up. That's why it is not possible in regular way.
But you can hangupOnStar attribute to hangup the caller party. And set an action URL to continue next dial verbs.
Here is a detail answer:
Twilio call transfer from in-call

Resources