greenfieldtech-nirs / phpari Goto Github PK
View Code? Open in Web Editor NEWA Class Library enabling Asterisk ARI functionality for PHP
License: GNU Lesser General Public License v2.1
A Class Library enabling Asterisk ARI functionality for PHP
License: GNU Lesser General Public License v2.1
Hello
Attempting a basic setup, attempting to connect to asterisk and invoke the channel list example, this seems to fail before it even gets to connect step
{
"require": {
"php": ">=5.3.9",
"educoder/pest": "1.0.0",
"devristo/phpws": "dev-master",
"greenfieldtech-nirs/phpari": "dev-master"
}
}
[general]
debug=1
logfile=console
[asterisk_ari]
username=hey
password=redacted
host=redacted
port=8088
endpoint=/ari
transport=ws
#!/usr/bin/php5
<?php
require_once("vendor/autoload.php");
echo "Starting ARI Connection\n";
$ariConnector = new phpari();
echo "Active Channels: " . json_encode($ariConnector->channels()->channel_list()) . "\n";
echo "Ending ARI Connection\n";
?>
user@host:~/phpari$ ./connectivity_test.php
Starting ARI Connection
PHP Notice: Undefined index: protocol in /home/user/phpari/vendor/greenfieldtech-nirs/phpari/phpari.php on line 100
2017-04-28T10:04:20-05:00 DEBUG (7): Initializing WebSocket Information
2017-04-28T10:04:20-05:00 DEBUG (7): Initializing Stasis Event Emitter
PHP Notice: Undefined property: phpari::$ariEndpoint in /home/user/phpari/vendor/greenfieldtech-nirs/phpari/src/interfaces/channels.php on line 35
Exception raised: Missing PestObject or empty string
File: /home/user/phpari/vendor/greenfieldtech-nirs/phpari/src/interfaces/channels.php
Line: 36user@host:~/phpari$
Hi,
examples/ChannelOriginate.php line 39 reads
"callerid" => "111",
It is case sensitive, so the "i" in callerID should be capitalized:
"callerId" => "111",
Also, the example shows all but one of the possible fields. Maybe you should add the originator field with a blank value like the rest of the unused fields for completeness?
Thanks,
Mark Ingles
i need to work with different asterisk servers, but in default they have prefix /asterisk
so this line doesnt work
$this->stasisClient = new \Devristo\Phpws\Client\WebSocket($ariTransport . "://" . $ariServer . ":" . $ariPort . "/ari/events?api_key=" . $ariUsername . ":" . $ariPassword . "&app=" . $stasisApplication, $this->stasisLoop, $this->stasisLogger);
this part of code
"/ari/
can we also set the prefix by ini?
Hello there,
we've been doing some tests using the library and everything was ok but the answering function.
If the call it's answered in the dialplan is ok, but if we try to answer the call inside the stasis it fails (it never answers the call).
We've tested it with Centos/Ubuntu systems and Asterisk13/Asterisk14.
The php version always 5.6.
To check the ARI itself we've tested ringing a call, get the channel id and then send a http post to answer the channel, like
curl -v -u user:pass -X POST "http://localhost:8088/ari/channels/1487608619.14/answer"
and that works, but this (inside the stasis) doesn't:
$this->phpariObject->channels()->channel_answer($this->stasisChannelID);
So looks like the Asterisk ARI part it's ok. We're able to manage the channels by ARI.
For the test we've used the example BasicStasisApplication.php without changing anything.
¿That simple test works for you? ¿Does the stasis answer the call?
Thanks for your help ;)
Hi @greenfieldtech-nirs, the changes merged in PR #49 seems to break functionality. Some examples of errors introduced with the changes are below:
PHP Notice: Undefined property: asterisk::$pestObject in /var/ari/vendor/greenfieldtech-nirs/phpari/src/interfaces/asterisk.php on line 113
PHP Fatal error: Call to a member function get() on a non-object in /var/ari/vendor/greenfieldtech-nirs/phpari/src/interfaces/asterisk.php on line 113
PHP Notice: Undefined index: protocol in /var/ari/vendor/greenfieldtech-nirs/phpari/phpari.php on line 100
PHP Notice: Undefined property: asterisk::$pestObject in /var/ari/vendor/greenfieldtech-nirs/phpari/src/interfaces/asterisk.php on line 113
PHP Fatal error: Call to a member function get() on a non-object in /var/ari/vendor/greenfieldtech-nirs/phpari/src/interfaces/asterisk.php on line 113
PHP Notice: Undefined index: protocol in /var/ari/vendor/greenfieldtech-nirs/phpari/phpari.php on line 100
PHP Notice: Undefined property: phpari::$ariEndpoint in /var/ari/lib/StasisAppCore.php on line 56
PHP Notice: Undefined property: asterisk::$pestObject in /var/ari/vendor/greenfieldtech-nirs/phpari/src/interfaces/asterisk.php on line 113
PHP Fatal error: Call to a member function get() on a non-object in /var/ari/vendor/greenfieldtech-nirs/phpari/src/interfaces/asterisk.php on line 113
So at first glance I am guessing that the React guzzle refactor is incomplete possibly? I would have expected changes in all of the interface files instead of just applications.php. Since this is a fairly significant change can it be done in a different branch or version so that we can set the old version in our composer.json until the refactor is stable/complete?
Hi there
I have an ARI application to which I attempted to add a new function using channel_continue
The channel that I am attempting to continue has been answered and had ringing started
When I continue the channel I see dialplan execution continuing in asterisk but I get no audio on the channel. The channel is able to pass audio when, instead of continuing, I start playback on the channel. This is whether or not I specify context,extension,priority, both methods of invocation have the same behavior
Do I need to add the channel to a bridge first or something? It seems like I'm missing something obvious.
Please let me know if you need additional data to help track this down, I will provide whatever is necessary, it will take some time to create a sanitized test case, but I can do that if it's necessary
Hi,
in release-3/src/interfaces/bridges.php line 280, inside the function delchannel, this line:
$result = $this->pestObject->delete($uri, $delObj);
should be
$result = $this->pestObject->post($uri, $delObj);
The HTTP method should be post, not delete. Or else ARI will return "Invalid method"
This error is in the prior versions too.
Thanks - Mark Ingles
Line 517 of interfaces/channels.php should read
$result = $this->pestObject->post("/channels/" . $channel_id . "/moh", $postMoh);
($channel_id was $mohClass)
There is a prob on line 56 on phpari_config.php
It is trying to load $configFile but it is not declared. Replace that with $config.
Please correct that .
Socket error when i stoping aplication with $this->stasisLoop->stop();
[2019-04-05 04:52:19] WARNING[7409]: res_http_websocket.c:505 ws_safe_read: Web socket closed
[2019-04-05 04:52:19] WARNING[7409]: ari/ari_websockets.c:128 ast_ari_websocket_session_read:
I've been pondering over this. Is it possible to connect 2 channels from 2 bridges?
Much like a callcenter would do. If A calls you (B) and you put A on hold while you call C and then you'll want to connect A to C and leave the conversation.
When trying to call recordings()->live('stop', $recording)
, you'll receive the error:
Missing argument 2 for PestJSON::post(), called in vendor\/greenfieldtech-nirs\/phpari\/src\/interfaces\/recordings.php on line 180 and defined
I fixed it locally by adding []
as a second parameter on line 180. Might also happen with other post() methods that don't require data.
Hi,
In applications.php, public function application_details(), line 81, it says:
$uri = "/applications";
I think it needs to say
$uri = "/applications/" . $applicationName;
to get the details of the specific application
Refererence: https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Applications+REST+API#Asterisk12ApplicationsRESTAPI-get
Sorry for not knowing the github syntax to make it easier for you.
Mark Ingles
I did speak to @greenfieldtech-nirs in the past about it and I haven't come back to him which I do apologize for as we were in the middle of rolling out a 1500 seater over multiple countries.
Now that that is over I would like to officially contribute.
Now the problem we where facing is we wrote a application that had a queue split across 12 asterisk servers. Now the amount of calls we handle the blocking aspect of curl was causing a issues. And at least in the project I had to change some calls to async requests.
The reason why I want to discuss is making phpari non blocking in line with phpreact and converting the calls to async is a large change to how the lib is being used. For example
// Current Originate
$response = $channels->channel_originate(
'SIP/7001',
NULL,
array(
"extension" => "7001",
"context" => 'from-phone',
"priority" => 1,
"app" => "",
"appArgs" => "",
"callerid" => "111",
"timeout" => -1,
"channelId" => '324234',
"otherChannelId" => ""
),
array("var1" => "cool")
);
// Will become callback based
$channels->channel_originate(
'SIP/7001',
NULL,
array(
"extension" => "7001",
"context" => 'from-phone',
"priority" => 1,
"app" => "",
"appArgs" => "",
"callerid" => "111",
"timeout" => -1,
"channelId" => '324234',
"otherChannelId" => ""
),
array("var1" => "cool"),
function($response) {
//Do Something with the response
}
);
// Or Promise Based
$channels->channel_originate(
'SIP/7001',
NULL,
array(
"extension" => "7001",
"context" => 'from-phone',
"priority" => 1,
"app" => "",
"appArgs" => "",
"callerid" => "111",
"timeout" => -1,
"channelId" => '324234',
"otherChannelId" => ""
),
array("var1" => "cool")
)->then(function($response) {
//Do Something with response
}, function($error) {
//Do Something with error
});
So I don't know seeing it is as large as of usage that it should be done on phpari as a next major release or if it should be done like they do with Predis/Predis and create a new Project for Predis/PredisAsync as that gives people the option of both.
I got the StatisApp up and running and looking at the code it should be displaying events as they are received, but I never see any.
What am I missing to be able to receive the events?
$this->stasisClient->on("message", function ($message) {
$event = json_decode($message->getData());
$this->stasisLogger->notice('Received event: ' . $event->type);
$this->stasisEvents->emit($event->type, array($event));
});
I get a connection refused when I try to connect, I am a little confused as to what user-id/password to put in phpari.ini?
[asterisk_ari]
username=ariuser
password=xxxx
where is this user-id/password defined? I tried using the one in ari.conf but it did not work:
[ariuser]
type=user
read_only=no
password=xxx
Thank you for your help
Michel.
Having an error with php 7.1 - I've tried updating the guzzle but no luck.
PHP Fatal error: Cannot use lexical variable $eventName as a parameter name in /home/asd/vendor/guzzlehttp/guzzle/src/Event/Emitter.php on line 49
If the underlying pest connection fails due to connection or authentication problems, it would be (in my opinion) more useful to have a descriptive exception specifying the nature of the problem rather than just receiving a false return value.
phpari/src/interfaces/recordings.php
in function live, line 199, the "unmute" case
$result = $this->pestObject->post($uri);
should be
$result = $this->pestObject->delete($uri);
Thanks,
Mark Ingles
I noticed this when I was using bridge_addchannel. ARI doesn't require role but PHPARI throws an exception if I do not provide one.
I started looking through the interfaces and it seems that most of them are requiring every parameter.
I forked and make a quick change to bridge_addchannel for example.
Is this purposeful or are you open to changing the interfaces to match ARI requirements?
Hello.
I started using asterisk and phpari and enjoying too much. i have an issue that i am browsing from past one week if someone can please help.
1: I want to call one of our employee number using phpari.
2: Once the person receive call will be asked to press 1 to accept and 2 to hangup.
3: If employee press 1 will give a call to the client and will connect both.
I DON'T KNOW HOW TO GET THE READ VALUE AFTER ORIGINATING CALL AND THE REST OF STUFF. also if someone guid eme to use phpari or phpagi for my this issue.
Hi everyone, i wrote to you because i have a problem about connection in asterisk .... whe use code asterisk console throws this error
ERROR[3075]: res_http_websocket.c:513 ws_safe_read: Error reading from web socket: Connection reset by peer
[2018-11-22 19:37:28] WARNING[3075]: ari/ari_websockets.c:128 ast_ari_websocket_session_read: WebSocket read error: Connection reset by peer
== WebSocket connection from '192.168.0.20:49921' forcefully closed due to fatal write error
can you help me please?
I am needing to pass options (like TtXx, etc) to originate when dialing a channel. Can't quite figure out how to do that.
I'm asking as php-react has made some leaps, and there are a few small things I want to update and fix.
Hi,
I am trying to make a Click2call for my Asterisk PBX, at the past I used AMI to make this, but I am trying to realize the same using ARI.
To begin learning how to use the ARI PHP API, I am trying to use StasisAppDial.php, but it seems that it does not executing the StasisAppEventHandler function that is who place the call.
# php StasisAppDial.php 'SIP/101' '30'
2018-09-11T03:46:12-07:00 INFO (6): Starting Stasis Program... Waiting for handshake...
2018-09-11T03:46:12-07:00 INFO (6): Initializing Handlers... Waiting for handshake...
2018-09-11T03:46:12-07:00 INFO (6): Connecting... Waiting for handshake...
2018-09-11T03:46:12-07:00 NOTICE (5): Request received!
2018-09-11T03:46:12-07:00 NOTICE (5): Handshake received!
I do not know if this is the right place to place my query. Can you tell me the place when I can resolve my question?. Thanks in advance.
Best Regards
Before I start diving into this project: I'm looking for a way to export the phone book so I can use that data to fill the phone book of my telephones. Is that possible using this project or would you suggest I use another more simple method?
hi, exist a way in ARI for detect if a channel (outgoing) is a fax?
That is my goal:
I would to call a number, when I receive stasisStart event if it's a voice then I create a bridge, create a new channel (I call a my agent) and add the 2 channel in the bridge, so the 2 channels talks.
If it's a fax then I would store this info in my DB and hungup the channel, without create bridge and new channel.
exist a StasisFax Event?
How could I do?
thanks
Hi,
I'm trying to record a call (by recording a channel or a bridge).
I use channels()->channel_record("channelid","file.wav","wav",60,1)
and I get "false" as a result.
Can anyone help?
why you store all this variables
private $applications;
private $asterisk;
private $bridges;
private $channels;
private $devicestates;
private $endpoints;
private $events;
private $mailboxes;
private $recordings;
private $sounds;
private $playbacks;
if you always create them again?
https://github.com/greenfieldtech-nirs/phpari/blob/master/phpari.php#L142
you cant reach these variables outside of phpari class, because they are private, and when you try reach them you always create a new instance? so why? why you dont test if variable is empty or not and after that decide if you create new instance or not?
Hello Nir,
we've noticed that the maximum ringing time for a dial using phpari is 30 seconds. After that the call is disconnected.
We're passing the timeout from the dialplan to the stasis and the stasis send it to the dial app properly:
body:
{
"endpoint": "PJSIP/ricardo20",
"app": "stasis-dial",
"appArgs": "",
"timeout": "200"
}
But it doesn't matter which value we send it always hang up the ringing after 30 seconds.
If we use the Dial app in Asterisk Dialplan the timeout out is ok with the value we setup,but not if we use phpari.
Do you think we're missing smth or is this a bug?
Thanks Nir
SIP Packet Session Progress Events are not generating an ari event.
These are important events in the sequence of setting up a call.
A little guidance on where these events could be added to existing code would be great.
I added 183 into vendor/guzzlehttp/psr7/src/Response.php, but that doesn't seem to do it.
Hi @greenfieldtech-nirs I am using the basic StasisAppDial.php example, but It doesn't work when I send "CALLERID(name)" => "test"
Could there be a bug in the library?
$response = $this->phpariObject->channels()->channel_originate(
$args[0],
NULL,
array(
"app" => "stasis-dial",
"appArgs" => '',
"timeout" => $args[1],
"callerId" => '888888888'
),
array(
"CALLERID(name)" => "test"
)
);
Hi, I’m trying you library, it’s good, but your example “ChannelOriginate.php” don’t work fine.
I obtain this:
Notice: Array to string conversion in /var/www/workspace_softeoscar/asterisk/phpari/src/interfaces/channels.php on line 150
Error: { “message”: “Application or extension must be specified” } Trace: #0 /var/www/workspace_softeoscar/asterisk/phpari/vendor/educoder/pest/Pest.php(242): Pest->checkLastResponseForError() #1 /var/www/workspace_softeoscar/asterisk/phpari/vendor/educoder/pest/Pest.php(364): Pest->doRequest(Resource id #61) #2 /var/www/workspace_softeoscar/asterisk/phpari/vendor/educoder/pest/PestJSON.php(47): Pest->post(‘/channels/Array’, ‘{“endpoint”:”SI…’, Array) #3 /var/www/workspace_softeoscar/asterisk/phpari/src/interfaces/channels.php(152): PestJSON->post(‘/channels/Array’, Array) #4 /var/www/workspace_softeoscar/asterisk/phpari/src/interfaces/channels.php(178): channels->originate(‘SIP/201′, Array, Array, NULL) #5 /var/www/workspace_softeoscar/asterisk/phpari/examples/ChannelOriginate.php(46): channels->channel_originate(‘SIP/201′, Array, Array) #6 {main}
I print $uri in in line 150, it’s:
/channels/Array
thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.