0

I want to make live conversation between number 1 and number 2. My code is given below -

<?php
require 'twilio-php-master/Twilio/autoload.php';
use Twilio\Rest\Client;
$sid = "******************";
$token = "***************"; 

$client = new Client($sid, $token);


  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.
            "Number 2",

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

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

?>

My twiML is given below -

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

When I hit this REST api in browser I am getting call in my mobile but phone is disconnected after trial account message. Please help me.

Farman Ali Khan
  • 822
  • 7
  • 24
  • I don't think you need to do the call (Dial) again in your TwiML as it has already called that number. Instead you need to tell it what to do, e.g. play a greeting or record something. See https://www.twilio.com/docs/quickstart/php/rest/initiating-calls – Andy Oct 06 '17 at 19:56
  • without dial still unable to make live call. I am able to play audio but not live conversation – Farman Ali Khan Oct 06 '17 at 20:27
  • I want to make just live conversation between two person – Farman Ali Khan Oct 06 '17 at 20:28
  • hi, Farman Ali Khan, were you able to achieve this ? if yes, please how did you do it. thanks – Yusuf Jun 22 '23 at 11:03

1 Answers1

0

The url which you have specified here

// Step 6: Set the URL Twilio will request when the call is answered.

needs to return some TwiML to tell Twilio what to do next. Your call is disconnecting because Twilio has run out of TwiML to execute.

Set your request URL to return TwiML which makes a call to a different number, then running your first script will call your phone, and once you pick up it will call the their phone and connect the two calls.

miknik
  • 5,748
  • 1
  • 10
  • 26
  • That means I need three number to make live conversation . Suppose I want to make call between number1 and number2, then I have to connect first number1 with number 3.Once number1 is connected I need to dial number 2 from number1 in twiML. Am I right? – Farman Ali Khan Oct 07 '17 at 04:22
  • When you make the initial call using the REST API, the `from` number needs to be a Twilio number or number verified in your account. You can make that call to a number owned by a person but when the call connects you only have a connection between Twilio and that one person. If you want to dial another person you will need to return TwiML to dial to the other person you want to connect to. – philnash Oct 09 '17 at 10:21