Exemplo n.º 1
0
        private async Task <bool> ProcessTopicState(AlarmBotContext context)
        {
            string utterance = (context.Activity.AsMessageActivity().Text ?? "").Trim();

            // we ar eusing TopicState to remember what we last asked
            switch (this.TopicState)
            {
            case TopicStates.TitlePrompt:
                this.Alarm.Title = utterance;
                return(await this.PromptForMissingData(context));

            case TopicStates.TimePrompt:
                // take first one in the future if a valid time has been parsed
                var times = context.GetDateTimes();
                if (times.Any(t => t > DateTimeOffset.Now))
                {
                    this.Alarm.Time = times.FirstOrDefault(t => t > DateTimeOffset.Now);
                }
                return(await this.PromptForMissingData(context));

            case TopicStates.CancelConfirmation:
                switch (context.RecognizedIntents.TopIntent?.Name)
                {
                case "confirmYes":
                    await AddAlarmResponses.ReplyWithTopicCanceled(context);

                    // End current topic
                    return(false);

                case "confirmNo":
                    // Re-prompt user for current field.
                    await AddAlarmResponses.ReplyWithTopicCanceled(context);

                    return(await this.PromptForMissingData(context));

                default:
                    // prompt again to confirm the cancelation
                    await AddAlarmResponses.ReplyWithCancelReprompt(context, this.Alarm);

                    return(true);
                }

            case TopicStates.AddConfirmation:
                switch (context.RecognizedIntents.TopIntent?.Name)
                {
                case "confirmYes":
                    if (context.UserState.Alarms == null)
                    {
                        context.UserState.Alarms = new List <Alarm>();
                    }
                    context.UserState.Alarms.Add(this.Alarm);
                    await AddAlarmResponses.ReplyWithAddedAlarm(context, this.Alarm);

                    // end topic
                    return(false);

                case "confirmNo":
                    await AddAlarmResponses.ReplyWithTopicCanceled(context);

                    // End current topic
                    return(false);

                default:
                    return(await this.PromptForMissingData(context));
                }

            default:
                return(await this.PromptForMissingData(context));
            }
        }
Exemplo n.º 2
0
        private async Task <bool> ProcessTopicState(IBotContext context)
        {
            string utterance = (context.Request.AsMessageActivity().Text ?? "").Trim();

            // we ar eusing TopicState to remember what we last asked
            switch (this.TopicState)
            {
            case TopicStates.TitlePrompt:
                this.Alarm.Title = utterance;
                return(await this.PromptForMissingData(context));

            case TopicStates.TimePrompt:
                // take first one in the future
                this.Alarm.Time = ((BotContext)context).GetDateTimes().Where(t => t > DateTimeOffset.Now).FirstOrDefault();
                return(await this.PromptForMissingData(context));

            case TopicStates.CancelConfirmation:
                switch (context.TopIntent.Name)
                {
                case "confirmYes":
                    AddAlarmResponses.ReplyWithTopicCanceled(context);
                    // End current topic
                    return(false);

                case "confirmNo":
                    // Re-prompt user for current field.
                    AddAlarmResponses.ReplyWithTopicCanceled(context);
                    return(await this.PromptForMissingData(context));

                default:
                    // prompt again to confirm the cancelation
                    AddAlarmResponses.ReplyWithCancelReprompt(context, this.Alarm);
                    return(true);
                }

            case TopicStates.AddConfirmation:
                switch (context.TopIntent?.Name)
                {
                case "confirmYes":
                    var alarms = (List <Alarm>)context.State.UserProperties[UserProperties.ALARMS];
                    if (alarms == null)
                    {
                        alarms = new List <Alarm>();
                        context.State.UserProperties[UserProperties.ALARMS] = alarms;
                    }
                    alarms.Add(this.Alarm);
                    AddAlarmResponses.ReplyWithAddedAlarm(context, this.Alarm);
                    // end topic
                    return(false);

                case "confirmNo":
                    AddAlarmResponses.ReplyWithTopicCanceled(context);
                    // End current topic
                    return(false);

                default:
                    return(await this.PromptForMissingData(context));
                }

            default:
                return(await this.PromptForMissingData(context));
            }
        }