How to put Twilio call on hold - php

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.

Related

Call Recording Twilio Proxy API 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 .

Why do I receive an error 500 when trying to access Paysafe Api server?

The Paysafe API was working perfectly fine in localhost, I was able to complete payment to Netbanx. I started to integrate the system on the website. I have a page for billing information, then a page for card payment where I use paysafe.js to create a token.
Then, I use PHP to get response from the server. This works in local. But online, this last part where I try to settle a payment, I get an error 500. I think it could be because the server is not using HTTPS. I want to know if it's possible that the error 500 is coming from the fact we don't have HTTPS or if it's something else?
P.S: It's complicated to access to the server because of bureaucracy, I don't want to make all the process if it's sure it's not that!
Thank you!
P.S.: I also tried using curl instead, and the response was bool(false).
require_once("config.php");
use Paysafe\Environment;
use Paysafe\PaysafeApiClient;
use Paysafe\CardPaymentService;
use Paysafe\CardPayments\Authorization;
$client = new PaysafeApiClient($paysafeApiKeyId, $paysafeApiKeySecret, Environment::TEST, $paysafeAccountNumber);
$info = new Authorization(array(
//PAYMENT ARRAY (Getting POST variable from previous page)
));
$response = $client->cardPaymentService()->authorize($info);
$statut = $response->status;
That Environment::TEST obviously does not match the production environment (or host-name).
Just enable PHP error reporting for your IP only, in order not to possibly leak any details.
Also check the console there (if any), if that host if even authorized to access the API.
I mean, HTTP500 is an error description just alike "it does not work".

Twilio call status always completed even if rejected

I have an application that does the following.
When the client calls a twilio number
my app will be notified, and list of numbers are sent back to be dialed by twilio depending on the agent's availability.
Then depending on the first call's status, if answered => success, otherwise try another agent's number.
First test:
$twiml = new Twiml();
$dial = $twiml->dial();
$dial->number('XXXXXXX'); // Agent A
$dial->number('XXXXXXX'); // Agent B
=> The problem with this version is that all agents are called simultaneously. Don't want that.
Checking call status:
$twiml = new Twiml();
$twiml->dial('XXXXXXXXX',
['action' => 'https://myapp.dev/xml/logger',
'method' => 'POST',
'statusCallbackEvent' =>'answered completed']);
// Log file
..
'CallStatus' => 'completed',
..
=> The call status is always completed even if the agent has rejected the call
Is there a way to implement my application need using twilio Voice SDK without using the complex Taskrouter API ?
Twilio developer evangelist here.
I think you need to check the DialCallStatus parameter which will be the status of the call leg you are making with the <Dial> rather than the status of the original call.
Let me know if that helps at all.

Setup OAuth2 in Lumen

I followed this article written to setup OAuth2 for my API that I'm writing in Lumen. I finished setting it up and I implemented the client so that I could test that it works. I haven't been able to get it to work. When I click the 'Login to API' button, it sends a POST to http://myserver.com/login and it never finishes. It hangs here and I get no exceptions or errors of any kind. Also, when it hangs like that I cannot just refresh the page. I have to serve it on another port, if that's a clue as to what's happening. I output a bunch of log messages and I've narrowed the trouble down to this:
$guzzleResponse = $client->post(sprintf('%s/oauth/access-token', $config->get('app.url')), [
'body' => $data
]);
I checked the parameters and they look good. $client is a GuzzleHttp Client. The post method inside looks like this:
public function post($url = null, array $options = [])
{
return $this->send($this->createRequest('POST', $url, $options));
}
I think I may have to enable cookies in Lumen. Where would I go to find that out? Does anyone have any other ideas?
To enable cookie, you can do this in .env file -
SESSION_DRIVER=cookie
Then run composer update command.
Had you check your .env?.. please add AUTH_MODEL=App\Auth\User if that no there.
Sometimes Guzzle doesnot work with port eg localhost:8888. If you are runnnig your server on some port change it to default 80 and guzzle will work

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