using twilio account how to create a dynamic conference call for voiceurl in php

805

I am trying to upload using client on twilio and trying buy a twilio number.

Also, I need to get a dynamic voice URL in order to record a conference call dynamically.

<?php


require_once 'vendor/autoload.php'; // Loads the library
use Twilio\Rest\Client;

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "*********************";
$token = "*******************";
$client = new Client($sid, $token);


$numbers = $client->availablePhoneNumbers('US')->local->read(
    array("areaCode" => "424")
);

$twilioNumber = $numbers[0]->phoneNumber;

$newNumber = $client->incomingPhoneNumbers->create(
            [
            "voiceUrl" => "host url",
            "voiceMethod" => "GET"
            ]
        );

if ($newNumber) {
            return $twilioNumber;
        } else {
            return 0;
        }

// In the voiceUrl parameter i am passing a conference call connect code hosted link but its not getting updated to twilio account dynamically.

45

Answer

Solution:

 You can use like     

 require 'Services/Twilio.php';

 $account_id = ACCOUNT_SID;
 $auth_token = AUTH_TOKEN;

 $number = $_REQUEST['id'];

 $client = new Services_Twilio($account_id, $auth_token);

 try{

 $number= $client->account->incoming_phone_numbers->create(array('PhoneNumber' =>'+'.$number));
$number_sid=$number->sid;
$number1 = $client->account->incoming_phone_numbers->get($number_sid);
$number1->update(array("VoiceUrl" => "http://11.11.1.111/test/twilio_call_response.php","SmsUrl"=>"http://11.11.1.111/test/incomingsms.php","VoiceFallbackUrl"=>"http://11.11.1.111/test/fall_backurl.php"));
$phone_number=str_replace('+','',$numbers);
$allocate='1';

}catch(Exception $e){

 echo $err = "Error purchasing number: {$e->getMessage()}";
}

echo $phone_number;

People are also looking for solutions to the problem: Triangle of asterisks in php

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.