Back-end driven VoicePHP application January 27, 2009
All practical applications need to use the data on the back-end to drive certain aspect of the application behavior. For voice based interaction, it can be quite easily done in VoicePHP.
Diagram below shows a typical application flow.
Key steps to look at:
- User interacts with the VoicePHP script.
- VoicePHP script interacts with the back-end**.
- Back-end does a database lookup and formulates appropriate response which is then conveyed to user via VoicePHP interaction.
Consider the sample code below. It is split into a front-end VoicePHP file that interacts with the user and a back-end PHP file (back-end could be anything – PHP, ASP, .NET etc.).
$pin = prompt("Enter Your Pin Number"); // Back-end can use
$result = notify("http://backend.myserver.com/authenticate.php?pin=$pin");
echo "You name is $result";
//PIN used to validate the user.
$pin = $_REQUEST['pin'];
// ... assuming database is connected ..
$result = mysql_query("select * from user_info where userpin = '$pin'");
$row = mysql_fetch_row($result);
// ... do other processing and return ...
// $row -> User Name
As you can see, in the front-end VoicePHP file,
- The user is asked to enter the PIN number.
- Using notify, the application passes the information to the back-end script.
- It uses the response from notify to echo the output to user.
In the back-end script,
- The PIN number is used to do a database lookup.
- Relevant information (name, in this case) is returned back.
** Note: If one was using the “premise model”, the VoicePHP script could interact with the database directly.
Does'nt it look easy? Try VoicePHP for yourself and feel free to modify the above script. VoicePHP is easy and accessible from your free TringMe account. More details at http://voicephp.com/howitworks.html