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

Questions and answers about IVR programming for Plum DEV

Moderators: support, admin

  • Author
  • Message
Offline

dgiacobb1

  • Posts: 7
  • Joined: Wed Dec 21, 2016 6:27 pm

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

PostTue Jan 31, 2017 7:31 pm

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
Offline

support

  • Posts: 3109
  • Joined: Mon Jun 02, 2003 4:47 pm
  • Location: Boston, MA

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

PostThu Feb 02, 2017 12:01 pm

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
Offline

dgiacobb1

  • Posts: 7
  • Joined: Wed Dec 21, 2016 6:27 pm

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

PostMon Feb 06, 2017 12:58 pm

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
Offline

support

  • Posts: 3109
  • Joined: Mon Jun 02, 2003 4:47 pm
  • Location: Boston, MA

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

PostMon Feb 06, 2017 3:54 pm

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
Offline

dgiacobb1

  • Posts: 7
  • Joined: Wed Dec 21, 2016 6:27 pm

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

PostThu Feb 09, 2017 12:19 pm

Thanks. Including the additional dtmf grammar with every MMDD of the year included worked successfully.

Return to Plum DEV Q&A

Who is online

Users browsing this forum: No registered users and 1 guest