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

Dynamically Create Grammar

Questions and answers about IVR programming for Plum DEV

Moderators: admin, support

Post Reply
Sparker
Posts: 14
Joined: Tue Jan 27, 2015 10:48 am

Dynamically Create Grammar

Post by Sparker »

I wish to dynamically create a different grammar for each field depending on the value of a specific field. I apologize for the "pseudo-code" below, but I'm away from work and do not have the exact code with me. I am presenting the person with a series of questions (dynamically produced). And each question has a different set of choices/answers. Some questions may be of boolean type, while others may be digit (0-9), while still others may be number. Therefore, I want to dynamically create/present the grammar per question.

In Code Behind, I evaluate a value and assign a grammar such as

Code: Select all

If(questionDataType ==1) //boolean
{
      IVRSession.gExpression = “builtin:grammar/boolean”;
}
else if(questionDataType==2) //number greater than 9
{
      IVRSession.gExpression = “builtin:grammar/number”;
}
else if(questionDataType==3) //number between 0 and 9
{
      IVRSession.gExpression = “builtin:grammar/digits”;
}
And in ASPX page I'm trying to do something like this...

Code: Select all

<var name ="qGrammar" expr="<%=IVRSession.gExpression%>" />

//some other code that works....


<field name=qAnswer>
     <grammar srcexpr="qGrammar" />
     <prompt>
          <value expr="questionOptions"/> (THIS IS A VARIABLE ESTABLISHED EARLIER THRU ANOTHER SUBDIALOG AND WORKS)
    </prompt>
</field>

When I try to do this I get the following error...
(This initial line is correctly spoken--it is the vxml that is returned via the variable "questionOptions" above)
<?xml version='1.0'?><speak>Press or say a number between 0 and 120.</speak>
---------
VXI::field_element - activating grammars for form = 'questionForm' formitem = 'qAnswer'
Cache Miss: http://MYSERVER/playGreeting.aspx
Attempting to fetch http://MYSERVER/playGreeting.aspx
HTTP/1.1 500 Internal Server Error - http://MYSERVER/playGreeting.aspx
Failure in inetptr->Open call in OSBrecLoadGrammarFromURI constructor
received event: error.badfetch.http.500:

Is it possible to dynamically create/present grammars? I'm not trying to use any "special" grammars--just the typical built-in grammars, but do need the ability to switch them depending on the type of question being asked--which isn't known until into the application.

Thanks for any assistance!

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

Re: Dynamically Create Grammar

Post by support »

Hi,

If you're looking to use only the basic, built-in grammars, you can use the type attribute of the <field> tag itself.

Here's a very basic example using the boolean built-in type with the grammars value existing in a php variable.

Code: Select all

<?php
// here's our grammar type in our server-side language
$grammar = 'boolean';
echo "<?xml version=\"1.0\"?>";
?>
<vxml version="2.0">

<form>
<field name="answer" type="<?=$grammar?>">
     <prompt>
          Please enter 1 for yes or 2 for no.
    </prompt>
    <filled>
      you entered <value expr="answer"/>.
    </filled>
</field>
</form>

</vxml>
Hopefully that helps. Please let us know if you have any additional questions.

Regards,
Plum Support

Sparker
Posts: 14
Joined: Tue Jan 27, 2015 10:48 am

Re: Dynamically Create Grammar

Post by Sparker »

I just wanted to let you know that I've resolved this issue myself. What I ended up doing was just returning the grammar src as a string via the subdialog along with the "questionOptions" and then using that returned value in my grammar tag--did this rather than assigning the value in my Code Behind. It wasn't how I initially wished to handle it, but it works, so I'll go with it!

Post Reply