Connect two persons through Twilio client - twilio

I have a task with this description:
Implement the call button:
When call icon is clicked, first Twilio calls the phone number #1 (Admin)
Once admin picked up the phone, the number #2 (provider) is called.
Both connected.
At this moment I figured out how to call through browser to phone numbers (like Admin can call to the provider in browser).
But I can't find any information, how to connect people through Twilio accordingly the task.
Is there any way to implement this solution?

I do not completely understand if you want to click a phone number on the website or if you want to completely connect two phone numbers automatically.
Scenario 1: User calls a number of your Twilio account
You setup a callback URL for that number and setup a web endpoint which generates a response similar to the following (XML, TwiML):
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial callerId="${callerId}">${targetNumber}</Dial>
</Response>
In my example I use TypeScript/JavaScript templating to replace the callerId and targetNumber variables according to our systems logic.
Secenario 2: You want to connect two phone numbers via Twilio
In this scenario your software first makes sure that Twilio calls your Admin. This can be done via a REST call or Twilio's API. There are so many options depending on which programming language you use and if you want to use a library from Twilio. But the basic idea is documented here:
https://www.twilio.com/docs/voice/make-calls
And you would always end up making a REST call against /2010-04-01/Accounts/{AccountSid}/Calls to initiate the call.
In the request you again specify a URL where Twilio then can read back XML / TwiML to understand what it should do with the call one it is connected. And again here you can use almost the same TwiML as above:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say>Just a second you are going to be connected to your provider.</Say>
<Dial callerId="${callerId}">${targetNumber}</Dial>
</Response>
In the above example I also added a <Say> statement such that the administrator knows, that they are going to be connected and need to be patient until the call is finally connected.
Important Notes:
In our application scenarios we are attempting to hide the phone numbers of the connected parties. The purpose is that the caller which dials into our system should have the opportunity to remain completely anonymous if desired. So we specify with callerId which caller id we want to send with outbound phone call. Bear in mind that this must be a phone number which you do own (is a number rented via Twilio or is a phone number you registered with Twilio).

Related

Not able to do simple twilio call

I am not able to do simple 2 way audio call between 2 numbers using twilio.
I have attached my python (Django) code. when I run the code, call Get connected and but after accepting call it get's disconnected immediately. also, I am not able listen to anything on Laptop.
I have joined the code and twiml from twilio.
def call_m(request):
account_sid = os.environ['TWILIO_ACCOUNT_SID']
auth_token = os.environ['TWILIO_AUTH_TOKEN']
client = Client(account_sid, auth_token)
call = client.calls.create(
url='twiml_url',
to='+91985XXXXXXX',
from_='+132YYYYyYYY',
)
print("sid ",call.sid)
return render(request, 'calls/incall.html')
Here's my twiml.
<?xml version="1.0" encoding="UTF-8"?>
<Response>
</Response>
if i changed My twiml to this
<Response>
<Dial>+9198xxxxxxxx</Dial>
</Response>
then after accepting call from "To" number, It say's number is busy please call later.
I think you may have some misconceptions about how Twilio works when making calls.
When you generate a call with Twilio using the REST API that creates a call leg between the to number and Twilio (not between your laptop and the phone).
When that call is answered on the end of the to number, Twilio then makes an HTTP request to the url that you passed to the API. That URL should respond with TwiML to tell Twilio what to do with the call next.
Now, when your application responded with an empty TwiML response (<Response></Response>) that tells Twilio that there is nothing left to do in this call, so Twilio hangs up.
When your application responded with a <Dial>, like this:
<Response>
<Dial>+9198xxxxxxxx</Dial>
</Response>
my guess is that the number in the dial was the same number that you used in the to parameter to make the call. In this case, Twilio placed a call to your number in response to the REST API request and then placed another call to your number as directed by the TwiML <Dial> and that second call found that your number was busy because you are already on the line with Twilio.
If you used a different number in the <Dial> then Twilio would place a call to that number and when they answered the phone you would be connected to them.
If you want to connect two callers with their own phones, then using <Dial> like this is the way forward.
If you want to place a call from your laptop to another device, then you will need a bit more than just the REST API. In this instance you need to build an application using the Twilio Voice SDK which allows you to make calls from a web browser or iOS or Android application. If this is of interest to you then I recommend you check out the getting started guide for the JavaScript voice SDK.
The call needs TWiML to stay active, so that explains why it ends the call when you are returning an empty TwiML reponse. You must keep feeding it TwiML to keep the call up.
Specific to calling the number, there could be an issue dialing that number that Twilio support could investigate, if geographic permissions allow international calls to that destination.

voice call using twilio to my personal number

