Is it possible to select and playback voicemessages with AGI nad PHP?


#1

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?


#2

You haven’t written an AGI. An AGI has a specific interface and way it works, and you can not just send it the contents of a sound file and have it play. You have to use the AGI interface to tell Asterisk to play a sound file on disk.

I’d suggest looking for an AGI library to start with and going from there.


#3

Thanks for the answer. Unfortunately I don’t see the command in the commands list which will tell Asterisk to play a messages.


#4

The command is documented[1] and it plays back a sound file from disk.

[1] https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+AGICommand_stream+file


#5

I saw it and didn’t understand that is used for this. I will start reading it. Thanks for the help!