Пример #1
0
        private async Task <DialogTurnResult> IntroStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var v3State = await _v3State.GetAsync(stepContext.Context, () => new BotData("", new Dictionary <string, object>()));

            var greetingState = v3State.GetProperty <GreetingState>(V3GreetingPropertyName);

            if (greetingState != null && !string.IsNullOrEmpty(greetingState.Name))
            {
                if (stepContext.Context.Activity.Text.Equals("change name", StringComparison.InvariantCultureIgnoreCase))
                {
                    v3State.SetProperty <bool>(ChangingNamePropertyName, true);

                    await stepContext.Context.SendActivityAsync("v4: Okay, what would you like to change your name to?");

                    await _userState.SaveChangesAsync(stepContext.Context);

                    return(new DialogTurnResult(DialogTurnStatus.Waiting));
                }

                await stepContext.Context.SendActivityAsync(MessageFactory.Text($"v4: Hi {greetingState.Name} from {greetingState.City}. You said: {stepContext.Context.Activity.Text}"), cancellationToken);

                return(new DialogTurnResult(DialogTurnStatus.Complete));
            }
            else
            {
                return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = MessageFactory.Text("v4: Hi, what is your name?") }, cancellationToken));
            }
        }
Пример #2
0
        public async override Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
        {
            await base.OnTurnAsync(turnContext, cancellationToken);

            // Save any state changes that might have occured during the turn.
            await _userState.SaveChangesAsync(turnContext, false, cancellationToken);

            await _conversationState.SaveChangesAsync(turnContext, false, cancellationToken);
        }