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

Getting error.grammar.choice in menu

Questions and answers about IVR programming for Plum DEV

Moderators: admin, support

Post Reply
dking
Posts: 15
Joined: Thu Jun 10, 2004 1:44 pm

Getting error.grammar.choice in menu

Post by dking »

I'm working with a demo account on http://hosting.plumgroup.com. The VoiceXML Validator doesn't encounter any errors in the xml listed below but I get error.grammar.choice when I call in (call log listed below).

What am I doing wrong?

-----------------------------
VoiceXML
-----------------------------

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>

<vxml xmlns="http://www.w3.org/2001/vxml"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.w3.org/2001/vxml http://www.w3.org/TR/voicexml20/vxml.xsd"
      version="2.0">







<script>
<![CDATA[
function speakablePhoneNumber(num) {
		var str = "";
		var startIndex = 0;

		// keep 800 together so it is read as "eight-hundred"
		if (num.match(/^800/)) {
			startIndex = 3;
			str += "800 ";
		}

		for (var i = startIndex; i < num.length; i++) {
			str += num.charAt(i) + " ";

			// pause after area code and three-digit prefix
			if ((i == 2) || (i == 5)) {
			    str += ", ";
			}
		}

		return str;
}

function speakableNumber(num) {
    var digitString = "";

    for (var i = 0; i < num.length; i++) {
        digitString += num.charAt(i) + " ";
    }

    return digitString;
}
]]>
</script>

<!-- turn off speech recognition -->
<property name="inputmodes" value="dtmf"/>
















<script>
  var contractNum = "3";
  var callbackNum;
  var message;
  var requestTypeID;
  var productID;

  var requestTypeList = new Array();
  
    
      requestTypeList[1] = 52894;
    
      requestTypeList[2] = 52908;
    
  

  var productList = new Array();
  
    
      productList[1] = 52852;
    
      productList[2] = 52850;
    
  
</script>


  
    
      
      

      
        
        
          <menu id="main">
            <prompt>

              Select a product for this ticket from the following choices: <enumerate/>
            </prompt>

            
              <choice dtmf="1" next="#setProduct">
                For David's Portal, press 1.
              </choice>
            
              <choice dtmf="2" next="#setProduct">
                For default, press 2.
              </choice>
            

            <noinput>

              <reprompt/>
            </noinput>
            <nomatch>
              I'm sorry, the value you entered is invalid.
              <reprompt/>
            </nomatch>
          </menu>
        
      
    
  
  


<form id="setProduct">
  <block>

    <prompt>You selected <value expr="application.lastresult$[i].utterance"/>.</prompt>
    <assign name="productID" expr="productList[application.lastresult$[i].utterance]"/>
    <goto next="#callbackMenu"/>
  </block>
</form>

<menu id="callbackMenu">
  <prompt>
    To enter a call back number, press 1.
    To continue without entering a call back number, press 2.
  </prompt>

  <noinput>
    <reprompt/>
  </noinput>
  <nomatch>
    I'm sorry, the value you entered is invalid.
    <reprompt/>
  </nomatch>

  <choice dtmf="1" next="#getCallbackNum"/>
  <choice dtmf="2" next="#useContractPhoneNumber"/>

</menu>

<form id="getCallbackNum">
  <field name="callbackNumField" type="digits?length=10">
    <prompt>
      Please enter the phone number, including area code, where you may be contacted.
    </prompt>
    <noinput>
      <reprompt/>
    </noinput>
    <nomatch>

      I'm sorry, the value you entered is invalid.
      <reprompt/>
    </nomatch>
  </field>

  <field name="confirmCallback" type="boolean">
    <prompt>
      You entered <value expr="speakablePhoneNumber(callbackNumField)"/>.
      If this is correct, press 1.
      To enter the call back number again, press 2.
    </prompt>
    <noinput>

      <reprompt/>
    </noinput>
    <nomatch>
      I'm sorry, the value you entered is invalid.
      <reprompt/>
    </nomatch>
    <filled>
      <if cond="confirmCallback">
        <assign name="callbackNum" expr="callbackNumField"/>

        <goto next="#getRequestType"/>
      <else/>
        <goto next="#getCallbackNum"/>
      </if>
    </filled>
  </field>
</form>

<form id="useContractPhoneNumber">
  <block>

    
    <assign name="callbackNum" expr="session.telephone.ani"/>
    <goto next="#getRequestType"/>
  </block>
</form>

<form id="getRequestType">
  <field name="requestTypeField" type="digits">
    <prompt>
      Select a request type for this ticket:
      
        
          For Bug, press 1.
        
          For Feature Request, press 2.
        
      
    </prompt>
    <noinput>

      <reprompt/>
    </noinput>
    <nomatch>
      I'm sorry, the value you entered is invalid.
      <reprompt/>
    </nomatch>

    <filled>
      <if cond="(requestTypeField == 0) || (requestTypeField > requestTypeList.length)">
        <prompt>I'm sorry, <value expr="requestTypeField"/> is an invalid response.</prompt>

        <clear namelist="requestTypeField"/>
      <else/>
        <assign name="requestTypeID" expr="requestTypeList[requestTypeField]"/>
        <goto next="#getMessage"/>
      </if>
    </filled>
  </field>
