Windows Live Agents: Subpatterns as menu responses


I'm taking a small break on my Windows Live Agents Testing posts because I've taken two weeks of vacations, so this post will be just a small "trick" and in a week or two we'll get back to the custom testing framework.

Using subpatterns in agent answers gives us the developers the benefits of having both structured and tidy code.

A small trick we can do with them is use them as responses for menu-like conversation patterns, adding more richness to our agent responses.

A typical use would be this small subpattern to simulate the available options:

subpattern ExampleForMenusPatternGroup
+ 1
+ 2
+ 3

+ launch_example_menu
- Choose one:
1. First option
2. Second option
3. Third option
<br>What is your option?
+ ANSWER=ExampleForMenusPatternGroup
call ExampleMenuAnswer(ANSWER)
insist
- Please input a number between 1 and 3
restart dialog

Ok, this would accept numbers 1 to 3 as responses. But what about if we want too to accept answers as "first" or "first option"?

Here comes the trick, I think just reading the code will be clear :)

subpattern ExampleForMenusPatternGroup {style=thawed}
+ 1
+ 2
+ 3
+ first [option]
return 1
+ second [option]
return 2
+ third [option]
return 3


procedure ExampleMenuAnswer(OPTION)
if (OPTION == 1)
- First option chosen
else if (OPTION == 2)
- Second option chosen
else if (OPTION == 3)
- Thid option chosen

Now we've added a more natural answers support for our menu-like pattern. using the "return" function in subpatterns. Also, no need to change our launch_example_menu code is required to reflect this richness.

Comments?

Posted by Kartones on 2008-06-10