Page 1 of 1

Can Range be defined in Grammer

Posted: Fri Mar 27, 2009 5:34 am
by amitkhosla
Hi

I have a requirement something like this.

User should be prompted with a message to input how many days before he wants to get an alert? Means like if he "SAYS" 23 days that means that 23 days before a schedule meeting time will update the user that he has an appointment 23 days from today.

Now I want to know if we can define range while defining voice mode grammer... I actually want the field to store value like 23 days when user says "twenty three days"

<grammar type="application/x-jsgf" mode="voice">
(one{1} | two{2} .. onehundred{100})+(years|year|months|month|days|day|weeks|week)
</grammar>

Here is the code
------------------------------------
<?xml version="1.0"?>
<vxml version="2.0">
<form id="date_frm">
<field name="alertBefore">
<grammar type="application/x-jsgf" mode="voice">
(one{1} | two{2} .. onehundred{100})+(years|year|months|month|days|day|weeks|week)
</grammar>
<prompt>
Enter how many days before you want the alert?
</prompt>
<filled>
you entered <value expr="alertBefore"/>
<reprompt/>
</filled>
</field>
</form>
</vxml>

Defining a range within IVR code

Posted: Fri Mar 27, 2009 12:43 pm
by support
Hi,

The following example of IVR code should help you get started (at least with defining a range). Please note the IVR tags, <ruleref>, and how to <grammar> were implemented:

Code: Select all

<?xml version="1.0"?>
<vxml version="2.0">

  <form id="start">
    <field name="dt">
      <grammar root="main" type="application/srgs+xml" mode="voice">
        <rule id="main" scope="public">
	  <ruleref uri="builtin:grammar/number?minallowed=1;maxallowed=100;maxdecimal=0"/>
	    <item>
		<one-of>
                  <item>day</item>
                  <item>days</item>
                  <item>week</item>
                  <item>weeks</item>
                  <item>month</item>
                  <item>months</item>
                  <item>year</item>
                  <item>years</item>
		</one-of>
	    </item>
        </rule>               
      </grammar>
            
      <prompt>Enter how many days before you want the alert?</prompt>
            
      <filled>
        <prompt bargein="false">
          I think you said <value expr="dt"/>.
        </prompt>
      </filled>
            
      <nomatch>
        I'm sorry, I didn't catch that.
        <reprompt/>
      </nomatch>
    </field>
  </form>
</vxml>
Then, once you have the string, you can use javascript to check the string. For IVR example, if the user said "2 weeks", you could use javascript to check for the string, "week", in it, and then multiply the value, 2, by 7 to get the number of days.

Hope this helps.

Regards,
Plum Support

Posted: Fri Mar 27, 2009 1:20 pm
by amitkhosla
Thanks a ton :)

I was trying a lot of things & read many articles. Got this type of example as well...but i tried it different way so i thought it works only with our defined grammers when i was getting error while trying.

Thanks once again.

Regards,
Amit