Published on 2005-09-29 11:43:47
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->obj->start_menu($id);
....
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;
}
}
$d->close();
....
Our VoiceXML PHP code will be simply :
// VoiceXML apps
$this->app = new VoiceXML;
$this->app->start_vxml('','','en','','','2.0');
$this->app->load("message", array("","Hello, welcome to ".$PHPVOICE['CompanyName']."!","#menu","hello.wav"));
$this->app->load("menu", array("menu",$menu_items));
$this->app->end_vxml();
$this->app->generate();
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.
Member of the PHP Magazine Network, Copyright (C) 2005-2008 phpmagazine.net All Rights Reserved