I am new to FreeSWITCH/Skypopen. I need to get the the status of a buddy using the skypopen module and PHP.
I am using the following PHP script to get the status.
<?php
$output = array();
$returnVar = "";
$result = exec('fs_cli -x "skypopen interface1 GET USER skypeusername ONLINESTATUS"', $returnVar, $output);
var_dump($result, $returnVar, $output);
?>
After executing the PHP file, I get the following response:
string(0) ""
array(2) {
[0]=>
string(68) "Using interface: globals.SKYPOPEN_INTERFACES[18].name=|||interface1|||"
[1]=>
string(0) ""
}
int(0)
It only returns Using interface: globals.SKYPOPEN_INTERFACES[18].name=|||interface1|||, not the online status of "skypeusername".
But if I execute the command skypopen interface1 GET USER skypeusername ONLINESTATUS in FreeSWITCH CLI, it returns the following:
freeswitch#internal> skypopen interface1 GET USER skypeusername ONLINESTATUS
Using interface: globals.SKYPOPEN_INTERFACES[18].name=|||interface1|||
2013-06-04 04:06:35.778928 [DEBUG] skypopen_protocol.c:1771 [1a3a11f|3d6ed64] [DEBUG_SKYPE 1771 ][interface1 ][IDLE,IDLE] SENDING: |||GET USER skypeusername ONLINESTATUS||||
2013-06-04 04:06:35.778928 [DEBUG] skypopen_protocol.c:209 [1a3a11f|3d6ed64] [DEBUG_SKYPE 209 ][interface1 ][IDLE,IDLE] READING: |||USER skypeusername ONLINESTATUS ONLINE|||
After doing some search in Google, I found that the skypopen module sends the result to its log file as DEBUG log.
Is there a way to get that response as result to the PHP script?
Skypopen module has a problem. So it does not return response to socket or cli. It returns to log only. You need to modify code to send response to socket and you will get it on php end.
I don't have this module loaded, but judging by the source code of the skypopen_function in mod_skypopen.c, it seems that the skypopen API calls never really return anything except for the interfaces line that you mentioned.
On the other hand, it looks like the module fires a skypopen::incoming_raw event every time it receives data from the Skype API, so you could try opening an ESL connection from PHP and listening for these.
You should first try it directly on fs_cli:
freeswitch#internal> /event plain CUSTOM skypopen::incoming_raw
Then:
freeswitch#internal> skypopen interface1 GET USER skypeusername ONLINESTATUS
Related
I've been using the Salesforce SOAP API for a number of years, but the original PHP client that Salesforce provided doesn't work with PHP8.1. I've attempted to incorporate the necessary elements of the client into my code since I'm only performing one simple action (creating a QuoteLineItem). I've been able to get the client to properly connect and login, but my create command doesn't get any response (not even a NULL value).
I've compared everything being sent from the PHP7.4 solution and my 8.1 implementation, and they appear almost identical.
Create statement:
$result = $this->sforcePartnerClient->create($arg);
$arg value:
object(stdClass)#1331 (2) { ["__CLASS__"]=> string(8) "stdClass" ["sObjects"]=> array(1) { [0]=> string(26) "\Module\Controller\SObject" } }
Why am I not getting even an error response?
I am using PerfectSwift for a RESTful API to bridge our TeamCity build server and HipChat; however I am stuck at a point whereby I am unable to post to the HipChat backend using Perfect's cURL wrapper.
The command I am trying to mimic is:
curl -d '{"color":"green","message":"My first notification (yey)","notify":false,"message_format":"text"}' -H 'Content-Type: application/json' https://<MY DOMAIN>/v2/room/509/notification?auth_token=<MY AUTH TOKEN>
I currently have the following code in my Perfect program:
let curl = CURL(url: "https://<MY DOMAIN>/v2/room/509/notification?auth_token=<MY AUTH TOKEN>")
curl.setOption(CURLOPT_POST, int: 1)
curl.setOption(CURLOPT_POSTFIELDS, s: "{\"color\":\"green\",\"message\":\"My first notification (yey)\",\"notify\":false,\"message_format\":\"text\"}")
curl.setOption(CURLOPT_HTTPHEADER, s: "[Content-Type:application/json]")
curl.perform { (code, header, body) in
}
However, the message never gets to HipChat, or, if it does, it's not in a readable format.
When I paste the first command into terminal, everything works as expected.
From my understanding, this uses a similar system to PHP, and I am therefore including the PHP tag as I feel PHP developers may be able to offer advice if I am using the wrong CURLOPTs etc...
Thanks in advance.
I am receiving the following error when using the putObject() function of the aws-sdk for php:
PHP Fatal error: Uncaught Aws\S3\Exception\MalformedXMLException: AWS Error Code: MalformedXML,
Status Code: 400, AWS Request ID: 7E36EB414B2A9436, AWS Error Type: client,
AWS Error Message: The XML you provided was not well-formed or did not validate against our published schema,
User-Agent: aws-sdk-php2/2.5.4 Guzzle/3.8.1 curl/7.26.0 PHP/5.5.19-1~dotdeb.1
thrown in /sites/sitename/vendor/aws/aws-sdk-php/src/Aws/Common/Exception/NamespaceExceptionFactory.php on line 91
Even though I am receiving the error, the process continues to run successfully and the files are moved to s3. I know this more than likely has something to do with the parameters that I am including in the function but I'm not sure what else needs to be there as the aws api for php only shows the 'bucket' and 'key' parameters as being required. My configuration is as follows:
$config = array();
$config['Bucket'] = IMAGE_BUCKET;
$config['Key'] = $imageName;
$config['SourceFile'] = $sourceImageDir;
$config['ACL'] = 'public-read';
$config['ContentLength'] = filesize($sourceImageDir);
$response = $s3->putObject($config);
If I knew what format the service was requiring I'm sure I could grab the request that I'm sending after it's turned into an xml string and compare it with that, but I can't seem to find it. If it exists. I would assume there is such a thing?
Thanks to the comment from Michael I was able to track the issue down further. It turns out that the issue was actually coming from a call to deleteObjects(). These commands are being executed within a shell script on the cli and it turns out there was another call preceeding the last call to putObject(). It was trying to send empty arrays to the s3 service...which would obviously return the given MalformedXML Status code.
I'm using Deezer APIs
$xml = simplexml_load_file('http://api.deezer.com/2.0//search/artist/?q=eminem&index=0&nb_items=1&output=xml');
var_dump($xml);
$xml = simplexml_load_file('http://api.deezer.com/2.0/artist/393/top/&output=xml');
var_dump($xml);
The first call works in the same way both on my local machine (Mac PHP 5.3.15) and online on a dream-host server (PHP 5.3.13), the second call works on my local machine, reporting all 5 track objects, but not on-line, where I just get
object(SimpleXMLElement)#4 (2) {
["data"]=> object(SimpleXMLElement)#1 (0) { }
["total"]=> object(SimpleXMLElement)#3 (0) { }
}
It seems to me very weird, do you have any clue?
Thanks
Deezer use geolocation for Artist Request.
So, if your server is geolocated in US for example, the first request have the same result between local and online but de second one (http://api.deezer.com/2.0/artist/393/top/&output=xml) don't have the same result local/online.
Request with FR Ip :
<?xml version="1.0" encoding="utf-8"?><root><data><track><id><![CDATA[2114267]]></id><readable><![CDATA[1]]></readable><title><![CDATA[My Life]]></title><link><![CDATA[http://www.deezer.com/track/2114267]]></link><duration><![CDATA[321]]></duration><rank><![CDATA[674751]]></rank><preview><![CDATA[http://cdn-preview-2.deezer.com/stream/2ecb4b24f51cdbfdaea89630f1978529-0.mp3]]></preview><artist><id><![CDATA[393]]></id><name><![CDATA[The Game]]></name></artist><type><![CDATA[track]]></type></track><track><id><![CDATA[2307182]]></id><readable><![CDATA[1]]></readable><title><![CDATA[Hate It Or Love It]]></title><link><![CDATA[http://www.deezer.com/track/2307182]]></link><duration><![CDATA[207]]></duration><rank><![CDATA[654207]]></rank><preview><![CDATA[http://cdn-preview-3.deezer.com/stream/393350005d03712abc9adfbe2bcfe2d3-0.mp3]]></preview><artist><id><![CDATA[393]]></id><name><![CDATA[The Game]]></name></artist><type><![CDATA[track]]></type></track><track><id><![CDATA[2294433]]></id><readable><![CDATA[1]]></readable><title><![CDATA[How We Do]]></title><link><![CDATA[http://www.deezer.com/track/2294433]]></link><duration><![CDATA[235]]></duration><rank><![CDATA[610398]]></rank><preview><![CDATA[http://cdn-preview-c.deezer.com/stream/c3683a1fc1899c9d1b128b222d0e080f-1.mp3]]></preview><artist><id><![CDATA[393]]></id><name><![CDATA[The Game]]></name></artist><type><![CDATA[track]]></type></track><track><id><![CDATA[62751648]]></id><readable><![CDATA[1]]></readable><title><![CDATA[Ali Bomaye]]></title><link><![CDATA[http://www.deezer.com/track/62751648]]></link><duration><![CDATA[373]]></duration><rank><![CDATA[571988]]></rank><preview><![CDATA[http://cdn-preview-1.deezer.com/stream/1bb2606c722235eeecb2b1caa039f5c1-0.mp3]]></preview><artist><id><![CDATA[393]]></id><name><![CDATA[The Game]]></name></artist><type><![CDATA[track]]></type></track><track><id><![CDATA[61571949]]></id><readable><![CDATA[1]]></readable><title><![CDATA[Celebration]]></title><link><![CDATA[http://www.deezer.com/track/61571949]]></link><duration><![CDATA[290]]></duration><rank><![CDATA[559639]]></rank><preview><![CDATA[http://cdn-preview-f.deezer.com/stream/f1f535359bd60ce3ec77d59fcfda4ebd-1.mp3]]></preview><artist><id><![CDATA[393]]></id><name><![CDATA[The Game]]></name></artist><type><![CDATA[track]]></type></track></data><total><![CDATA[5]]></total></root>
The same request with US location :
<?xml version="1.0" encoding="utf-8"?><root><data></data><total><![CDATA[0]]></total></root>
To complete the answer. You can change Geolocation of your request (and have result from US Server) with access_token of user located in non-restricted country because when you request the deezer api with access_token, the api will use the user country and not the server country.
To get an access token from user :
http://developers.deezer.com/api/oauth
Don't forget on each request when you want to use the User geolocation to add this :
?access_token=XXXXX
EDIT :
I am part of the deezer team.
if you want to access xml by http protocol you will need to set allow_url_fopen ON in php.ini or
ini_set('allow_url_fopen ','ON');
in your code. or you can also do this if you are using php version <5
$temp = file_get_contents($url);
$XmlObj = simplexml_load_string($temp);
try:
$xml = simplexml_load_file('http://api.deezer.com/2.0/artist/393/top/?output=xml');
(i.e. change the '&' to '?')
This may or may not be the problem.
I am quite experienced in PHP but I've always had troubles with connection between servers like "post". I have a FLAC audio file that I need to post to Google's Speech Recognition API server. I don't know neither how to "listen" to its response. I would like a script like that, assuming that this kind of function exists :
<?php
$fileId = $_GET['fileId'];
$filepath = $fileId . ".flac";
recognize($filepath);
function recognize($pathToFile) {
//It's the following function that I'm looking for
$response = $pathToFile->post("http://www.google.com/speech-api/v1/.....&client=chromium");
//The $response would be the short JSON that Google feed back.
echo $response;
}
?>
EDIT
I've followed a tutorial to create a Shell Script that posts my FLAC file using Wget --post. I would like to post like this, but in PHP. Also, at the end of the command, there is this > answer.ret line, so that Google's answer would be written to this file. I was wondering if there was an alternate method to it in PHP.
Here's the command line :
wget -q -U "Mozilla/5.0" --post-file audio1.flac --header="Content-Type: audio/x-flac; rate=16000" -O - "http://www.google.com/speech-api/v1/recognize?lang=fr-fr&client=chromium" > trancription1.ret
EDIT 2
I figured out how to do it, with #hakre 's answer and baked up a little Gist for curious people. Here it is: https://gist.github.com/chlkbumper/4969389. Don't forget that the FLAC file must be a 16k bitrate FLAC
A POST request is just a standard HTTP request, just with the POST method specified. The rest of the HTTP Request and HTTP Response is pretty much the same.
You get the response of a request in form of a HTTP Response btw.. It is absolutely normaltiv defined in RFC 2616 - just relate to this document and it explains everything.
A function in PHP to send HTTP requests is file_get_contents, it returns the requests response. This is done via the HTTP stream wrapper that offers some options you need to send a POST request (default is GET). See HTTP context options.
Another popular PHP extension for sending HTTP requests are the Curl bindings.