Call Recording Twilio Proxy API PHP - php

i have been trying to record call using twilio proxy api. But i am having a weird issue i got a couple of twilio number but on one number call is being recorded perfectly but on others it just doesnt record call here is my code that was placed in the callback url
$twilio = new Client($sid, $token);
$inbound_id=$_REQUEST['inboundParticipantSid'];
$recording = $twilio->calls($_REQUEST['inboundResourceSid'])->recordings->create(['recordingStatusCallback'=>
"https://tvmount.services/wbadmin2/record.php?inbound_id=".$inbound_id]);
i tried debugging it and the problem is that on my other twilio numbers it just dont redirect to the record.php .

Related

Twilio sending message Using twilio library

Sending twilio message from my api returns this error
Twilio sending message The requested resource /2010-04-01/Accounts//Messages.json was not found
this is how I send a message. anyone incountered a problem?
$this->client = new \Services_Twilio($sid, $token);
return $this->client->account->messages->sendMessage($from ,$to, $message);
this is the documentation I followed
https://www.twilio.com/docs/api/rest/sending-sms
How do I create Messages.json
I used this https://github.com/twilio/twilio-php on laravel 4.2
Another Twilio developer evangelist here. Think I might be able to help.
The error message you got was this:
The requested resource /2010-04-01/Accounts//Messages.json was not found
The key point is the URL, particularly the double slash in the middle. That is where your Account Sid should be, thus leading to the 404 error.
In this case, I would double check how you are setting $sid. Make sure it is assigned before you try to create the Twilio client object.
Hi Twilio developer evangelist here.
Sorry to hear you're having trouble with your code.
You seem to not have posted your complete code, so I don't see where you actually require the library.
I have however written an example which worked for me.
// Your Account Sid and Auth Token from twilio.com/user/account
$sid = 'AC';
$token = '01';
$client = new \Services_Twilio($sid, $token);
$message = $client->account->messages->sendMessage(
'+44', // From a valid Twilio number
'+44', // Text this number
"Hello monkey!"
);
I have removed some sensitive data on the code, but if you replace that with your token and numbers, you should be able to send a text message correctly.
Also, just in case you have the contents of the 'Services' folder elsewhere, make sure your paths are correct.
You have entered messages when it should be sms_messages.
CHANGE
$this->client->account->messages->sendMessage($from ,$to, $message);
INTO
$this->client->account->sms_messages->create($from ,$to, $message);
Also make sure that you are running this code inside a class otherwise you need to remove the $this-> from your code and use a local varible.

How to put Twilio call on hold

I am trying to implement following on Twilio, but not sure why I am not able to get it done correctly. I have initiated a call using standard Twilio procedures from twilio.device.connect. After a call is initiated, I am updating the call to new url in order to put it on hold.
$client = new Services_Twilio($accountSid, $authToken);
$call = $client->account->calls->get($call_sid);
$call->update(
array(
"Url" => "http://localhost/voice.xml",
"Method" => "POST",
)
);
Now here instead of putting end user on hold it just disconnects the call, and play music on my side. Why it is happening?
Twilio evangelist here.
I'd suggest checking to see if Twilio is logging any errors:
https://www.twilio.com/user/account/monitor/alerts
If you are trying to redirect Twilio to "http://localhost", thats not going to work because Twilio obviously does not know how to reach the localhost running on your own machine.
If you want to expose a web server running on your own local machine to the internet via a public URL check out an awesome tool called ngrok.
the reason is that after the <Play> tag in your
"http://localhost/voice.xml" file.. there is no further TwiML that gets executed.
The solution is to redirect the call back to its original state.

Twilio Multiple Number Dialing, What is Equivalent in REST API of Given TWIML

As we know it is very easy to dial multiple numbers at once via TwiML. Note That, Once one of the dialed numbers picks up. Rest of the numbers are disconnected automatically.
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial>
<Number>415-123-4567</Number>
<Number>415-321-7654</Number>
<Number>415-456-7890</Number>
</Dial>
</Response>
But What would be the Equivalent of this REST API? Considering I am using PHP helper libraries. I can make single number call like this.
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library
// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "{{ sid }}";
$token = "{{ auth_token }}";
$client = new Services_Twilio($sid, $token);
$call = $client->account->calls->create("+14158675309", "+14155551212", "http://demo.twilio.com/docs/voice.xml", array());
My guess is I can loop through numbers to create single calls. But how do disconnect other numbers when one call is picked up?
Twilio evangelist here.
I think what you'd need to do in order to create a simul-dial app using the REST API is create a loop that initiates all of the outbound calls you want to make. Each time you start a new call save the CallSid for that call in an some kind of datastore like a database.
Which ever call answers first it is going to make an HTTP request to the URL you specified when you created the call. In that PHP file you can loop over that list of CallSids you saved earlier and use the REST API to set all but that first calls Status property to "completed". Doing this tells Twilio to hang up on all of the other calls.
Hope that helps.