</form>

<form id="getMessage">

  <record name="messageField" beep="true" maxtime="120s"
          finalsilence="4000ms" dtmfterm="true" type="audio/x-wav">
    <prompt>Please leave a message after the beep.</prompt>
    <filled>
      <assign name="message" expr="messageField"/>
      <goto next="#messageMenu"/>
    </filled>
  </record>
</form>

<menu id="messageMenu">
  <prompt>
    To listen to this message, press 1.
    To use this message, press 2.
    To re-record the message, press 3.
  </prompt>
  <noinput>
    <reprompt/>
  </noinput>
  <nomatch>
    I'm sorry, the value you entered is invalid.
    <reprompt/>

  </nomatch>

  <choice dtmf="1" next="#listenToMessage"/>
  <choice dtmf="2" next="#submitTicket"/>
  <choice dtmf="3" next="#getMessage"/>
</menu>

<form id="submitTicket">
  <block>
    <submit next="http://dking.zeus.dev.poss.com/desktop?control_action=HD_PORTS_TICKET_CREATE"
            method="post"
            enctype="multipart/form-data"
            namelist="contractNum callbackNum
                      requestTypeID message
                      productID"
            fetchtimeout="100s"/>
  </block>

</form>

<form id="listenToMessage">
  <block>
    <audio expr="message"/>
    <goto next="#messageMenu"/>
  </block>
</form>

</vxml>

------------------------------
Call Log
------------------------------

Wed 21 Jul 2004 04:47:04 PM EDT:
New call
Beginning tel session
Beginning prompt session
Beginning rec session
Call Start ANII 7175061128 DNIS 3108 VURL http://hosting.plumgroup.com/plumvp/director.vxml
DocumentParser::FetchDocument()
Previously playing audio (if any) has finished
Previously playing audio (if any) has finished
DocumentParser::FetchDocument(http://hosting.plumgroup.com/plumvp/director.vxml)
Attempting to fetch http://hosting.plumgroup.com/plumvp/director.vxml
VXI::var_element(name="dnis" expr = "session.telephone.dnis")
Previously playing audio (if any) has finished
Previously playing audio (if any) has finished
DocumentParser::FetchDocument(director.php)
Posted form data is URL encoded
Attempting to fetch http://hosting.plumgroup.com/plumvp/director.php

Previously playing audio (if any) has finished
Previously playing audio (if any) has finished
DocumentParser::FetchDocument([edited])
Attempting to fetch [edited]

Wed 21 Jul 2004 04:47:07 PM EDT:
GrammarManager::CreateGrammarFromString(application/x-jsgf):
---------

<?xml version='1.0'?>
<grammar type="application/jsgf" mode="dtmf">
(1)
</grammar>

---------

GrammarManager::CreateGrammarFromString(application/x-jsgf):
---------

<?xml version='1.0'?>
<grammar type="application/jsgf" mode="dtmf">
(2)
</grammar>

---------

Loading Builtin builtin:grammar/digits
Loading Builtin builtin:dtmf/digits
Loading Builtin builtin:grammar/digits
Loading Builtin builtin:dtmf/digits
Attempting to fetch [edited]
bargein set to true
INPUTMODES set to "DTMF"
Audio segment added to prompt queue from TTS text/plain;charset=wchar_t for:
---------
Welcome to Perfect Order telephone support.
---------
VXI::queue_prompts()
bargein set to true
INPUTMODES set to "DTMF"
Audio segment added to prompt queue from TTS text/plain;charset=wchar_t for:
---------

To submit a ticket, press 1.
To check the status of a ticket, press 2.

---------
VXI::do_recognition()
PromptManager::Play()
Previously playing audio (if any) has finished
Previously playing audio (if any) has finished
Newly queued prompts are now being played

Wed 21 Jul 2004 04:47:13 PM EDT:
Found grammar match
hypothesis #11
VXI::queue_prompts()
bargein set to true
INPUTMODES set to "DTMF"
Audio segment added to prompt queue from TTS text/plain;charset=wchar_t for:
---------
Enter contract number.
---------
VXI::field_element - activating grammars for form = 'submitTicket' formitem = 'contractNum'
VXI::do_recognition()
PromptManager::Play()
Previously playing audio (if any) has finished
Previously playing audio (if any) has finished
Newly queued prompts are now being played

Wed 21 Jul 2004 04:47:16 PM EDT:
Found grammar match
hypothesis #13
Previously playing audio (if any) has finished
Previously playing audio (if any) has finished
DocumentParser::FetchDocument([edited])
Posted form data is URL encoded
Attempting to fetch [edited]

Wed 21 Jul 2004 04:47:19 PM EDT:
Loading Builtin builtin:grammar/digits
Loading Builtin builtin:dtmf/digits
Attempting to fetch [edited]
VXI::queue_prompts()
bargein set to true
INPUTMODES set to "DTMF"
Audio segment added to prompt queue from TTS text/plain;charset=wchar_t for:
---------
Enter PIN for this contract.
---------
VXI::field_element - activating grammars for form = 'activeContract' formitem = 'pin'
VXI::do_recognition()
PromptManager::Play()
Previously playing audio (if any) has finished
Previously playing audio (if any) has finished
Newly queued prompts are now being played

Wed 21 Jul 2004 04:47:24 PM EDT:
Found grammar match
hypothesis #11234
VXI::var_element(name="contractNum" expr = "3")
Previously playing audio (if any) has finished
Previously playing audio (if any) has finished
DocumentParser::FetchDocument([edited])
Posted form data is URL encoded
Attempting to fetch [edited]

Wed 21 Jul 2004 04:47:26 PM EDT:
GrammarManager::CreateGrammarFromString(application/x-jsgf):
---------

<?xml version='1.0'?>
<grammar type="application/jsgf" mode="dtmf">
(For David's Portal, press 1.)
</grammar>

---------

bargein set to true
INPUTMODES set to "DTMF"
Audio segment added to prompt queue from TTS text/plain;charset=wchar_t for:
---------

A serious error of type
---------
bargein set to true
INPUTMODES set to "DTMF"
Audio segment added to prompt queue from TTS text/plain;charset=wchar_t for:
---------
error.grammar.choice
---------
bargein set to true
INPUTMODES set to "DTMF"
Audio segment added to prompt queue from TTS text/plain;charset=wchar_t for:
---------
has occured. Exiting.
---------
VXI::exit_element()
Previously playing audio (if any) has finished
Newly queued prompts are now being played

Wed 21 Jul 2004 04:47:32 PM EDT:
Previously playing audio (if any) has finished
Call End Event
Ending session
Ending Session On Channel 0

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

test IVR script incrementaly before errors accumulate

Post by support »

Hello:

It would appear that you have several problems with your vxml script:

1) In your first menu, you use the <enumerate> tag, but then for your <choice> tags, the contents are listing the options explicitly. You can fix this by changing your menu to something like this:

Code: Select all

<menu id="main">
   <prompt>
       Select a product for this ticket from the following choices:
       For David's Portal, press 1.
       For default, press 2.
   </prompt>
           
   <choice dtmf="1" next="#setProduct"/>      
   <choice dtmf="2" next="#setProduct"/>
  
           
  <noinput>
      <reprompt/>
  </noinput>
  <nomatch>
      I'm sorry, the value you entered is invalid.
      <reprompt/>
  </nomatch>
</menu>

2) in the setProduct form, you use

