Example #1
0
 public static IForm <SandwichOrder> BuildForm()
 {
     // When the skill completes (OnCompletion), send an `endOfConversation` activity and include the finished order.
     return(new FormBuilder <SandwichOrder>()
            .Message("Welcome to the simple sandwich order bot! Say 'end' or 'stop' and I'll end the conversation and back to the parent.")
            .OnCompletion((context, order) => ConversationHelper.EndConversation(context.Activity as Activity, order))
            .Build());
 }
        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:
                    if (activity.Text.ToLower().Contains("end") || activity.Text.ToLower().Contains("stop"))
                    {
                        await ConversationHelper.ClearState(activity);

                        await ConversationHelper.EndConversation(activity, endOfConversationCode : EndOfConversationCodes.UserCancelled);
                    }
                    else
                    {
                        await Conversation.SendAsync(activity, MakeRootDialog);
                    }

                    break;

                case ActivityTypes.EndOfConversation:
                    Trace.TraceInformation($"EndOfConversation: {activity}");

                    // Clear the dialog stack if the root bot has ended the conversation.
                    await ConversationHelper.ClearState(activity);

                    break;

                case ActivityTypes.ConversationUpdate:
                case ActivityTypes.ContactRelationUpdate:
                case ActivityTypes.Typing:
                case ActivityTypes.DeleteUserData:
                default:
                    Trace.TraceError($"Unknown activity type ignored: {activity.GetActivityType()}");
                    break;
                }
            }
            return(new HttpResponseMessage(System.Net.HttpStatusCode.Accepted));
        }