public override Task <WaterfallDialog> GetWaterfallDialog(ITurnContext turnContext, CancellationToken cancellation) { return(Task.Run(() => { return new WaterfallDialog(Name, new WaterfallStep[] { async(dialogContext, cancellationToken) => { // Get which days they want to be contacted. return await dialogContext.PromptAsync( Prompt.DaysPrompt, new PromptOptions { Prompt = Phrases.Preferences.GetUpdateDays, RetryPrompt = Phrases.Preferences.GetUpdateDaysRetry }, cancellationToken); }, async(dialogContext, cancellationToken) => { // Get the result. This was already validated by the prompt. DayFlagsHelpers.FromString((string)dialogContext.Result, ",", out DayFlags dayFlags); var user = await api.GetUser(dialogContext.Context); user.ReminderFrequency = dayFlags; await this.api.Update(user); await Messages.SendAsync(Phrases.Preferences.UpdateDaysUpdated(dayFlags), dialogContext.Context, cancellationToken); return await dialogContext.EndDialogAsync(null, cancellationToken); } }); }));
public static PromptValidator <string> Create() { return(async(promptContext, cancellationToken) => { var success = DayFlagsHelpers.FromString(promptContext.Context.Activity.Text, ",", out DayFlags dayFlags); return await Task.FromResult(success); }); }
public async Task Update(string reminderDays, bool reminderDaysIsValid) { DayFlagsHelpers.FromString(reminderDays, ",", out var dayFlags); await CreateTestFlow(DaysDialog.Name) .Test("test", Phrases.Preferences.GetUpdateDays) .Test(reminderDays, reminderDaysIsValid ? Phrases.Preferences.UpdateDaysUpdated(dayFlags) : Phrases.Preferences.GetUpdateDaysRetry) .StartTestAsync(); if (reminderDaysIsValid) { var user = await this.Api.GetUser(this.turnContext); Assert.Equal(user.ReminderFrequency, dayFlags); } }