Code: Select all

<prompt>You selected <value expr="application.lastresult$[0].utterance"/>.</prompt>

But this IVR application variable is not filled for <choice> tags. Its only filled in for fields.
I would recommend that you test your script incrementaly...if you wait too long before testing your IVR script you will find that the IVR errors will accumulate and be harder to track. The rule of them we go by here is to test every fairly good sized form/dialog/menu after adding it. That way most IVR errors you encounter later will be constrained to the current piece you are working on.

Hope this helps! After fixing these 2 problems, feel free to post back should you encounter any more IVR issues you cant diagnose :)

Plum Support
Last edited by support on Thu Feb 25, 2010 4:42 pm, edited 3 times in total.

dking
Posts: 15
Joined: Thu Jun 10, 2004 1:44 pm

Follow-up questions

Post by dking »

1) I can only specify text in the choice tag's body if I am accepting speech input?

2) How do I easily assign the selected choice to a variable? The choices are dynamically generated and I'd rather not iterate over them multiple times (once for prompt, once for choices, once for forms, etc).

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

choice tag not best option for this IVR application

Post by support »

1) No, you can put text into the choice tags' body, but when you use the <enumerate> tag, it will specify the dtmf digit that corresponds with each choice. I just removed the references to the <enumeration> for simplicity since the dtmf digits are hardcoded in the preceding prompt.

2)If you want to assign a value depending on which option was chosen, a <choice> tag is probably not the most appropriate construct for this IVR application. You could do something like this:

Code: Select all

<form id="test_menu">
  <field name="choose_option">
    <grammar>1|2|3|4</grammar>
    <prompt>
       If responding to an Insurance Operations Cancellation Notice,
       Press 1.

       To request a call back from an Underwriter,
       Press 2.
	
	To repeat this information,
	Press 3.

	To return to the main menu,
	Press 4.
    </prompt>

  <filled>
	<if cond="choose_option == '1'">
	   <goto next="#get_transfer_extension"/>

	<elseif cond="choose_option == '2'"/>
	  <assign name="transfer_ext" expr="'3209'"/>
          <goto next="#transfer"/>

        <elseif cond="choose_option == '3'" />
          <!-- repeat this menu -->
	  <goto next="#test_menu"/>

	<elseif cond="choose_option == '4'" />
	  <submit next="main_menu.php" method="post"/>

	</if>
  </filled>
  <catch event="nomatch noinput">
    <audio src="wav/choose_option.wav">
	  Please choose from the following options
	</audio>
    <reprompt />
  </catch>
  </field>
</form>
Please ignore the random bits of business logic; I pulled this example out of some source from a Plum client project :)

Post Reply