Hi i want to be able to run the php script below from web browser, make a call and then play sound.
When i run the file it show that connection established but call does not work.
Am new to phpagi and am not sure how to do this, just guessing with code below, any help please?
<?php
require "phpagi-asmanager.php";
$as = new AGI_AsteriskManager();
$res = $as->connect("192.168.43.132", "josh", "mysecret");
if($res == FALSE) {
echo "Connection failed.\n";
}
elseif($res == TRUE){
echo "Connection established.\n";
}
$as->add_event_handler('Action', 'Originate');
$as->add_event_handler('Channel', 'SIP/john');
$as->add_event_handler('Application', 'playback');
$as->add_event_handler('Data', 'hello-world');
$as->disconnect(); //When done
?>`Preformatted text``Preformatted text`
Please edit your post to include Preformatted text
tags to preserve your original formatting.
I made this code like 10 years ago, not third party library needed
<?php
$pbx="localhost";
$pbx="localhost";
$trunk="cpeak";
$src=$_GET[src];
$dest=$_GET[dest];
$callerid=$_GET[cid];
$message=$_GET[code];
$socket = fsockopen($pbx,"5038", $errno, $errstr, $timeout);
fputs($socket, "Action: Login\r\n");
fputs($socket, "UserName: admin\r\n"); //
fputs($socket, "Secret: 1234\r\n\r\n"); //
//
$wrets=fgets($socket,128);
echo $wrets;
fputs($socket, "Action: Originate\r\n" );
fputs($socket, "Channel: SIP/$trunk/$dest\r\n" );
fputs($socket, "Application: Playback\r\n" );
fputs($socket, "Data: $message\r\n" );
fputs($socket, "CallerID: $callerid\r\n" );
fputs($socket, "Async: yes\r\n\r\n" );
fputs($socket, "Action: Logoff\r\n\r\n");
sleep (1);
$wrets=fgets($socket,128);
?>
http://165.11.118.32/webcall.php?dest=01161285411381&cid=18007142020&code=hello-world
As implied by the non-class library code above, this requirement appears to be one for AMI, not for AGI.
Thanks @ambiorixg12 and @david551 it works!!!
I only have two challenges:
- Is only playing the default asterisk .wav files and not my recorded .wav files. It seems it has to do with the codec, requiring ulaw. I use the code below to try to convert to Asterisk readable but no luck. Any help?
echo system(“sox /var/lib/asterisk/agi-bin/texttospeech/src/sound/outpusss113.wav -r 8000 -e signed-integer -b 16 -c 1 /var/lib/asterisk/agi-bin/texttospeech/src/sound/outpusss11.wav”);
- Is it possible to also detect and store in a variable a key that is pressed by the person who receives the calls?
Asterisk .wav files are not Mu-Law, they are signed linear (as per your sox parameters).
The “echo” at the beginning of your command line makes no sense
It is, use local channel to send the call to the dial plan and then using
the use any of the following methods ODBC, system() or shell() app save it on a DB, dont request me example for it because at the end I dont want to finishng writting an autodialer for you, there are a a lot exmaples on the internet