Hello,
I’m trying to select and play voicemessages which are saved in database with PHP + AGI. What I have so far is
#!/usr/bin/php
<?php
$db = 'test';
$dbuser = 'root';
$dbpass = 'xxxx';
$dbhost = 'localhost';
mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db("$db");
$row = mysql_query("SELECT * FROM voicemessages WHERE mailboxuser='5634'");
while ($result = mysql_fetch_array($row)) {
$name = $result['dir'].$result['recording'];
$tmpName = $result['recording'];
$size = $result['duration'];
$type = 'wav';
$fp = fopen($name, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
echo $content;
}
?>
and in dialplan I have simply this. extension.ael
:
9999=>{
NoOp();
WaitExten(1);
AGI(/var/lib/asterisk/agi-bin/playback.php);
};
The output in CLI is:
-- Executing [9999@internal:3] AGI("SIP/5634-0000001a", "/var/lib/asterisk/agi-bin/playback.php") in new stack
-- Launched AGI Script /var/lib/asterisk/agi-bin/playback.php
<SIP/5634-0000001a>AGI Tx >> agi_request: /var/lib/asterisk/agi-bin/playback.php
<SIP/5634-0000001a>AGI Tx >> agi_channel: SIP/5634-0000001a
<SIP/5634-0000001a>AGI Tx >> agi_language: en
<SIP/5634-0000001a>AGI Tx >> agi_type: SIP
<SIP/5634-0000001a>AGI Tx >> agi_uniqueid: 1531206865.26
<SIP/5634-0000001a>AGI Tx >> agi_version: 14.6.1
<SIP/5634-0000001a>AGI Tx >> agi_callerid: 5634
<SIP/5634-0000001a>AGI Tx >> agi_calleridname: 5634
<SIP/5634-0000001a>AGI Tx >> agi_callingpres: 0
<SIP/5634-0000001a>AGI Tx >> agi_callingani2: 0
<SIP/5634-0000001a>AGI Tx >> agi_callington: 0
<SIP/5634-0000001a>AGI Tx >> agi_callingtns: 0
<SIP/5634-0000001a>AGI Tx >> agi_dnid: 9999
<SIP/5634-0000001a>AGI Tx >> agi_rdnis: unknown
<SIP/5634-0000001a>AGI Tx >> agi_context: internal
<SIP/5634-0000001a>AGI Tx >> agi_extension: 9999
<SIP/5634-0000001a>AGI Tx >> agi_priority: 4
<SIP/5634-0000001a>AGI Tx >> agi_enhanced: 0.0
<SIP/5634-0000001a>AGI Tx >> agi_accountcode:
<SIP/5634-0000001a>AGI Tx >> agi_threadid: 139704681412352
<SIP/5634-0000001a>AGI Tx >>
PHP Warning: fopen() expects parameter 1 to be a valid path, string given in /var/lib/asterisk/agi-bin/playback.php on line 18
PHP Warning: filesize() expects parameter 1 to be a valid path, string given in /var/lib/asterisk/agi-bin/playback.php on line 19
PHP Warning: fread() expects parameter 1 to be resource, boolean given in /var/lib/asterisk/agi-bin/playback.php on line 19
PHP Warning: fclose() expects parameter 1 to be resource, boolean given in /var/lib/asterisk/agi-bin/playback.php on line 21
PHP Warning: fopen() expects parameter 1 to be a valid path, string given in /var/lib/asterisk/agi-bin/playback.php on line 18
PHP Warning: filesize() expects parameter 1 to be a valid path, string given in /var/lib/asterisk/agi-bin/playback.php on line 19
PHP Warning: fread() expects parameter 1 to be resource, boolean given in /var/lib/asterisk/agi-bin/playback.php on line 19
PHP Warning: fclose() expects parameter 1 to be resource, boolean given in /var/lib/asterisk/agi-bin/playback.php on line 21
-- <SIP/5634-0000001a>AGI Script /var/lib/asterisk/agi-bin/playback.php completed, returning 0
Is it possible to be done like this?