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->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.

2 Comments on "VoiceXML PHP Framework home application improved"

  1. dele November 26, 2006 at 3:02 am · Reply

    I have carefully read and understood how to use the framework and fine. But the issue is i dont quite understand how the technology works.
    I mean, having written my PHP codes, how do i deploy it so that when people dial a number say 3567 (my number), it loads the VoiceXML i have written.
    What do i need to know.

  2. Hatem November 26, 2006 at 5:48 am · Reply

    You need a VoiceXML Browser, just find the most suitable one for you.

Leave a Comment