TWIML for reverse click-to-dial browser plugin - twilio

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.

Related

twilio master account make outbound call with subaccount validated number

I need to make outgoing calls from browser and i set capability token with the master account.
Then i make a call request to twilio from browser and return a twiml from my server.
In the twiml, i set the callerId to a subaccount validated outgoing phone number.
When dial to another client, it works fine. But, if dial to a phone number it not work.
From the debugger i saw this error:
it said callerId must be provided for TwilioClient and SIP calls when using Dial.
I dont know why, I need a help.

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?

A SIP provider with PSTN number and extension range for DID

I have a Twilio account with USA PSTN number like +11234567890. In my company all users have an internal SIP 4-digit number like 2001, 2002 etc.
Is somewhere a USA SIP provider which allows anyone USA client to call my number +11234567890 with extension directly, like +11234567890XXXX, and pass this full number into my PBX via SIP trunk call? With that number I can bridge a caller and callee directly (Direct Inward Call, DID), bypassing voice menu.
A Twilio techsupport says that i must buy another PSTN number, and they don't allowing such extensions. So, buying a external number per every user looks silly.
Is somewhere a USA SIP provider which allows anyone USA client to call my number +11234567890 with extension directly, like +11234567890XXXX, and pass this full number into my PBX via SIP trunk call?
No. This is impossible -- phone numbers in the US (as well as Canada and some countries in the Caribbean) must confirm to the North American Numbering Plan, which mandates that phone numbers be nine digits long. The US telephone network does not permit longer numbers to be dialed, no more than an IPv4 network would permit a five-octet IP address to be used.
Some devices will allow extra digits to be entered, e.g. to allow novelty "phonewords" to be dialed, but the extra digits are discarded. They are not sent to the phone network.
As George mentions in the comment , that is not the most intuitive way of dialing for the end users. You could achieve something similar with your Twilio number by using inbound PSTN or SIP call to invoke your application which can ask for extension and respond using the <Sip> noun of the <Dial> verb, to establish a call with your SIP endpoint.
A possible flow to achieve what you require is mentioned below :
Create a rest endpoint that does the following
Asks caller to enter extension number by <Say>-ing a message
Uses TwiML to <Gather> extension number from caller
<Dial> this extension on your sip infrastructure
Point your Twilio Number to above endpoint.
3 . Dont forget to whitelist Twilio's SIP address and media ports in your infrastructure
Sample TwiML to dial to your sip infrastructure is mentioned below (if extension is can be dialed directly as endpoint , do a direct sip to the extension , else pass extension as a header to your pbx and have pbx dial the extension)
<Response>
<Dial>
<Sip>
sip:stan#example.com?extensionNumber=2001&customeheader=xyz
</Sip>
</Dial>
</Response>

Twillio iOS App, not making calls properly

I am experimenting with Twillio for iOS, and going through the quick start tutorial here
https://www.twilio.com/docs/quickstart/php/ios-client/passing-parameters
Now I setup a heroku account as per the tutorial and so far I am accomplishing everything up until the point where I press dial in the app and make a call to a cell phone that I entered, I get an automated message saying " Welcome to Twillio"
and then in like 3 seconds it hangs up. No Error messages are logged or anything.
Any help would be appreciated.
Twilio evangelist here.
Assuming you are using the TwiML sample from the previous step in Twilio Client for iOS the quickstart, it sounds like your application is behaving as expected.
When using Twilio Client, you need to tell Twilio what to do with the VoIP connection thats being from iOS into Twilio, which you do by setting up a web server that has a URL that returns a set of TwiML "verbs". In the Quickstart, the TwiML we show includes the <Say> verb, which tells Twilio to take text and turn it into the robot voice that you're hearing.
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say>Welcome to Twilio</Say>
</Response>
Once Twilio finishes executing all of the TwiML verbs you give it, it disconnects the call.
If you want a different experience from whats shown in the Quickstart you can just change the TwiML your server returns. For example, if you want to have Twilio drop that Client call into a conference you could change the TwiML to:
<Response>
<Dial>
<Conference>Party Time</Conference>
</Dial>
</Response>
If you want Twilio to dial a PSTN number (like making a call to a cell phone), you would use the <Dial> verb with the <Number> noun:
<Response>
<Dial>
<Number>+15555555555</Number>
</Dial>
</Response>
Hope that helps.

Dialling Offline Twilio Client

I need to make calls to some Twilio clients that will received the call through the browser. The problem is, these clients don't necessarily have their browser open.
I know normally, a user would have to open up the browser and through the twilio util capability and twilio device to turn their browser into a device. And THEN they can receive incoming call.
Is there way to dial clients, when they haven't initialize their twilio client yet?
Twilio evangelist here.
If you try to dial a client who is not online Twilio will view that as a no-answer. You can get a notification of this by providing a URL for the <Dial> verbs action parameter.
When the call ends Twilio will make a request to this URL with a parameter named DialCallStatus which you can use to determine what happened when Twilio tried to dial the Client.
Hope that helps.

Resources