Shweta Shinde
Shweta Shinde

Reputation: 11

How to make call through Twilio where two people will have live conversation?

I am trying to setup a call between two people and I am able to make a call but the person who pick up the call can listen pre-recorded voice mail. I want to have live conversation between these two people. I am not getting what should be the URL and how can I set it up.

My Sample PHP Code is -

require_once "application/helpers/Services/twilio-php-master/Twilio/autoload.php";
use Twilio\Rest\Client;

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

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

try {
    // Initiate a new outbound call
    $call = $client->account->calls->create(
        // Step 4: Change the 'To' number below to whatever number you'd like 
        // to call.
        "+91my_number",
        //$_POST['to'],

        // Step 5: Change the 'From' number below to be a valid Twilio number 
        // that you've purchased or verified with Twilio.
        "+1_twilioverified_number",

        // Step 6: Set the URL Twilio will request when the call is answered.
        array("url" => "http://demo.twilio.com/welcome/voice/")
    );
    echo "Started call: " . $call->sid;
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}

Is there anyone who can help me with this. Thank you in advance. Awaiting for reply.

Upvotes: 2

Views: 1019

Answers (1)

philnash
philnash

Reputation: 73029

Twilio developer evangelist here.

Currently your code is working fine, the thing you need to change is the URL that is listed as "Step 6" in the comments. Currently that URL points to some TwiML that reads out a message.

Instead of reading that message, you will need to provide a URL that returns some TwiML that <Dial>s another <Number>. You see, when the first part of the call connects, Twilio makes an HTTP POST request to that URL to get the instructions for what to do next.

This URL needs to be available online for Twilio to make the HTTP request to. You can either deploy this TwiML to a server of yours, use a TwiML Bin from the Twilio console or test it out using ngrok on your local development machine.

The TwiML you want should look a bit like this:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Dial>
    <Number>YOUR_NUMBER_HERE</Number>
  </Dial>
</Response>

Let me know if that helps at all.

Upvotes: 3

Related Questions