Ask Grammar

The bot asks and acknowledges an intention in the user's sentence, based on a grammar file or through the IBM RPA Studio grammar editor.

Starting from IBM RPA 23.0.3, this command is removed from the product. For more information, see Removed.

Important:As a result from the command's removal on IBM RPA 23.0.3, it no longer works on newer IBM RPA client versions.

Command availability: IBM RPA SaaS and IBM RPA on premises

Script syntax

IBM RPA's proprietary script language has a syntax similar to other programming languages. The script syntax defines the command's syntax in the script file. You can work with this syntax in IBM RPA Studio's Script mode.

ivrAskGrammar [--isfromeditor(Boolean)] --assetname(String) --grammar(String) [--retry(Boolean)] [--attempts(Numeric)] [--retrytext(String)] [--timeoutsub(String)] [--recognitionTimeout(TimeSpan)] [--speechCompleteTimeout(TimeSpan)] [--noInputTimeout(TimeSpan)] [--speechIncompleteTimeout(TimeSpan)] [--confidenceThreshold(Numeric)] [--beep(Boolean)] [--language(Language)] --text(String) [--timeout(TimeSpan)] (String)=value (String)=utterance (Boolean)=timedout (Boolean)=success (String)=botHistoryMessageId

Input parameter

The following table displays the list of input parameters available in this command. In the table, you can see the parameter name when working in IBM RPA Studio's Script mode and its Designer mode equivalent label.

Designer mode label Script mode name Required Accepted variable types Description
Use grammar editor isfromeditor Optional Boolean Enable to use a grammar file.
Grammar File assetname Required when Use grammar editor is False Text Grammar's asset file.
Grammar grammar Required when Use grammar editor is True Text Grammar that is created by questions and answers in the Grammar Editor.
Retry retry Optional Boolean Enable to the bot ask a new question if there is no answer on the first attempt.
Attempts attempts Optional Number Number of times the question is asked again.
Alternatives texts retrytext Optional Text Alternative question asked if there is no answer on the first attempt.
Time out sub timeoutsub Optional Text Subroutine executed if user response time runs out.
Recognition timeout recognitionTimeout Optional Time Span Timeout to acknowledge the user's response.
Speech complete timeout speechCompleteTimeout Optional Time Span Timeout for user silence after bot speech.
No input timeout noInputTimeout Optional Time Span Time for the user to start the conversation.
Speech incomplete timeout speechIncompleteTimeout Optional Time Span Maximum waiting time for a user speech that has not yet ended.
Confidence threshold confidenceThreshold Optional Number Confidence level for the recognition of an intention in the user's sentence.
Confidence rate ranges from 1 to 100. If recognition has a lower rate than specified, the returned value is null.
Beep beep Optional Boolean Beep that is played on each bot answer.
This parameter is only used for communication type "IVR".
Language language Optional Language Language used in bot conversation.
A variable of type Language must be entered, which is obtained using the Create a Language command.
Text text Required Text Question asked to the user by the bot.
Timeout timeout Optional Time Span, Number, Text Timeout for waiting for user response.

Output parameter

Designer mode label Script mode name Accepted variable types Description
Value value Text Returns the intent recognized in the user's sentence
Utterance utterance Text Returns the complete sentence informed by the user.
Timed out timedout Boolean Returns True if the maximum wait time for the user's response has ran out, or False otherwise.
Success success Boolean Returns True if the script executes successfully, or False otherwise.
History Message botHistoryMessageId Text Returns an identifier for other commands to save your history along with the history of this command.

This field returns the identity value of the saved history if one has been set Storage Adapter at the Connect to Chatbot command. To use it, simply add this output to the command-specific input parameter whose history you want to link to this command's history.

Example

Based on a XML grammar file containing the values "Seattle", "Los Angeles", "New York" and "Miami" that specify US cities, the robot asks the user which city he wants to go, using the file as a filter to recognize the user response.

defVar --name userName --type List --innertype String
defVar --name language --type Language
defVar --name voiceEngine --type SpeechEngine
defVar --name answerRecognized --type String
defVar --name userCompleteSentence --type String
defVar --name timeAnswer --type Boolean
defVar --name successExecution --type Boolean
googleEngine --culture "en-US" --voice "en-US-Standard-E" voiceEngine=value
createLanguage --culture "en-US" --speech ${voiceEngine} language=value
botConnect --type "Ivr" --language ${language} --autoanswer  --timeout "00:00:05"
	botAskName --beep  --text "Hello, what is your name?" --textformat "0" --timeout "00:01:00" userName=values
	// Download the following file to execute the command.
	ivrAskGrammar --assetname "grammarFile.xml" --confidenceThreshold 100 --beep  --text "${userName}, which city in the United States would you like to fly to?" --textformat "Markdown" --timeout "00:00:05" answerRecognized=value userCompleteSentence=utterance timeAnswer=timedout successExecution=success
	botSay --text "Thanks, ${userName}!Good flight to ${answerRecognized}!" --textformat "0"
botDisconnect

You can use the following structure to create the grammar file:

<?xml version="1.0" encoding="UTF-8" ?>  
<grammar version="1.0" xml:lang="en-US"  
         xmlns="http://www.w3.org/2001/06/grammar"  
         tag-format="semantics/1.0" root="Main">    
  <rule id="Main">  
    <item>  
      I would like to fly from <ruleref uri="#Cities"/>  
      to <ruleref uri="#Cities"/>  
    </item>  
  </rule>  
  
  <rule id="Cities" scope="public">  
    <one-of>  
      <item> Seattle </item>  
      <item> Los Angeles </item>  
      <item> New York </item>  
      <item> Miami </item>  
    </one-of>  
  </rule>  
</grammar>
Note:When you run this command using IVR type, you get prompted by a window to call the IVR. This window might show a phone number or the Zoiper QR code to calls via the Zoiper application. You see this window in debug mode in the IBM RPA Studio.

Starting from IBM RPA 23.0.3, this window isn't available due to the IVR removal. For more information, see Removed.