Creating a VXML Interface within SCInterface

From SCInterface Wiki

Revision as of 02:09, 15 March 2006 by Admin (Talk | contribs)
(diff) ←Older revision | Current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search

Creating a VXML based interface is very easy since you can embed php into vxml files as long as you save the file with a php extension. This should enable your VXML server to render the PHP and the VXML parser will then only see valid VXML.

You will need to download the PHP API into the directory where your VXML files reside. You can do this by issuing the command: svn co svn://svn.scinterface.com/sci_phpapi

If you dont have subversion setup, you can download and install the tarball from the SCInterface site.

Once the API is installed, you'll want to use it to gather data from SCM. In our example, we'll issue a serverlist call and render the data to the user via a voice xml file.

First we'll create a php file to gather the serverlist data. In a real example, the VXML application would ask for a username/password. For example purposes we will hardcode these values:

<?php
include ("./sci_phpapi/SCM.php");

      $SCM = new SCM();
      // setup the command to get the key
      $commandList = $retMesgList = array();
      $commandList[] = array('operation' => 'userlogin',
                             'username'  => 'sdemo',
                             'password'  => 'sensor' );

      $retMesgList = $SCM->sendCommand($commandList);

      if (strcmp($retMesgList[0]->getClassType(), "messageerror") == 0)
       {
       // if we cant even get a key we can't do anything so return
       $retMesgList[0]->printError();
       return;
       }
      else
       {
       $key = $retMesgList[0]->desc;
       }


      $command = array();
      $serverlist = array( 'key' => $key, 'operation' => 'serverlist');
      $serverlist['checkStatus'] = 1;
      $serverlist['App'] = 1;
      $serverlist['SC'] = 0;
      $serverlist['SCM'] = 0;
      $command[] = $serverlist;

      $retMesgList = $SCM->sendCommand($command);
      $servers = $retMesgList[0];
//print_r($servers);
?>

This basically establishes a connection to the SCM via the userlogin command, and then executes a serverlist operation to gather only apps. The return data is stored as a php array.

We made this a separate file for ease of testing. In this fashion the file can be tested standalone, and then imported into our vxml file that renders the actual data. This is one way to separate your business and presentation logic. In this fashion you could present the same data to the user over many different interfaces without duplicating code.

The presentation file looks like this:

<?php
include("./fetch_serverlist.php");
?>
<vxml version="2.0">
  <form>
    <block>
     <audio>Executing serverlist</audio>
     <break size="medium"/>
      <?
      print("<audio>You have permissions on ". count($servers->desc_array) ." servers </audio>");
      print("<break size=\"medium\"/>");
      foreach ($servers->desc_array as $key=>$value)
       {
       print("<audio>". $servers->desc_array[$key]->serverName  ."</audio>\n");
       print("<break time=\"1s\"/>");
       if (isset($value->statusInfo[0]->output))
         {
         print("<audio>The ". $value->statusInfo[0]->name ." is ". $value->statusInfo[0]->output ." on ". $value->serverName  ."</audio>\n");
         print("<break time=\"1s\"/>");
         }
       }
      ?>
    </block>
  </form>
</vxml>

This VXML file uses PHP to loop through each item in the returned array from SCM and speak the servername and status to the user.


Thats all there is to it! Have a question? Post your question to the SCInterface Forums.