Ejemplo n.º 1
0
        private async Task PizzaFormComplete(IDialogContext context, IAwaitable <PizzaOrder> result)
        {
            PizzaOrder order = null;

            try
            {
                order = await result;
            }
            catch (OperationCanceledException)
            {
                await context.PostAsync("You canceled the form!");

                // If the user cancels the skill, send an `endOfConversation` activity to the skill consumer.
                await ConversationHelper.EndConversation(context.Activity as Activity, endOfConversationCode : EndOfConversationCodes.UserCancelled);

                return;
            }

            if (order != null)
            {
                await context.PostAsync("Your Pizza Order: " + order.ToString());
            }
            else
            {
                await context.PostAsync("Form returned empty response!");
            }

            // When the skill completes, send an `endOfConversation` activity and include the finished order.
            await ConversationHelper.EndConversation(context.Activity as Activity, order);

            context.Wait(MessageReceived);
        }
Ejemplo n.º 2
0
        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:
                    // Send an `endOfconversation` activity if the user cancels the skill.
                    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, MakeRoot);
                    }
                    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));
        }