Page 1 of 1

Extending a grammar for <fields> with a date type specified

Posted: Tue Jan 31, 2017 6:31 pm
by dgiacobb1
Hi,

Is there a way to script a <field> that captures a date and will also allow the user to say "main menu" or press * to goto the "main menu"?

I'm currently using a <field> tag with the type of "date" <field name="dateentered" type="date"> . This works great for capturing dates. But I'm unable to figure out how to extend this to allow the user to say "main menu".

Also, your documentation said "universal" grammars for actions like "main menu" or "connect to a agent" aren't supported so defining this type of global grammar doesn't seem possible.

Thanks,
Dan

Re: Extending a grammar for <fields> with a date type specif

Posted: Thu Feb 02, 2017 11:01 am
by support
Hi Dan,

Yes, you can have multiple grammars in a field like this:

Code: Select all

<form id="multiple_grammars">
    <field name="dateentered">
      <!-- Date grammar -->
      <grammar src="builtin:grammar/date" mode="voice"/> 
      
      <!-- Main menu grammar -->
      <grammar type="application/srgs+xml" root="MAINMENU" mode="voice">
        <rule id="MAINMENU">
          <one-of>
            <item>main menu</item>
          </one-of>
        </rule>
      </grammar>
        
      <!-- * grammar -->
      <grammar type="application/srgs+xml" root="STAR" mode="dtmf">
        <rule id="STAR">
          <one-of>
            <item>*</item>
          </one-of>
        </rule>
      </grammar>
This will accept spoken dates, spoken "main menu", and the * DTMF. All valid inputs will be assigned to dateentered.

We do not support ASR (spoken) global grammars, but we do DTMF global grammars. This means you will have to include the MAINMENU grammar wherever you want to use it, but you could create the STAR grammar in your root document using the <link> tag. For more details on the <link> tag and global DTMF grammars, please take a look here: http://www.plumvoice.com/docs/dev/voicexml:tags:link

Re: Extending a grammar for <fields> with a date type specif

Posted: Mon Feb 06, 2017 11:58 am
by dgiacobb1
Thank you for the answer. This solution worked great for spoken dates, spoken "main menu", and the * DTMF.

How do I also include DTMF responses for entering a date in this field? I added this <grammar> line but it did not accept dtmf for entering a date:

<grammar src="builtin:grammar/date" mode="dtmf"/>

Thanks,
Dan

Re: Extending a grammar for <fields> with a date type specif

Posted: Mon Feb 06, 2017 2:54 pm
by support
Hi,

The grammar line you have specified does accept DTMF but there are limitations to the built-in date grammar. The built-in date grammar only takes input as YYYMMDD. For more details, please take a look at these docs (scroll down to date built-in grammar): http://www.plumvoice.com/docs/dev/devel ... :grammar?s

The alternative (and ideal) way to handle this is to build your own custom date grammar. For example: this grammar accepts dates up to 60 days from today in MMDDYY format:

Code: Select all

<grammar type="application/srgs+xml" mode="dtmf" root="DATE_ROOT">
      <rule id="DATE_ROOT">
        <one-of>
          <?php $timestamp = time();
            // Date grammar will accept today up to 60 days from now
            for ($i=0; $i<60; $i++) {
              echo '<item>'.date('mdy', $timestamp).'</item>';
              $timestamp += 86400;
            }
          ?>
        </one-of>
      </rule>
    </grammar>
We've used PHP to help us write repetitive VXML, but you may use any language of your choosing.

Regards,
Plum Support

Re: Extending a grammar for <fields> with a date type specif

Posted: Thu Feb 09, 2017 11:19 am
by dgiacobb1
Thanks. Including the additional dtmf grammar with every MMDD of the year included worked successfully.