Connect Twilio Outbound call to Watson Assistant - twilio

I'm trying to make an outbound call using Twilio's API and connect the number that i'm calling to my Watson Voice Agent(that is linked to my Watson Assistant). I can call the phone but the call isn't redirected to the assistant.
I'm using the Twilio API for java. I've set my Twilio number's SIP trunk to use my Voice Agent's SIP
This is the method implementation
public String callPhone(String to, String from)throws URISyntaxException{
Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
Call call = Call.creator(
new com.twilio.type.PhoneNumber(to),
new com.twilio.type.PhoneNumber(from),
new URI("http://www.example.com/sipdial.xml"))
.create();
return call.getSid();
This is my call:
tw.callPhone(phoneIWantToCall,TwilioPhoneNumber);
tw.callPhone("sip:TwilioPhoneNumber#us-south.voiceagent.cloud.ibm.com",TwilioPhoneNumber);
I receive a call from my Twilio number but it isn't directed to my Assistant

Twilio developer evangelist here.
The issue here is that you are creating two separate calls that don't connect.
Instead of generating two calls using the REST API, you need to return TwiML from the URI in your URI parameter that connects the call to the person to the Watson agent. So you should set the URI in your callPhone method to a URL in your own application. And that URI should return TwiML that includes <Dial> to connect to the agent in this case using <Sip>.
The TwiML should look a bit like this:
<Response>
<Dial>
<Sip>sip:TwilioPhoneNumber#us-south.voiceagent.cloud.ibm.com</Sip>
</Dial>
</Response>
Let me know if that helps at all.

Related

how to execute dialing a queue in twilio php?

How do I execute this code?
$response = new Twiml();
$dial = $response->dial();
$dial->queue('support', ['url' => 'about_to_connect.xml']);
echo $response;
I'm using laravel and used this function on button click. All I get is a Twiml return.
Twilio developer evangelist here.
Let me explain the use of TwiML within Twilio applications. TwiML does not initiate phone calls, it is used to react to events within phone calls.
When you receive an incoming call to your Twilio number or when you make a call via the Voice API which connects, Twilio then needs to ask your application what to do with that call. It does so by making an HTTP request to the URL you provide for the phone number or via the API request. Your application needs to respond to that request with TwiML to provide the instructions for the call.
In your case, it looks like you're trying to make a call to a number and then connect that user to the first person waiting in the support queue. To do that, you should keep the TwiML you have, just don't execute it on the button click.
Instead, when your user clicks the button you should make the API call to generate the call and direct Twilio to call this TwiML when the call connects.
This tutorial on click to call using Twilio and Laravel should help with this.

Twilio - Can I use a webhook, TwiML, Studio or Function to route Voice Calls to an elastic sip trunk

I want to setup Failover routing within Twilio phone numbers. If I can use a Webhook or other Twilio method that offers "Primary Handler Fails" then I can do this within specific numbers. I know how to create method for forwarding call to a different number that I can place in that failover field. Here is what I don't know:
How do I direct the first field "A Call Comes In" to my Elastic Sip Trunk?
Thank you!
Twilio developer evangelist here.
You can't setup calls to be forwarded to your SIP trunk in general, however you can have them forwarded to a SIP address that is registered on your trunk.
To do so, you need to use the <Dial> verb, nesting a <Sip> inside. Like this:
<Response>
<Dial>
<Sip>SIP_ADDRESS</Sip>
</Dial>
</Response>

The phone number in 'Dial' is not shown in output file

I have the following xml
<Dial timeout="10" action="file.php" method="POST">211</Dial>
which dials the hypothetical 211 to try and connect the caller with 211.
When I read what was sent via $_POST, there's no mention of 211.. Why is that?
Not using Twilio client.
Twilio developer evangelist here.
I'm guessing you are returning that TwiML, the <Dial> (within a <Response> I hope) when someone calls your Twilio number and Twilio sends a webhook to your application.
I'm not sure where you are looking for the number, 211, in the $_POST object. If it is when Twilio sends the webhook to you then this is before you have told Twilio you want to dial 211 and so Twilio doesn't know anything about it yet. If you are looking for all the parameters that Twilio sends to you in that webhook, check out this article in the docs on Twilio's request to your application in a voice call.
Are there other POST requests that Twilio is making to your application where you are expecting to see this number?

TWIML for reverse click-to-dial browser plugin

I have a mostly working chrome extension that uses the Twilio client to allow calling a number from the browser. The twilio client is too unstable to be used reliably, so I'm re-wiring the extension to just perform 'reverse click to dial', but am having trouble getting my head wrapped around the twiml flow.
Assume I have a web service that can produce twiml. Here's the call flow I want to achieve:
Agent launches my chrome extension, and gives it a phone number to dial.
Stored in the extension's settings is the twilio account sid,token, app sid for the twiml app/service, AND the number to connect the dialed number to, typically the agent's cell phone.
My extension makes a request to twilio API, which in turn requests a route in my twiml app.
some magical twiml is produced
agent's cell phone rings
agent answers
he is connected to an outbound dial to the original number he was dialing
What is the simplest twiml that will accomplish this? to boil down the flow:
agent enters number into chrome extension and clicks CALL
agent's phone rings
agent answers and is connected to number entered in step 1.
Twilio evangelist here.
The way I would do this:
Extension talks to Twilio API to start an outbound phone call to entered number
When entered number answers your app returns Twiml that tells Twilio to <Say> something like "Hold on while we connect you to an agent and then <Dial> the agent:
<Response>
<Say>Hold on while we connect you</Say>
<Dial callerId="+15555555555">
<Number>[Agent Number]</Number>
<Dial>
<Response>
If you want to reverse this to dial the agent first, just have your extension tell Twilio to call the Agent number first and then, when the Agent answers, have the TwiML say something like "Hold on while we connect you to the customer" and <Dial> the customer number.
Hope that helps.

Can you do peer to peer calls with Twilio?

If I wanted to create an interoffice phone system with Twilio can you call between two registered clients on Twilio, i.e. can I call my co-worker in the office across from me?
Bonus prize, if you can do that, can you enqueue the call to the other person, essentially creating a multi-line phone for people?
Thanks!
Twilio evangelist here.
Sure, you can absolutely make a Client to Client call. The Twilio Client for JavaScript Quickstart has a walk-through showing you how to do this:
https://www.twilio.com/docs/quickstart/php/client/browser-to-browser-calls
You can also use the Queue verb in a client-to-client call.
Lets say you want to put Call A (lets call them 'customer') into a queue. To do that you would create a new TwiML App and point it at a URL that returns the <Enqueue> verb. When you initiate that client you would use that TwiML Apps SID to generate the Capability token.
Now for Call B (lets call them 'agent'). If you want to connect them to callers in your Queu, you would create another TwiML app whose URL returns TwiML with the <Dial> verb containing the <Queue> noun. This tells Twilio to connect the 'agent' with the first caller in the queue. As with the 'customer', when you initialize the 'agent', you would use the 'agent' specific TwiML App SID to generate the Capability token.
Hope that helps.
Devin

Resources