I am executing a php agi command using phpagi-asmanager.php class on my Asterisk 14 box and it is only showing a 1 line output instead of showing the full results.
require_once( '/var/lib/asterisk/agi-bin/phpagi-asmanager.php' );
$agi = new AGI_AsteriskManager();
$agi->connect();
$result = $agi->Command('queue show');
echo '<pre>';
print_r($result);
The above code only outputs:
Array
(
[Response] => Success
[Message] => Command output follows
[Output] =>
)
Instead of showing the list of Queues and its members
Use tcpdump and see communication between your app and asterisk server.
Also check, that same command works on asterisk.
Related
I got an error while adding Twilio SMS APi to my website. My site is in wordpress and using Woo commerce.
Error : Fatal error: Class 'Client' not found in /var/www/html/++++/wp-content/themes/dokan-theme-v2.2.2-child/functions.php on line 4583
My code is below:
function wl8OrderPlacedTriggerSomething($order_id){
//do something...
//echo get_stylesheet_directory_uri(). '/twilio-php-master/Twilio/Rest/Client.php';
require_once( get_stylesheet_directory_uri(). '/twilio-php-master/Twilio/autoload.php');
require( get_stylesheet_directory_uri(). '/twilio-php-master/Twilio/Rest/Client.php');
// Use the REST API Client to make requests to the Twilio REST API
// use Twilio\Rest\Client;
// Your Account SID and Auth Token from twilio.com/console
$sid = 'xxxxxxxxxxxxxxxxxxxxxx';
$token = 'xxxxxxxxxxxxxxxx';
$client = new Client($sid, $token);
// Use the client to do fun stuff like send text messages!
$client->messages->create(
// the number you'd like to send the message to (xxxxxxx)
'xxxxxxxxx',
array(
// A Twilio phone number you purchased at twilio.com/console
'from' => '+xxxxxxx',
// the body of the text message you'd like to send
'body' => "Hey Jenny! Good luck on the bar exam!"
)
);
}
Please help me for the same.
Thank you,
Twilio developer evangelist here.
I think you may need to use the fully qualified namespace for the Client in this case. Try:
$client = new Twilio\Rest\Client($sid, $token);
Let me know if that helps.
Edit
OK, that didn't work. After reading around, I've found that it's not recommended to use require or require_once within a function. I'd recommend you require the autoload file outside of your function, use the namespace and then call the Client inside the function. Like this:
require_once( get_stylesheet_directory_uri(). '/twilio-php-master/Twilio/autoload.php');
use Twilio\Rest\Client;
function wl8OrderPlacedTriggerSomething($order_id){
$sid = 'xxxxxxxxxxxxxxxxxxxxxx';
$token = 'xxxxxxxxxxxxxxxx';
$client = new Client($sid, $token);
// and so on...
}
make sure that autoload.php and Client.php files are getting loaded properly.
its unable to load client call
I'm facing quite an issue and I really don't know what it's caused by at all. A lot of stuff on my website gets done via websockets, for example pushing messages to clients.
For pushing I'm using ZMQ and Ratchet.
This is the php code:
$UserMessage = array(
'user' => $userid,
'message' => 'Search started',
);
$context = new \ZMQContext();
$socket = $context->getSocket(\ZMQ::SOCKET_PUSH, 'my pusher');
$socket->connect("tcp://localhost:5555");
$socket->send(json_encode($UserMessage));
This is the push-server:
<?php
require dirname(__DIR__) . '/vendor/autoload.php';
$loop = React\EventLoop\Factory::create();
$pusher = new Some\Bundle\Topic\Pusher();
// Listen for the web server to make a ZeroMQ push after an ajax request
$context = new React\ZMQ\Context($loop);
$pull = $context->getSocket(ZMQ::SOCKET_PULL);
$pull->bind('tcp://127.0.0.1:5555'); // Binding to 127.0.0.1 means the only client that can connect is itself
$pull->on('message', array($pusher, 'onMessage'));
// Set up our WebSocket server for clients wanting real-time updates
$webSock = new React\Socket\Server($loop);
$webSock->listen(8181, '0.0.0.0'); // Binding to 0.0.0.0 means remotes can connect
$webServer = new Ratchet\Server\IoServer(
new Ratchet\Http\HttpServer(
new Ratchet\WebSocket\WsServer(
new Ratchet\Wamp\WampServer(
$pusher
)
)
),
$webSock
);
$loop->run();
The problem is: sometimes messages don't get pushed AT ALL. This is happening very randomly. Sometimes it works like a charm for 20 messages in a row, sometimes not.
Does anyone have any idea what this might be caused by? I'm using nginx as a webserver by the way. Are there any kind of logs that might help out?
Regards
I'm trying to configure Asterisk to play a sound if it's holidays or if it's not during business hours.
After a long search her's what's i came with in Extensions.Conf:
exten => s,n,GotoIfTime(17:31-08:30|fri-mon|*|*?closed,1)
exten => s,n,SetMusicOnHold(default)
[closed]
exten => 6000,1,Answer
exten => 6000,2,MusicOnHold()
exten => 6000,n,Hangup()
i have the following in musiconhold.conf
[default]
mode=files
directory=/var/lib/asterisk/mohmp3
random=yes
How i can achieve this?
Any reply whould be very appreciated
To play a sound, you may use the Playback command.
I tried this out in our office if we get any call to our office number above working hour or on weekend, we will announce a voice that you have called on non working hours and call will be placed in queue.
The call will remain in queue with music to caller. If any employee is available they will receive it.
caller can hangup the call anytime in the queue.
These are my configuration and script which i used in our office
extensions_customs.conf
[Landing]
exten => 600,1,Answer()
exten => 600,2,AGI(work-time.php)
exten => 600,3,Hangup()
queues_additional.conf
[30]
announce-frequency=15
announce-holdtime=no
announce-position=yes
autofill=no
eventmemberstatus=no
eventwhencalled=no
joinempty=yes
leavewhenempty=no
maxlen=0
music=New
periodic-announce-frequency=0
queue-callswaiting=queue-callswaiting
queue-thankyou=queue-thankyou
queue-thereare=queue-thereare
queue-youarenext=queue-youarenext
reportholdtime=no
retry=1
ringinuse=no
servicelevel=60
strategy=rrmemory
timeout=15
weight=0
wrapuptime=0
member=Local/50872#from-queue/n,0,Agent 3,SIP/50872
member=Local/50873#from-queue/n,0,Agent 4,SIP/50873
member=Local/50874#from-queue/n,0,Agent 5,SIP/50874
member=Local/50875#from-queue/n,0,Agent 6,SIP/50875
member=Local/50876#from-queue/n,0,Agent 7,SIP/50876
member=Local/50877#from-queue/n,0,Agent 8,SIP/50877
member=Local/50878#from-queue/n,0,Agent 9,SIP/50878
work-time.php
#!/usr/bin/php-cgi -q
<?PHP
//Set time limit
set_time_limit(50);
//Include PHPAGI
require('phpagi.php');
//Development version. Set to none on production.
error_reporting(E_ALL);
//Create a new object
$agi = new AGI();
$agi->answer();
$tempDate = date('Y-m-d H:i');/**(Fetching data and time from running system)**/
$hours = date('H:i');
$day= date('D', strtotime( $tempDate));
if($hours>='09:00' && $hours<='17:30')
{
if($day=='Sat' || $day=='Sun')
{
$agi->exec('Playback','called-on-non-working');
$agi->exec('Queue','30');/**In queue call will not be hanged until callee hangup**/
}
else
{
$agi->exec('Playback','cce');
$agi->exec('Queue','30');
}
}
else
{
$agi->exec('Playback','called-on-non-working');
$agi->exec('Queue','30');
}
?>
If my office landline is called it will be transfered to extension 600(Landing) there i have my small script running called work-time.php
Before all i have created all extension number in a Queue(See queues_additional.conf)
now script will be executed, script checks for date and time if time is above office timing it will play a file and place the call in queue. Since no is available call will not be answered. And in queue Moh will be played
Xively provisioning - how does an app request a device feed ID and key?
On the "Provisioning" page it says:
"8 An application prompts the user for the serial number of the device they have just activated, the application uses a Master Key and the device serial number to request the device Feed ID and key from Xively."
This seems to suggest there's an API to do this, but I can't find it!
Does anyone know where this is in the docs or how to do this?
To get a feed ID for the device one need to make a Read Device request.
Go to Account | Settings | Add a master key
with Read/Update all permissions.
2) Note down the master key. Now to read all the devices (instances) created for a product (template) use API and key from (1)
URL: https://api.xively.com/v2/products/product_id/devices
X-ApiKey: The key you created in (1)
This API will return all devices with feedId and device keys.
A working example with Curl
include ('sensorui.inc');
include(APP_CLASS_LOADER);
// script to list all devices for a product
$url = "https://api.xively.com/v2/products/XwYNEGj4epo7HXNM0DGK/devices" ;
// API KEY
// This is master key API (from Account | settings page)
// for some reason (bug?) READ only key does not work!
$xheaders = array("X-ApiKey" => "your_master_key");
$cookies = array();
$curl = new \com\yuktix\util\curl\Wrapper($url,$cookies,$xheaders) ;
$curl->setCookies($cookies);
$curl->setXHeaders($xheaders);
// $curl->setDebug();
$response = $curl->doGet();
print_r($response);
$code = ($response["code"] != 200) ? 1 : 0 ;
return $code ;
Returns
rjha#kubuntu13:~/code/bitbucket/sensorui/scripts/xively$ php list-product.php
Array
(
[code] => 200
[response] => {"totalResults":2,"itemsPerPage":30,"startIndex":1,"devices":[{"serial":"SVSN001","activation_code":"xxx","created_at":"2014-02-02T15:05:37Z","activated_at":"2014-02-02T15:12:41Z","feed_id":xxx,"api_key":"xxx"},{"serial":"SVSN002","activation_code":"xxxx","created_at":"2014-02-02T15:05:37Z","activated_at":null,"feed_id":xxxx}]}
I have recently written a lot of selenium 1 tests for a fairly complex project. They are all written in php and run smoothly on the selenium-server 1.0.7.
Obviously with firefox 5 (and 6 released today) selenium server 1.0.7 is not working anymore. I've tried, but the server is just opening blank windows.
Now I am trying to get those tests running on selenium grid. I managed to get a hub and a couple of remote-controls runnnig using grid v1, but they only open blank windows just like the old server did. So I figured i needed to upgrade to grid v2.
For some reason i can get the clients connected to the hub, but if I try running my tests against the hub it doesn't seem to be able to connect at all ("PHPUnit_Framework_Exception: Could not connect to the Selenium RC server"). I tried running them against selenium standalone server 2.4.0 and that does seem to work.
I read in a forum, that selenium grid 2 just doesn't work with phpunit (yet?).
How can i get my tests running on a grid? What is missing for phpunit to connect to the server? I appreciate any help!
I set up the hub as follows:
java -jar selenium-server-standalone-2.4.0.jar -role hub
And two slaves:
java -jar selenium-server-standalone-2.4.0.jar -role rc -hub http://127.0.0.1:4444/grid/register -port 5555
java -jar selenium-server-standalone-2.4.0.jar -role webdriver -hub http://127.0.0.1:4444/grid/register -port 5556
Everything seems to be working till here as i see two nodes in the grid console (http://localhost:4444/grid/console).
So here is all the initialization I am doing in code:
<?php
require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
class Grid_Test extends PHPUnit_Extensions_SeleniumTestCase
{
public $captureScreenshotOnFailure = false;
public static $browsers = array(
'FFLinux' => array(
'name' => 'Firefox on Linux',
'browser' => '*firefox',
'host' => '127.0.0.1',
'port' => 4444,
'timeout' => 30000
));
public function setUp()
{
$this->setBrowserUrl('http://www.google.com');
}
public function testGridWorking()
{
$this->open('/');
$this->assertTrue(false);
}
}
This code still works on the standalone server 2.4.0. It fails at the last line as expected.
The Exception seems to be thrown in PHPUnit/Extentions/SeleniumTestCase/Driver.php. There seems to be the problem.
protected function doCommand($command, array $arguments = array())
{
$url = sprintf(
'http://%s:%s/selenium-server/driver/?cmd=%s',
$this->host,
$this->port,
urlencode($command)
);
[...]
$handle = #fopen($url, 'r', FALSE, $context);
if (!$handle) {
throw new PHPUnit_Framework_Exception(
'Could not connect to the Selenium RC server.'
);
}
[...]
}
When i request http://localhost:4444/selenium-driver/driver in the browser, i get:
HTTP ERROR: 500
org.openqa.grid.internal.GridException: Session not available - []
RequestURI=/selenium-server/driver
Any idea how to fix this? Do I need to change that url maybe ?
Also make sure you have setup the Grid correctly here is a small post that shows how it is done : http://opensourcetester.co.uk/2011/07/06/selenium-grid-2/
BTW I dint see code that does the driver instantiation.. Am i missing something?
Here is how it is done:
require_once "phpwebdriver/WebDriver.php";
require("phpwebdriver/LocatorStrategy.php");
$webdriver = new WebDriver("localhost", "4444");
$webdriver->connect("firefox");
$webdriver->get("http://google.com");
$element = $webdriver->findElementBy(LocatorStrategy::name, "q");
$element->sendKeys(array("selenium google code" ) );
$element->submit();
$webdriver->close();
for more: http://code.google.com/p/php-webdriver-bindings/
The problem with trying to use PHPUnit with Selenium Grid 2 has already been reported to the project owners. Have a look at the patch available here to see if it works for you.
Anyway, if I were you I would start thinking about migrating to WebDriver through one of the drivers available out there for PHP, like php-webdriver.