I am creating Swift app from which user can able to do call from Twilio number to personal number and for that i have implement code as below which i have referred from Twilio documentation here is the reference link
This is the code which i have used in my app
but now issue is that call is receiving to my personal number but i am to able to talk with another person who is receiving call and when call is received from personal number than i can able to here TWIML Bin content which i have added as.XML format as below
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say>This is the demo for Call And SMS</Say>
<Dial>+15005550006</Dial>
</Response>
so Outgoing call is from +15005550006 and receiving from my personal number then only i can here is that tag text i am not able to talk like we talk on normal voice call through network carrier so can anyone have idea how to connect call when i receive call from my personal number
if any one have idea that how to connect call from twillio number to personal number using Swift than kindly tell so i can able to solve this
This Code which you have used to make the call is only made for MAKING the call and NOT handling the actual communication after the call has been connected.
To be able to have a proper VoIP or conventional call using your twilio purchased phone number to your courier based phone number, you have to first make the swift app using the TwilioVoiceSDK, the code you have mentioned was only doing an HTTP request with parameters to invoke an outgoing call, but with twilioVoiceSDK you will not only invoke the code but will also be able to handle the actual communications after the call gets connected.
TwilioVoiceSDK look into this to get further explanation of the whole system.
Secondly you will also need to code in TwiML bin or twilio cloud to handle the outgoing calls to actual phone number as well, which you can also check from the above link.
Coming back to this code
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say>This is the demo for Call And SMS</Say>
<Dial>+15005550006</Dial>
</Response>
This will convert the text to speech and the dials the specified number, The caller will hear the text and the call will initiate and thats it.
This is the demo for Call And SMS

Transfer Enqueued Call to Conference Using Twilio

Imagine there is an incoming call currently enqueued via Twilio.
I want to transfer this call a new conference line.
Currently, my app "updates" the call with a redirect URL that responds with the following TwiML.
Unfortunately, it just hangs there, listening to music, and I never enter the conference.
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial>
<Conference endConferenceOnExit="true" startConferenceOnEnter="true" waitUrl="http://example.com/music">
{{CallSid}}
</Conference>
</Dial>
</Response>
Note that the {{CallSid}} is dynamically updated with the call identifier (aka Call SID). Also, I have not tried this with a second phone (because maybe it won't connect to the conference line until there is more than one person?)
Twilio developer evangelist here.
First up, your question in parentheses was indeed correct, a conference will not start with one person in, so will just play the hold music until someone else joins.
Secondly, once you added a second call you were still hearing hold music. However, for the <Conference> identifier, you said you were using the CallSid. That identifier is unique per call leg, so each of your calls would have different CallSids and thus would join different conference calls. To first ensure that this is the issue, I would test your code with a static identifier for the conference (<Conference>Test</Conference> for example). If you can get callers talking together like that, then you will need to find a way to identify a conference independent of the individual CallSids and use that as the identifier so that you can join the calls together.
Let me know if that helps at all.

Forwarding to multiple destinations with Twilio functions

I am new to twilio. I am trying to setup a phone number that rings multiple destinations.
I followed this blog and set up a twiML script like so.
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial>
<Number>+1-777-777-7777</Number>
<Sip>sip:1777xxxxxxxxxx#in.callcentric.com;region=us2</Sip>
<Sip>sip:1777xxxxxxxxxx#in.callcentric.com;region=us2</Sip>
</Dial>
</Response>
However as reported by other users in the comments this does not seem to work for scenarios where the destinations are a mix of sip and numbers. In my case only the phone number rings. The sip destinations don't receive the call at all.
Is there a way to make this work? either with bins or the new twilio functions?
Twilio developer evangelist here.
It is not possible to use multiple <Sip> nouns in a <Dial>. From the documentation:
Currently, only one <Sip> noun may be specified per <Dial>, and the INVITE message may be sent to only one SIP endpoint. Also, you cannot add any other nouns (eg <Number>, <Client>) in the same <Dial> as the SIP. If you want to use another noun, set up a callback on the <Dial> to use alternate methods.
You could, instead, add the incoming caller to a queue with <Enqueue> and dial each of the numbers/SIP addresses using the REST API. Then, when one connects, connect it to the call in the queue and disconnect the other calls. You'd need to keep a reference to the original call SID so that could connect directly to it and to each of the generated call SIDs so that you can terminate them with the REST API too.
Let me know if that helps at all.

Can Twilio detect if a call to a Google Voice number gets forwarded to voicemail or an actual person?

I have an app that creates outbound calls to set up simple conferences.
I am having difficulty dealing with dialing out to Google Voice numbers as I use IfMachine to be able to determine if the call goes to voicemail for one or more participants so that I can "fail" the conference call attempt.
Here's the issue that I am having...
Google Voice answers the call attempt and asks you to say your name before forwarding your call onto the configured endpoint for that user.
I can use IfMachine to detect this and I can automate this portion and get Google Voice to forward the call, but then I can no longer detect if the call ultimately goes to voicemail or if an actual person picks up on the other end.
any ideas?
Twilio Evangelist here,
I think given that there are 2 points you need machine detection, you may want to use a <Gather> as secondary call screening before connecting the person to a conference.
When you make the outbound call to a number, you're using IfMachine to find out if you get to Google Voice. So that's great. But because you're passed that hurdle, it won't be triggered again.
What you could do is to use call screening, to manually detect a human with some TwiML like this:
<Response>
<Gather numDigits="1" timeout="15" action="/some-conference-path">
<Say>Press any key to be connected to the Something Something Conference</Say>
</Gather>
</Response>
Then, if the call is answered by a human, they can press any key on their keypad and be redirect to the actual conference call, or if the Gather times out, you most likely got their voicemail.
You're basically combining automatic and manual machine detection as you need to do it twice at different points of the same call.
Hope this helps!

Resources