11

I want to create a help desk web page in which an agent can click a link to initiate an outbound call to a target number. I understand how to use the Web Client to make that happen, but for an agent who doesn't have bandwidth to support VoIP, I'd like Twilio to call the agent's phone number then dial the target number.

The experience would be much like using Google Voice with Google Chat/Hangout client -- Google Voice calls your number/client, then initiates a call to the target.

Also, if both agent and target phone numbers are domestic landlines, would this scenario incur 2X the per minute landline fees?

I'm not looking for code necessarily, but rather an answer based on Twilio APIs and Twiml concepts.

user3079993
  • 153
  • 1
  • 9

3 Answers3

15

Twilio evangelist here.

Sounds like you are looking to create "Click to Call". Here is some code from our docs that shows how to do this:

https://www.twilio.com/docs/howto/click-to-call

The basics are:

Use the REST API to initiate an outbound call. When that call is answered Twilio is going to make an HTTP request to some URL that you told about in your initial REST request. That URL's job is to return TwiML that contains the <Dial> verb which tells Twilio to dial the second phone number and bridge the two call legs together.

For domestic US calls, the total cost is going to be 4 cents / minute. 2 cents per each leg, since each leg is considered outbound. See Example 4 on this page:

https://www.twilio.com/help/faq/voice/how-much-am-i-charged-for-call-forwarding

Hope that helps.

Devin Rader
  • 10,260
  • 1
  • 20
  • 32
5

Simple/Direct Twilio Calls Agent->Call

original url: https://www.twilio.com/docs/quickstart/php/rest/call-request#call-end-callback

First file loaded from browser:

use Twilio\Rest\Client;

// Step 2: Set our AccountSid and AuthToken from https://twilio.com/console
$AccountSid = "SID";
$AuthToken = "AuthTok";

// Step 3: Instantiate a new Twilio Rest Client
$client = new Client($AccountSid, $AuthToken);

try {
    // Initiate a new outbound call
    $call = $client->account->calls->create(

        "+12125551111",// connect this number(Agent)

        // that you've purchased or verified with Twilio.
        "+12135554646",// caller id for call

        // Set the URL Twilio will request when the call is answered.
        array("url" => "http://example.com/call_them.php")

    );
    echo "Started call: " . $call->sid;
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}

call_them.php:

<?php
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
//inside dial.. actual number you want to reach
?>
<Response>
<Dial>+18185556363</Dial>
</Response>
ZStoneDPM
  • 311
  • 3
  • 6
1

Thank you for the great answer, @user3229526, it worked like a charm.

In order to unhardcode the number to call, just append the number you wish to call as a URL parameter in the Twilio Requst URL

array("url" => "http://example.com/call_them.php?number=1234567890")

And edit call_them.php to accept that parameter

<Response>
    <Dial>
        <?php echo '+1'. $_GET['number']; ?> // +1 for country code
    </Dial> 
</Response>