public async Task <DialogTurnResult> ChooseItemCategoryStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { var state = await Accessors.CustomerDataState.GetAsync(stepContext.Context, cancellationToken : cancellationToken); var itemCategories = await Client.GetItemCategories(); if (!itemCategories.Any()) { await Chatter.SendMessageAsync(stepContext.Context, StaticTexts.NoItemCategoriesExistText); return(await stepContext.ReplaceDialogAsync(Name, cancellationToken : cancellationToken)); } state.ItemCategories = itemCategories; await Accessors.CustomerDataState.SetAsync(stepContext.Context, state, cancellationToken); var converter = new Converter <ItemCategoryDto, string>(input => input.DisplayName); return(await stepContext.PromptAsync(ItemCategoryPrompt, new PromptOptions { Prompt = await Chatter.GetActivityAsync(stepContext.Context, StaticTexts.ChooseItemCategoryText), RetryPrompt = await Chatter.GetActivityAsync(stepContext.Context, StaticTexts.ChooseItemCategoryAgainText), Choices = ChoiceFactory.ToChoices(itemCategories.ConvertAll(converter)) }, cancellationToken)); }
public async Task <DialogTurnResult> ChooseOrderStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { var state = await Accessors.CustomerDataState.GetAsync(stepContext.Context, null, cancellationToken); if (state.SalesOrders == null) { var orders = await Client.GetSalesOrdersOfCustomer(state.Customer.Number); state.SalesOrders = ConvertDictionary(orders); var attachments = new List <Attachment>(); foreach (var order in orders) { attachments.Add(StaticTexts.CreatePostedSalesOrderAttachment(order.Key, order.Value, state.Customer)); } await Accessors.CustomerDataState.SetAsync(stepContext.Context, state, cancellationToken); await stepContext.Context.SendActivityAsync(MessageFactory.Carousel(attachments), cancellationToken); await Chatter.SendMessageAsync(stepContext.Context, StaticTexts.ViewedOrdersText); } return(await stepContext.PromptAsync(OrdersPrompt, new PromptOptions { Prompt = await Chatter.GetActivityAsync(stepContext.Context, StaticTexts.EnterOrderNumberText), RetryPrompt = await Chatter.GetActivityAsync(stepContext.Context, StaticTexts.EnterOrderNumberAgainText) }, cancellationToken : cancellationToken)); }
public async Task <DialogTurnResult> PhraseStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { var state = await Accessors.CustomerDataState.GetAsync(stepContext.Context, null, cancellationToken); var phrase = await VoiceVerifier.GetEnrollmentPhraseAsync(); var profileEnrollments = await VoiceVerifier.GetNumberOfEnrollments(state.UnAuthorizedCustomer); if (profileEnrollments >= 3) { return(await stepContext.PromptAsync(VoicePrompt, new PromptOptions { Prompt = await Chatter.GetActivityAsIsAsync(StaticTexts.UploadVerificationVoiceText(phrase)), RetryPrompt = await Chatter.GetActivityAsIsAsync(StaticTexts.VoiceNotAuthenticText(phrase)) }, cancellationToken)); } await Chatter.SendMessageAsync(stepContext.Context, StaticTexts.UploadVoicesIntroText); return(await stepContext.PromptAsync(PhrasePrompt, new PromptOptions { Prompt = await Chatter.GetActivityAsIsAsync( StaticTexts.UploadVoiceText(phrase, profileEnrollments + 1)) }, cancellationToken)); }
public async Task <DialogTurnResult> ConfirmSalesOrderStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { var state = await Accessors.CustomerDataState.GetAsync(stepContext.Context, cancellationToken : cancellationToken); var attachment = StaticTexts.CreateSalesOrderAttachment(state.TempSalesOrderLines); await stepContext.Context.SendActivityAsync(MessageFactory.Attachment(attachment), cancellationToken); await Chatter.SendMessageAsync(stepContext.Context, StaticTexts.TempOrderViewedText); return(await stepContext.PromptAsync(ConfirmSalesOrderPrompt, new PromptOptions { Prompt = await Chatter.GetActivityAsync(stepContext.Context, StaticTexts.ConfirmSalesOrderText), RetryPrompt = await Chatter.GetActivityAsync(stepContext.Context, StaticTexts.ConfirmSalesOrderText) }, cancellationToken)); }
public async Task <DialogTurnResult> CustomerIdStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { var state = await Accessors.CustomerDataState.GetAsync(stepContext.Context, cancellationToken : cancellationToken); if (state.Customer != null) { return(await stepContext.ContinueDialogAsync(cancellationToken)); } await Chatter.SendMessageAsync(stepContext.Context, StaticTexts.WelcomeOrderText); return(await stepContext.PromptAsync(CustomerIdPrompt, new PromptOptions { Prompt = await Chatter.GetActivityAsync(stepContext.Context, StaticTexts.CustomerIdText), RetryPrompt = await Chatter.GetActivityAsync(stepContext.Context, StaticTexts.CustomerNotFoundText) }, cancellationToken)); }
public async Task StartOrContinueDialogAsync(ITurnContext turnContext, CancellationToken cancellationToken) { var dialogContext = await languageSet.CreateContextAsync(turnContext, cancellationToken); if (dialogContext.ActiveDialog is null) { await dialogContext.BeginDialogAsync(LanguageDialog.Name, null, cancellationToken); } else { var context = await dialogContext.ContinueDialogAsync(cancellationToken); if (context.Status == DialogTurnStatus.Complete) { await Chatter.SendMessageAsync(turnContext, StaticTexts.WelcomeText); } } }
public async Task StartOrContinueDialogAsync(ITurnContext turnContext, CancellationToken cancellationToken) { var dialogContext = await viewOrdersSet.CreateContextAsync(turnContext, cancellationToken); if (dialogContext.ActiveDialog is null) { await ResetCustomerData(turnContext, cancellationToken, false, StaticTexts.ViewOrdersIntention, true); await dialogContext.BeginDialogAsync(CustomerIdDialog.Name, null, cancellationToken); } else { var context = await dialogContext.ContinueDialogAsync(cancellationToken); if (context.Status == DialogTurnStatus.Complete) { await ResetCustomerData(turnContext, cancellationToken, false, StaticTexts.ViewOrdersIntention, false); await Chatter.SendMessageAsync(turnContext, StaticTexts.AnythingElseText); } } }
public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken)) { var state = await Accessors.CustomerDataState.GetAsync(turnContext, () => StaticTexts.SetCustomerData(false, null, false, null, null, false), cancellationToken : cancellationToken); if (turnContext.Activity.Type == ActivityTypes.Message) { if (turnContext.Activity.Attachments != null) { var url = turnContext.Activity.Attachments[0].ContentUrl; var transcribed = await SpeechRecognizer.RecognizeSpeech(url); if (transcribed != "") { await Chatter.SendMessageAsIsAsync(turnContext, "You said:" + transcribed); } turnContext.Activity.Text = transcribed; } var text = await Chatter.GetInputAsync(turnContext); var intention = await NaturalLanguageEngine.RecognizeIntention(text, cancellationToken); bool ordering = state.isOrdering; bool viewing = state.isViewing; if (!state.BotWelcomedUser || state.ChoosenLanguage == null) { await LanguageDialogSet.StartOrContinueDialogAsync(turnContext, cancellationToken); state.BotWelcomedUser = true; await Accessors.CustomerDataState.SetAsync(turnContext, state, cancellationToken); } else if (intention == StaticTexts.StartOverIntention) { await EndAllDialogsAsync(turnContext, cancellationToken); await Chatter.SendMessageAsync(turnContext, StaticTexts.CancelText); await Chatter.SendMessageAsync(turnContext, StaticTexts.AnythingElseText); } else if (intention == StaticTexts.HelpIntention) { await Chatter.SendMessageAsync(turnContext, StaticTexts.HelpText); } else if (intention == StaticTexts.ChangeLanguageIntention) { await EndAllDialogsAsync(turnContext, cancellationToken); state.ChoosenLanguage = null; await Accessors.CustomerDataState.SetAsync(turnContext, state, cancellationToken); await LanguageDialogSet.StartOrContinueDialogAsync(turnContext, cancellationToken); } else if (ordering || (intention == StaticTexts.StartOrderIntention && !viewing)) { await SalesDialogSet.StartOrContinueDialogAsync(turnContext, cancellationToken); } else if (viewing || intention == StaticTexts.ViewOrdersIntention) { await ViewOrdersDialogSet.StartOrContinueDialogAsync(turnContext, cancellationToken); } else if (intention == StaticTexts.GreetingIntention) { await Chatter.SendMessageAsync(turnContext, StaticTexts.GreetingText); } else if (intention == StaticTexts.JokeIntention) { await Chatter.SendMessageAsync(turnContext, StaticTexts.JokeText); } else { await Chatter.SendMessageAsync(turnContext, StaticTexts.NoneText); } } else if (turnContext.Activity.Type == ActivityTypes.ConversationUpdate) { if (turnContext.Activity.MembersAdded.Any()) { if (turnContext.Activity.MembersAdded[0].Name == "User") { if (!state.BotWelcomedUser) { await LanguageDialogSet.StartOrContinueDialogAsync(turnContext, cancellationToken); state.BotWelcomedUser = true; await Accessors.CustomerDataState.SetAsync(turnContext, state, cancellationToken); } } } } await Accessors.ConversationState.SaveChangesAsync(turnContext, false, cancellationToken); }