Pass dynamic TwiML when making calls

How can I pass dynamic TwiML to the Twilio API when making calls?
$client = new Services_Twilio($sid, $token);
So instead of passing a URL to fetch the TwiML:
$call = $client->account->calls->create("+14158675309", "+14155551212", "http://demo.twilio.com/docs/voice.xml", array());
Could I dynamically generate the TwiML and pass it to the API?
$twiml = new Services_Twilio_Twiml();
$twiml->say( 'Hello Mark');
$call = $client->account->calls->create("+14158675309", "+14155551212", $twiml);
Twilio evangelist here.
Instead of specifying a static XML file in the create function, you can make this a PHP file and dynamically generate the response.
You still use create() to tell Twilio to initiate the phone call. When the call is answered, Twilio will request the URL you've specified to get the TwiML that tells it how to proceed with the call. So for example you change:
http://demo.twilio.com/docs/voice.xml
to
http://demo.twilio.com/docs/voice.php
And have the PHP generate the TwiML output:
$twiml = new Services_Twilio_Twiml();
$twiml->say( 'Hello Mark');
Here is the documentation for generating TwiML using the PHP helper library:
https://github.com/twilio/twilio-php#generating-twiml
Hope that helps.
Could I dynamically generate the TwiML and pass it to the API?
The answer is no, not without a URL. I realize this a delayed response but I have recently been searching for a way around this. The best method I have found of generating dynamic text for outgoing calls without a web server is here - bouncing it off of the twimlets url.

How to make browser-phone call with twilio

i am currently stacked with twilio client call where i have to call a user from browser. Lets see the scenario.
start snippet:
include 'twilio/Services/Twilio/Capability.php';
include 'twilio/Services/Twilio.php';
$accountSid = 'ACxxxxxxxxxxxxxxx';
$authToken = 'xxxxxxxxxxxxxxxxx';
$token = new Services_Twilio_Capability($accountSid, $authToken);
$token->allowClientOutgoing('APXXXXXXXXXXX');
$client = new Services_Twilio($accountSid, $authToken);
$call = $client->account->calls->create("twilio Number", "client number", "https://www.mysite.com/twilio/callback", array());
And my call back goes like this:
function callback(){
$xml = "<Response><Say>Placing your call now.</Say><Dial callerId='twilio verified number' timeout='40' record='true'></Dial></Response>";
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" . $xml;
exit();
}
I dont know what exactly the $from, $to parameters with in the calls->create() function takes. If we are initially initiating the call to $to then, it should work.
My requirement is to call a client to client number from my browser. Yes, i see the referencees here but stacked again.
Twilio evangelist here.
Looks like your current code is using the REST library to initiate the call. This send a message to Twilio to initiate a phone call from Twilio to some phone. All of that happens on the server, not in the browser.
In your case it sounds like you want to actually make a phone call right from the browser. To do that you need to use Twilio Client, which is a JavaScript framework that lets you create an audio connection from a browser to Twilio, and the connection is made using WebRTC (or Flash if needed). Its the job of the Twilio Client SDK to figure out how to create and manage the actual audio connection between your browser and Twilio.
http://www.twilio.com/client
https://www.twilio.com/docs/tutorials/walkthrough/browser-calls/php/laravel
This is different than initiating a call using the REST API. When you initiate an outbound call using the REST API, the API does not actually manage the audio connection. Your using the API simply to tell Twilio to initiate a phone call between Twilio and a phone (or to send a text message), or to ask Twilio for information (like getting list of send SMS messages). The management of the actual audio connection is handled by Twilios internal systems.
The first part of your PHP code is correct you need to create a Twilio Capability token. That token is used by our JavaScript library. This tutorial shows the JavaScript code that you can use to make a call from your browser to Twilio:
https://www.twilio.com/docs/tutorials/walkthrough/browser-calls/php/laravel
Once the browser connects to Twilio, Twilio will make a request to the URL you've set on your TwiML App (the string starting with "AP" that you specified when you created the capability token). You can return whatever TwiML you like from this URL, including using the <Dial> very to tell Twilio to bridge the Twilio Client connection into a <Conference>.
Hope that helps.
Devin
This will be helpful. If you look through the code, there is some api (i think callFromBrowser()) which does the trick.

Categories