简体   繁体   中英

Connect two persons through Twilio client

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM