microsoft / botframework-sdk

Bot Framework provides the most comprehensive experience for building conversation applications.
MIT License
7.5k stars 2.44k forks source link

AnnotatedSandwichBot SandwichOrderFormComplete missing? #48

Closed IntranetFactory closed 8 years ago

IntranetFactory commented 8 years ago

When the SandwichOrder Form is completed I'd like to store the order. I didn't find any code in the sample where I could add the logic to store the successfully completed order. I think storing the resulting form is essential for any bot.

I would also like to detect if the user quits the form and which steps of the form had been completed. This would allow to analyze the order process and where users abandon there order.

willportnoy commented 8 years ago

For the first question, you can have a calling dialog that will receive the result of the IFormDialog.

For the second question, that's an interesting idea - @chrimc62 ?

chrimc62 commented 8 years ago

There is an OnCompletion method on the form builder that lets you define a delegate to be called when the form is complete. You can also compose together a chain of dialogs by using the methods off of Chain. Something like this: Chain .From(() => FormDialog.FromType()) .Do(async result => ...) You can tell if a form has been abandoned by the OperationCanceled exception in the task if you use the dialog stuff more directly. We don't have any way of reporting back how far they got though. I'll look to see what we can figure out there.

IntranetFactory commented 8 years ago

I'm afraid that I don't find the place where such a delegate should be added and how to get then the completed SandwichOrder. Would it be possible that you add such a delegate to the Microsoft.Bot.Sample.AnnotatedSandwichBot sample?

chrimc62 commented 8 years ago

Add it to the end of your BuildForm, like this: public static IForm BuildForm() { return new FormBuilder() .Message("Welcome to the sandwich order bot!") .Field(nameof(SandwichOrder.Sandwich)) .Field(nameof(SandwichOrder.Length)) .Field(nameof(SandwichOrder.Bread)) .Field(nameof(SandwichOrder.Cheese)) .Field(nameof(SandwichOrder.Toppings)) .Message("For sandwich toppings you have selected {Toppings}.") .Field(nameof(SandwichOrder.Sauces)) .Field(nameof(SandwichOrder.DeliveryAddress), validate: async (state, response) => { var result = new ValidateResult { IsValid = true }; var address = (response as string).Trim(); if (address.Length > 0 && address[0] < '0' || address[0] > '9') { result.Feedback = "Address must start with a number."; result.IsValid = false; } return result; }) .Field(nameof(SandwichOrder.DeliveryTime), "What time do you want your sandwich delivered? {||}") .Confirm("Do you want to order your {Length} {Sandwich} on {Bread} {&Bread} with {[{Cheese} {Toppings} {Sauces}]} to be sent to {DeliveryAddress} {?at {DeliveryTime:t}}?") .AddRemainingFields() .Message("Thanks for ordering a sandwich!") .OnCompletion()

IntranetFactory commented 8 years ago

Thank you.

Stevenic commented 8 years ago

Please re-open if you're still having issues.