How To Create a Menu Using VoiceModel
VoiceModel does not contain a Menu object that will present users with options and branch in the call flow based on the users input. So how do you add a menu to your voice application when using VoiceModel? Easy. Just add an Ask object and put conditions on the transitions for the state that renders the Ask object to the IVR browser. Here is some sample code that you can find in the examples for VoiceModel.
Conditions on transitions are entered as Javascript. The IVR system returns the users input in the variable called result, so we just check its value to determine which transition to take to the next state. That is all there is to create a menu in VoiceModel.
public class HomeController : VoiceController
{
public override CallFlow BuildCallFlow()
{
CallFlow flow = new CallFlow();
flow.AddState(ViewStateBuilder.Build("mainMenu",
new Ask("mainMenu", "Press one for option one. Press two for option two.",
new Grammar("digits?maxlength=1")))
.AddTransition("continue", "optionOne", new Condition("result == '1'"))
.AddTransition("continue", "optionTwo", new Condition("result == '2'"))
.AddTransition("continue", "invalidSelect",
new Condition("result != '1' && result != '2'")),true);
flow.AddState(ViewStateBuilder.Build("optionOne",
new Exit("optionOne","You selected option one. Goodbye.")));
flow.AddState(ViewStateBuilder.Build("optionTwo",
new Exit("optionTwo","You selected option two. Goodbye.")));
flow.AddState(ViewStateBuilder.Build("invalidSelect",
new Exit("invalidSelect","That was an invalid selection. Goodbye.")));
return flow;
}
}
Conditions on transitions are entered as Javascript. The IVR system returns the users input in the variable called result, so we just check its value to determine which transition to take to the next state. That is all there is to create a menu in VoiceModel.
Comments
Post a Comment