Title: Windows Live Agents: Subpatterns as menu responses
Slug: windows-live-agents-subpatterns-as-menu-responses
Date: 2008-06-10 00:30:00
Author: Kartones
Lang: en
Tags: Development, Windows Live Agents
Description: Tips for using subpatterns as menu responses in Windows Live Agents.

 <p align="justify"><br>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.<br></p> <p align="justify">Using subpatterns in agent answers gives us the developers the benefits of having both structured and tidy code. </p> <p align="justify">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.</p> <p align="justify">A typical use would be this small subpattern to simulate the available options:</p> <p><font face="Courier New">subpattern ExampleForMenusPatternGroup<br>+ 1<br>+ 2<br>+ 3</font>  </p><p align="justify"> </p> <p><font face="Courier New">+ launch_example_menu<br>  - Choose one:<br>    1. First option<br>    2. Second option<br>    3. Third option<br>    &lt;br&gt;What is your option?<br>  + ANSWER=ExampleForMenusPatternGroup<br>    call ExampleMenuAnswer(ANSWER)<br>  insist<br>    - Please input a number between 1 and 3<br>    restart dialog</font>  </p><p align="justify"> </p> <p align="justify">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"?</p> <p align="justify">Here comes the trick, I think just reading the code will be clear :)</p> <p><font face="Courier New">subpattern ExampleForMenusPatternGroup {style=thawed}<br>+ 1<br>+ 2<br>+ 3<br>+ first [option]<br>  return 1<br>+ second [option]<br>  return 2<br>+ third [option]<br>  return 3</font></p> <p><br><font face="Courier New">procedure ExampleMenuAnswer(OPTION)<br>  if (OPTION == 1)<br>    - First option chosen<br>  else if (OPTION == 2)<br>    - Second option chosen<br>  else if (OPTION == 3)<br>    - Thid option chosen</font></p> <p> </p> <p>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 l<font face="Courier New">aunch_example_menu </font>code is required to reflect this richness.</p> <p align="justify"></p>
