private async Task <DialogTurnResult> FinalStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            VacationDetail vacationDetails = await hrBotStateService.UserProfileAccessor.GetAsync(stepContext.Context, () => new VacationDetail());

            if (string.IsNullOrEmpty(vacationDetails.Name))
            {
                // Set the name
                vacationDetails.Name = (string)stepContext.Result;

                // Save any state changes that might have occured during the turn.
                await hrBotStateService.UserProfileAccessor.SetAsync(stepContext.Context, vacationDetails);
            }

            await stepContext.Context.SendActivityAsync(MessageFactory.Text(String.Format("Hi {0}. How can I help you today?", vacationDetails.Name)), cancellationToken);

            return(await stepContext.EndDialogAsync(null, cancellationToken));
        }
        private async Task <DialogTurnResult> InitialStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            VacationDetail vacationDetails = await hrBotStateService.UserProfileAccessor.GetAsync(stepContext.Context, () => new VacationDetail());

            if (string.IsNullOrEmpty(vacationDetails.Name))
            {
                return(await stepContext.PromptAsync($"{nameof(GreetingDialog)}.name",
                                                     new PromptOptions
                {
                    Prompt = MessageFactory.Text("What is your name?")
                }, cancellationToken));
            }
            else
            {
                return(await stepContext.NextAsync(null, cancellationToken));
            }
        }
示例#3
0
        private async Task GetName(ITurnContext turnContext, CancellationToken cancellationToken)
        {
            VacationDetail vacationDetails = await hrBotStateService.UserProfileAccessor.GetAsync(turnContext, () => new VacationDetail());

            if (!string.IsNullOrEmpty(vacationDetails.Name))
            {
                await turnContext.SendActivityAsync(MessageFactory.Text(String.Format("Hi {0}. How can I help you today?", vacationDetails.Name)), cancellationToken);
            }
            else
            {
                // Prompt the user for their name.
                await turnContext.SendActivityAsync(MessageFactory.Text($"What is your name?"), cancellationToken);

                // Save any state changes that might have occured during the turn.
                await hrBotStateService.UserProfileAccessor.SetAsync(turnContext, vacationDetails);

                await hrBotStateService.UserState.SaveChangesAsync(turnContext);
            }
        }