We've Moved! Please visit our new and improved forum over at our new portal: https://portal.plumvoice.com/hc/en-us/community/topics

How can I generate dynamic menus and other voiceXML construc

Questions and answers about IVR programming for Plum DEV

Moderators: admin, support

Post Reply
jcanter
Posts: 47
Joined: Thu Jun 19, 2003 8:54 am

How can I generate dynamic menus and other voiceXML construc

Post by jcanter »

Is there an easy way to build a list of menu options for a <field> tag dynamically. For example, I think this is the proper way to do it if I want to only accecpt option 1 or 2 in a field tag:

Code: Select all

    <field name="OptionSelected" type="digits?length=1" >
      <grammar type="application/x-jsgf">
        ( 1 | 2 )
      </grammar>
     <prompt>
        Please press 1 or 2.
      </prompt>
      <nomatch>
         You did not press 1 or 2.
      </nomatch>
      <filled>
         You pressed <value expr="OptionSelected"/>
      </filled>
    </field>
But, what is the cleanest way to do this if I want to build the options dynamically from something like a database. For example, caller one may be allowed to press 1 or 2, but caller 2 may be allowed to press 1, 2, and 5.

admin
Site Admin
Posts: 35
Joined: Thu May 29, 2003 3:12 pm

Dynamic menus in IVR appplications

Post by admin »

Yes, you can generate menu options for each field dynamically. This is usually accomplished by using some form of middleware (for the plum voice platform, many IVR developers choose php) to gather data and generate the voiceXML for the menus. Below is a simple php script that will print one of two possible vxml fields, depending on what value the $type variable contains...

Code: Select all

<?xml version="1.0"?>
<vxml version="2.0">
  <form name="user_form">
     <field name="OptionSelected" type="digits?length=1" > 
      
<?php

  /**
   this variable stores what type of user is accessing the system
   this could be passed in as a post or get variable, or retrieved from a
   database...
  */
  $type = "POWER_USER";

  //the user is a "power user" so provide them with more options
  if($type == "POWER_USER"){
?>
    <grammar type="application/x-jsgf">1|2|3</grammar> 
     <prompt> 
        Welcome power user!
        Please press 1 or 2 or 3. 
<?php
  }
  //the user is a "normal user", so there are less options provided
  else{
?>
   <grammar type="application/x-jsgf">1|2</grammar> 
     <prompt> 
        Welcome normal user
        Please press 1 or 2. 
<?php
}
?>
      </prompt> 
      <nomatch> 
         Sorry, I didn't understand you. 
      </nomatch> 
      <filled> 
         You pressed <value expr="OptionSelected"/> 
      </filled> 
    </field> 
  </form>
</vxml>
NOTE: This is not intended to solve the dynamic menu problem you specifically mentioned. Rather, it provides a simplistic IVR example of how to generate voice XML dynamically using PHP. You may also find it beneficial to use the <menu> tag.

For a comprehensive reference to all PHP functions, please visit:
http://www.php.net/docs.php

SIDE NOTE: It's import that there are no extra characters inside the <grammar> tag; it could be interpreted as the wrong IVR grammar and cause user input to fail matching.

jcanter
Posts: 47
Joined: Thu Jun 19, 2003 8:54 am

Post by jcanter »

This is interesting. So, in an unrelated example, is it then possible for the IVR to reference the $type variable. So for example, could I somehow speak the contents(POWER_USER) in a <prompt> tag?

support
Posts: 3632
Joined: Mon Jun 02, 2003 3:47 pm
Location: Boston, MA
Contact:

More Information is needed to answer your IVR question

Post by support »

Your question is unclear...could you please give a more detailed description? If you seek answers to a different question, please post them under a new IVR topic.

Thank You.

:wink:
Last edited by support on Mon Jan 18, 2010 9:57 am, edited 1 time in total.

jcanter
Posts: 47
Joined: Thu Jun 19, 2003 8:54 am

Post by jcanter »

I was just wondering if I had direct access to the php $type variable. So I could us it in a vxml script. I realize this is probably incorrect syntax, but this is what I am asking:

Code: Select all

<prompt>
  Your php variable is <value expr="$type"/>
</prompt>
[/quote]

jcanter
Posts: 47
Joined: Thu Jun 19, 2003 8:54 am

Post by jcanter »

Actually, after looking at this for a few minutes, it seems I could probably do something like this:

Code: Select all

<prompt>
  <?php
    echo '<assign name="type" expr="'.$type.'" />';
  ?>
  Your php variable is <value expr="type"/> 
</prompt>

jcanter
Posts: 47
Joined: Thu Jun 19, 2003 8:54 am

Post by jcanter »

[quote="jcanter"]Actually, after looking at this for a few minutes, it seems I could probably do something like this:

Code: Select all

<prompt>
  <?php
    echo '<assign name="type" expr="'.$type.'" />';
  ?>
  Your php variable is <value expr="type"/> 
</prompt>
However, in trying to do this, anything in the <?php ?> section is just simply being ignored.

jcanter
Posts: 47
Joined: Thu Jun 19, 2003 8:54 am

Post by jcanter »

Ok, I have it working now. I have to turn off short tags in the php.ini and add .vxml to the know php extensions in the http.conf. Thanks.

Post Reply