Twilio - Taskrouter - Whisper during reservation - while ringing agent [duplicate] - twilio

I have two questions regarding TaskRouter.
How do I record a call when using TaskRouter?
How do I whisper to the worker when a call is bridged with caller?

Twilio developer evangelist here.
When you receive an assignment callback and you connect the caller with an agent using the call or dequeue instruction, you can send back further attributes in the response. To record the call, send the attribute record with the value record-from-answer to record the entire call.
To whisper to a worker you need to use the call instruction in your assignment callback. You can then supply a URL that will get called when the agent picks up the call before bridging the calls together which you can use as a whisper.
So, for example:
<?php
$reservationSid = $_REQUEST['ReservationSid'];
header('Content-Type: application/xml');
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<Response>
<Say>You have a new call!</Say>
<Dial>
<Queue reservationSid="<?php echo $reservationSid ?>"></Queue>
</Dial>
</Response>
See the documentation for initiating a call in the assignment callback for more information.

Related

Twilio API: Transferring connection to a forwarded number?

Im placing an outbound call, and based on the automated message from whom Twilio is calling, it calls my phone with the connection.
Here is the script that places the phone call.
import os
from twilio.rest import Client
account_sid = "xxxx"
auth_token = "xxxx"
client = Client(account_sid, auth_token)
call = client.calls.create( url='http://myhost.com/rec.php',to='+1234',from_='+9876')
print(call.sid)
The phone call is placed, and the action script sends a TwiML gather response. Here's rec.php
echo '<Response>
<Gather input="speech"
partialResultCallback="http://myhost.com/partial.php"
action="http://myhost.com/finalresult.php">
</Gather>
</Response>
I've got the partial page logging the text. But when I forward a call, my phone rings for one second, then disconnects. There's no errors in the debugger either.
Here's partial.php
if(contains("To continue in English", $_REQUEST['UnstableSpeechResult'])){
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<Response>
<Dial>+myPhoneNumber</Dial>
</Response>";
}
here is final result, which i think is called when the phone call is complete? im not sure.
if(contains("To continue in English", $_POST['SpeechResult'])){
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<Response>
<Dial>+myPhoneNumber</Dial>
</Response>";
}
According to the documentation, partialResultCallback doesn't process TwiML.
The webhooks Twilio makes to your partialResultCallback are
asynchronous. They do not accept any TwiML in response. If you want to
take more actions based on this partial result, you need to use the
REST API to modify the call.
Not sure how your phone is ringing given the above. Any more details you can provide will help troubleshoot the issue.

Get response (TwiMl) Url to connect to conference call

The problem I'm trying to solve is having a Twilio phone number connect to a TwiMl, created within my PHP code, while making an outbound call with the end result having the caller and callee in the conference room together.
To set up the TwiMl I coded:
$response = '<Response>
<Play>%s</Play>
<Dial timeout=\'60\' callerId=\'%s\'>
<Conference startConferenceOnEnter="true" endConferenceOnExit="true">
conf-test
</Conference>
</Dial>
</Response>';
And to connect the callee to the call, I'm trying to use:
$client->account->calls->create(
+1XXXXXXXXXX, //To
+1XXXXXXXXXX, //From
array(
"url" => ???));
How do I get the URL from the above TwiMl into the url to connect further participants as well as the initial callee? Is this even possible, or am I forced to use a TwiMl bin and use that URL?
You can pass in TwiML using the below approach,
Pass TwiML with Call Initiation Requests
https://www.twilio.com/changelog/pass-twiml-call-initiation-requests

Twilio api play message before call hangup

I am hanging up a call like this(java):
Call.updater('somesid').setStatus(Call.UpdateStatus.COMPLETED).update();
I would like to play a message(not via some audio file, but via the twilio 'say' verb) before this call is ended.
How do I do it if its possible?
Twilio developer evangelist here.
Instead of just completing the call with the API request, you can redirect the call to some new TwiML instead. To do so, you need a new URL to send the call to and you update it like this:
Call.updater(callSid)
.setMethod(HttpMethod.POST)
.setUrl(URI.create(newUrl))
.update();
The new URL should then return TwiML that <Say>s the message you want and then hangs up with <Hangup/>. Like this:
<Response>
<Say voice="alice">Sorry, I have to hang up now.</Say>
<Hangup/>
</Response>

Twilio TaskRouter - Whisper and recording

I have two questions regarding TaskRouter.
How do I record a call when using TaskRouter?
How do I whisper to the worker when a call is bridged with caller?
Twilio developer evangelist here.
When you receive an assignment callback and you connect the caller with an agent using the call or dequeue instruction, you can send back further attributes in the response. To record the call, send the attribute record with the value record-from-answer to record the entire call.
To whisper to a worker you need to use the call instruction in your assignment callback. You can then supply a URL that will get called when the agent picks up the call before bridging the calls together which you can use as a whisper.
So, for example:
<?php
$reservationSid = $_REQUEST['ReservationSid'];
header('Content-Type: application/xml');
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<Response>
<Say>You have a new call!</Say>
<Dial>
<Queue reservationSid="<?php echo $reservationSid ?>"></Queue>
</Dial>
</Response>
See the documentation for initiating a call in the assignment callback for more information.

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