The Sandwich Bot
Microsoft's example of bot to take a sandwich order is a perfect example of how to use forms. There are only a finite number of things you can put on a sandwich from a given restaurant so it makes sense to build a form to guide a user through the order. The way this works is it takes a serialized class and basically presents a user with a series of questions with clickable answers to keep them within the bounds of the service you offer.
Here is their example class;
using System;
using System.Collections.Generic;
// The SandwichOrder is the simple form you want to fill out. It must be serializable so the bot can be stateless.
// The order of fields defines the default order in which questions will be asked.
// Enumerations shows the legal options for each field in the SandwichOrder and the order is the order values will be presented
// in a conversation.
namespace Microsoft.Bot.Sample.SimpleSandwichBot
{
public enum SandwichOptions
{
BLT, BlackForestHam, BuffaloChicken, ChickenAndBaconRanchMelt, ColdCutCombo, MeatballMarinara,
OvenRoastedChicken, RoastBeef, RotisserieStyleChicken, SpicyItalian, SteakAndCheese, SweetOnionTeriyaki, Tuna,
TurkeyBreast, Veggie
};
public enum LengthOptions { SixInch, FootLong };
public enum BreadOptions { NineGrainWheat, NineGrainHoneyOat, Italian, ItalianHerbsAndCheese, Flatbread };
public enum CheeseOptions { American, MontereyCheddar, Pepperjack };
public enum ToppingOptions
{
Avocado, BananaPeppers, Cucumbers, GreenBellPeppers, Jalapenos,
Lettuce, Olives, Pickles, RedOnion, Spinach, Tomatoes
};
public enum SauceOptions
{
ChipotleSouthwest, HoneyMustard, LightMayonnaise, RegularMayonnaise,
Mustard, Oil, Pepper, Ranch, SweetOnion, Vinegar
};
[Serializable]
public class SandwichOrder
{
public SandwichOptions? Sandwich;
public LengthOptions? Length;
public BreadOptions? Bread;
public CheeseOptions? Cheese;
public List<ToppingOptions> Toppings;
public List<SauceOptions> Sauce;
public static IForm<SandwichOrder> BuildForm()
{
return new FormBuilder<SandwichOrder>()
.Message("Welcome to the simple sandwich order bot!")
.Build();
}
};
}
internal static IDialog<SandwichOrder> MakeRootDialog()
{
return Chain.From(() => FormDialog.FromForm(SandwichOrder.BuildForm));
}
[ResponseType(typeof(void))]
public virtual async Task<HttpResponseMessage> Post([FromBody] Activity activity)
{
if (activity != null)
{
// one of these will have an interface and process it
switch (activity.GetActivityType())
{
case ActivityTypes.Message:
await Conversation.SendAsync(activity, MakeRootDialog);
break;
case ActivityTypes.ConversationUpdate:
case ActivityTypes.ContactRelationUpdate:
case ActivityTypes.Typing:
case ActivityTypes.DeleteUserData:
default:
Trace.TraceError($"Unknown activity type ignored: {activity.GetActivityType()}");
Key concept
Getting the user to work through selection choices is very cool, and huge time saver, but you need to remember to use last weeks blog to save the data, so when you get through the questions, you know which sandwich and what options the user has selected, then you can take them to a payment website, and deliver the sandwich.
Next week we are going to use some machine learning and show you how to handle types of free text users questions. For this we will employee Microsoft LUIS.
Doug Routledge, C# Lync, Skype for Business, SQL, Exchange, UC,
Full Stack Developer BridgeOC Bridge Operator Console Twitter - @droutledge @ndbridge |
No comments:
Post a Comment
Any spam comments will be deleted and your user account will be disabled.