VoiceXML PHP Framework home application improved


I have set the default home application with a sample hello world code as you may notice. But in this article I’ll try to show a more useful usage with very small piece of code. Since we have all the VoiceXML applications under the folder app, we can use the home application to list the availables services and allow to switch to any of them.

To do so I’ll use the message module to play a welcome message, then the menu module to list the available services for the end user. We’ll just need to do some improvements to the menu module to allow adding an id.

function menu(&$obj,$params)
if (is_array($params[1])) {
$id = $params[0];
$params = $params[1];
$this->obj = &$obj;

This way we can still use the menu module in two ways with an id or without.

To list the available application we can write :

function process () {
global $PHPVOICE;
// List available apps
$menu_items = array();
$d = dir("app/");
while (false !== ($entry = $d->read())) {
if ($entry != '.' and $entry!='..' and is_dir('app/'.$entry) and $entry!='home') {
$menu_items[$entry] = $PHPVOICE["AbsoluteURI"].'/'.$entry;

Our VoiceXML PHP code will be simply :

// VoiceXML apps
$this->app = new VoiceXML;
$this->app->load("message", array("","Hello, welcome to ".$PHPVOICE['CompanyName']."!","#menu","hello.wav"));
$this->app->load("menu", array("menu",$menu_items));

Compared to the hello world sample we just called the menu module, and linked the message module with the menu module. Running this application we can have a dialogue like this :

SERVER >> "Hello, welcome to VoiceXML for PHP, please choose an option for the menu!"
SERVER >> "Say one of: audiotel auth musica naviguate"
USER > "Please enter your 5 digit pin code"

This was a sample code showing how to move from an application to another, it’s possible to make it more advanced by using database to create the menu and manage it dynamicly. It’s possible too to make the others applications link back to the home app so you can naviguate more easily.