Larson Technical Services: Voice Technology Consulting

Exercise 8.3

Write an application-driven VoiceXML form that accepts a meal order at a pizza restaurant. The application should confirm the order after the order has been entered. The pizza restaurant offers the following menu:

  • Pizzas are three sizes: small, medium, and large
  • Pizzas may have one or more of these toppings: cheese, pepperoni, sausage, peppers, pineapple, and tomatoes
  • Drinks have three sizes: small, medium, and large
  • Drinks may be Coke, Pepsi, Diet Pepsi, lemonade, or water
  • An order may contain zero or more pizzas, and zero or more drinks


<?xml version="1.0"?>
<!DOCTYPE vxml PUBLIC "-//BeVocal Inc//VoiceXML 2.0//EN" 
"http://cafe.bevocal.com/libraries/dtd/vxml2-0-bevocal.dtd">
 <vxml version="2.0" xmlns = "http://www.w3.org/2001/vxml">  

<!-exercise 8.3  get drinks (get pizza toppings not implemented;  -->
<!-- they are similar to get drink)                                                   -->
<!-- get drink  --> 

<script>

     <![CDATA[
          var drink_size = new Array();
          var drink_content = new Array();

          // set listindex
          var drink_list_index  = 0;
     ]]>

</script>

<form id="get_drink"> 
     <field name = "current_drink_size">
          <prompt> Drink size: <break/> small, medium, or large? </prompt>
               <grammar type="application/grammar+xml" root = "drink_glass">
                    <rule id = "drink_glass" scope = "public">
                         <one-of>
                              <item> small </item>
                              <item> medium </item>
                              <item> large </item>
                         </one-of>
                    </rule>
               </grammar>
     </field>

     <field name = "current_drink_content">
          <prompt> Which drink? <break/> coke, pepsi, dietpepsi, lemonade, water? </prompt>
               <grammar type="application/grammar+xml" root = "drink_kind">
                    <rule id = "drink_kind" scope = "public">
                         <one-of>
                              <item> coke </item>
                              <item> pepsi </item>
                              <item> dietpepsi </item>
                              <item> lemonade </item>
                              <item> water </item>
                         </one-of>
                    </rule>
               </grammar>
    </field>

    <filled>
          <script>

          <![CDATA[
               drink_size[drink_list_index] = current_drink_size;
               drink_content[drink_list_index] = current_drink_content;
               drink_list_index = drink_list_index + 1;
          ]]>

          </script>
          <goto next="#another_drink"/>
     </filled>
</form>  

<form id="another_drink">
     <field name="more">
          <prompt>do you want another drink? </prompt>
          <grammar type = "application/grammar+xml" root = "yes_no">
               <rule id = "yes_no" scope = "public">
                    <one-of>
                         <item> yes </item>
                         <item> no </item>
                    </one-of>
               </rule>
          </grammar>
     <filled>
          <if cond = "more == 'yes'"> 
               <goto next="#get_drink"/>
          </if>
               <submit namelist= "drink_list_index drink_size drink_content"/>
     </filled>
     </field>
</form>
</vxml>

Return to the Instructor’s Page

Comments are off for this post