public static async Task <DialogTurnResult> BuildNumberPrompt(this DialogContext dc, string message = "Please confirm: Yes to proceed or No to cancel", CancellationToken cancellationToken = default(CancellationToken)) { return(await dc.PromptAsync(nameof(NumberPrompt <int>), new PromptOptions { Prompt = MessageFactory.Text(message) }, cancellationToken)); }
protected override Task <DialogTurnResult> OnBeginDialogAsync(DialogContext innerDc, object options, CancellationToken cancellationToken = default) { return(innerDc.PromptAsync(nameof(TextPrompt), new PromptOptions() { Prompt = MessageFactory.Text("Wie viel rekursionen sollen erstellt werden?") })); }
protected override async Task OnStartAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken)) { var onboardingState = await _onboardingState.GetAsync(dc.Context, () => new OnboardingState()); if (string.IsNullOrEmpty(onboardingState.Name) || onboardingState.Number == 0) { await _responder.ReplyWith(dc.Context, MainResponses.ResponseIds.NewUserGreeting); await dc.BeginDialogAsync(nameof(OnboardingDialog)); } else { var attachement = GetGreetingCard(onboardingState.Name); var opts = new PromptOptions { Prompt = new Activity { Type = ActivityTypes.Message, Attachments = new List <Attachment> { attachement }, }, }; await dc.PromptAsync("GreetingPrompt", opts); } }
public static async Task <DialogTurnResult> BuildChoicePrompt(this DialogContext dc, string message, string[] choicelist, CancellationToken cancellationToken = default(CancellationToken)) { return(await dc.PromptAsync(nameof(ChoicePrompt), new PromptOptions { Prompt = MessageFactory.Text(message), Choices = ChoiceFactory.ToChoices(choicelist.ToList <string>()), }, cancellationToken)); }
public async Task <DialogTurnResult> ToppingStep(DialogContext dc, CancellationToken cancellationToken = default) { dc.ActiveDialog.State["stepID"] = "ToppingStep"; var toppingMessage = MessageFactory.Text("What topping would you like", "What topping would you like", InputHints.ExpectingInput); return(await dc.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = toppingMessage }, cancellationToken)); }
public async Task <DialogTurnResult> DateStep(DialogContext dc, CancellationToken cancellationToken = default) { dc.ActiveDialog.State["stepID"] = "DateStep"; var cheeseMessage = MessageFactory.Text("When would you like to take the fligh", "When would you like to take the fligh", InputHints.ExpectingInput); return(await dc.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = cheeseMessage }, cancellationToken)); }
private static async Task <DialogTurnResult> Waterfall2_Step1(DialogContext dc, WaterfallStepContext stepContext, CancellationToken cancellationToken) { await dc.Context.SendActivityAsync("step1"); return(await dc.PromptAsync("number", new PromptOptions { Prompt = MessageFactory.Text("Enter a number."), RetryPrompt = MessageFactory.Text("It must be a number") })); }
private static async Task <DialogTurnResult> WaterfallStep2(DialogContext dc, WaterfallStepContext stepContext, CancellationToken cancellationToken) { if (stepContext.Values != null) { var numberResult = (int)stepContext.Result; await dc.Context.SendActivityAsync(MessageFactory.Text($"Thanks for '{numberResult}'"), cancellationToken); } return(await dc.PromptAsync("number", new PromptOptions { Prompt = MessageFactory.Text("Enter another number.") }, cancellationToken)); }
public override async Task <DialogTurnResult> ResumeDialogAsync(DialogContext outerDc, DialogReason reason, object result = null, CancellationToken cancellationToken = default) { recursions = Convert.ToInt32(result); await outerDc.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = MessageFactory.Text($"Resume root dialog with recursion value {recursions}") }); return(await outerDc.BeginDialogAsync(nameof(WaterfallDialog))); }
private static async Task <DialogTurnResult> WaterfallStep2(DialogContext dc, WaterfallStepContext stepContext) { // step context represents values from previous (waterfall) step - in this case the first number if (stepContext.Values != null) { var numberResult = (int)stepContext.Result; await dc.Context.SendActivityAsync($"Thanks for '{numberResult}'"); } return(await dc.PromptAsync("number", new PromptOptions { Prompt = MessageFactory.Text("Enter another number.") })); }
public static async Task <DialogTurnResult> BuildConfirmYesNoPrompt(this DialogContext dc, string message = "Please confirm: Yes to proceed or No to cancel", CancellationToken cancellationToken = default(CancellationToken)) { return(await dc.PromptAsync(nameof(ChoicePrompt), new PromptOptions { Prompt = MessageFactory.Text(message), Choices = ChoiceFactory.ToChoices(new List <string>() { "Yes", "No" }), }, cancellationToken)); }
public static async Task <DialogTurnResult> ToShow(DialogContext stepContext, CancellationToken cancellationToken) { return(await stepContext.PromptAsync( nameof(TextPrompt), new PromptOptions { Prompt = CreateCarousel() }, cancellationToken )); }
public static async Task <DialogTurnResult> BuildMultilineTextPrompt(this DialogContext dc, string[] messages, string finalMessage, CancellationToken cancellationToken = default(CancellationToken)) { foreach (string msg in messages) { await SendTextActivity(dc.Context, msg, cancellationToken); } return(await dc.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = MessageFactory.Text(finalMessage) }, cancellationToken)); }
public override Task <DialogTurnResult> ContinueDialogAsync(DialogContext outerDc, CancellationToken cancellationToken = default) { if (!int.TryParse(outerDc.Context.Activity.Text, out var recursions)) { return(outerDc.PromptAsync(nameof(TextPrompt), new PromptOptions() { Prompt = MessageFactory.Text($"{outerDc.Context.Activity.Text} konnte nicht in eine Zahl konvertiert werden.") })); } return(outerDc.EndDialogAsync(recursions)); }
private static async Task <DialogTurnResult> WaterfallStep1(DialogContext dc, WaterfallStepContext stepContext) { // we are only interested in Message activities - any other type of activity we will immediately complete teh waterfall if (dc.Context.Activity.Type != ActivityTypes.Message) { return(await dc.EndAsync()); } // this prompt will not continue until we receive a number return(await dc.PromptAsync("number", new PromptOptions { Prompt = MessageFactory.Text("Enter a number.") })); }
private static async Task Waterfall2_Step2(DialogContext dc, object args, SkipStepFunction next) { if (args != null) { var numberResult = (NumberResult <int>)args; await dc.Context.SendActivityAsync($"Thanks for '{numberResult.Value}'"); } await dc.Context.SendActivityAsync("step2"); await dc.PromptAsync("number", "Enter a number.", new PromptOptions { RetryPromptString = "It must be a number" }); }
public async Task <DialogTurnResult> OriginStep(DialogContext dc, CancellationToken cancellationToken = default) { dc.ActiveDialog.State["stepID"] = "OriginStep"; var options = new string[] { "Kosice", "Bratislava", "Budapest", }.ToList(); var sizeOptions = new PromptOptions { Prompt = MessageFactory.Text("Where would you like to go?"), Choices = ChoiceFactory.ToChoices(options), }; return(await dc.PromptAsync(nameof(ChoicePrompt), sizeOptions, cancellationToken)); }
public async Task <DialogTurnResult> DestinationStep(DialogContext dc, CancellationToken cancellationToken = default) { dc.ActiveDialog.State["stepID"] = "DestinationStep"; var options = new string[] { "London", "Wiena", "Krakow", }.ToList(); var sizeOptions = new PromptOptions { Prompt = MessageFactory.Text("From where would you like to go?"), Choices = ChoiceFactory.ToChoices(options), }; return(await dc.PromptAsync(nameof(ChoicePrompt), sizeOptions, cancellationToken)); }
public async Task <DialogTurnResult> SizeStep(DialogContext dc, CancellationToken cancellationToken = default) { dc.ActiveDialog.State["stepID"] = "SizeStep"; var options = new string[] { "Small", "Medium", "Big", }.ToList(); var sizeOptions = new PromptOptions { Prompt = MessageFactory.Text("What size would you like"), Choices = ChoiceFactory.ToChoices(options), }; return(await dc.PromptAsync(nameof(ChoicePrompt), sizeOptions, cancellationToken)); }
private static async Task <DialogTurnResult> Waterfall2_Step2(DialogContext dc, WaterfallStepContext stepContext) { if (stepContext.Values != null) { var numberResult = (int)stepContext.Result; await dc.Context.SendActivityAsync($"Thanks for '{numberResult}'"); } await dc.Context.SendActivityAsync("step2"); return(await dc.PromptAsync("number", new PromptOptions { Prompt = MessageFactory.Text("Enter a number."), RetryPrompt = MessageFactory.Text("It must be a number") })); }
public override async Task <DialogTurnResult> ContinueDialogAsync(DialogContext dc, CancellationToken cancellationToken = default) { if (dc.Context.Activity.Text == "get me out") { return(await dc.EndDialogAsync("PICA", cancellationToken)); } if (dc.Context.Activity.Text == "prompt") { var promptMessage = MessageFactory.Text("Hej zidan voco go ??? ", "Hej zidan voco go???", InputHints.ExpectingInput); return(await dc.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = promptMessage }, cancellationToken)); } if (dc.Context.Activity.Text == "redirect") { throw new RedirectDialogException(); } await dc.Context.SendActivityAsync($"MUHAHAHAHAHA SI LEN MOJ a znam co pises: {dc.Context.Activity.Text}"); return(new DialogTurnResult(DialogTurnStatus.Waiting)); }
private static async Task <DialogTurnResult> WaterfallStep1(DialogContext dc, WaterfallStepContext stepContext, CancellationToken cancellationToken) { return(await dc.PromptAsync("number", new PromptOptions { Prompt = MessageFactory.Text("Enter a number.") }, cancellationToken)); }
public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken)) { // use state accessor to extract the didBotWelcomeUser flag var didBotWelcomeUser = await _botSpielUserStateAccessors.DidBotWelcomeUser.GetAsync(turnContext, () => false); var currentBotUserData = await _botSpielUserStateAccessors.BotUserDataAccessor.GetAsync(turnContext, () => _botUserData); string conCat = ""; List <string> existInEntities = new List <string>(); bool DeleteOK = true; if (turnContext.Activity.Type == ActivityTypes.Message) { // Establish dialog state from the conversation state. DialogContext dc = await _dialogs.CreateContextAsync(turnContext, cancellationToken); //Custom Code Start | Added Code Block if (turnContext.Activity.Text.ToLowerInvariant() == "cancel") { await dc.CancelAllDialogsAsync(cancellationToken); } //Custom Code End // Continue any current dialog. DialogTurnResult dialogTurnResult = await dc.ContinueDialogAsync(); // Process the result of any complete dialog. if (dialogTurnResult.Status is DialogTurnStatus.Complete) { switch (dialogTurnResult.Result) { case BotUserEntityContext botUserEntityContext: if (botUserEntityContext.module != "Choose an area") { // Store the results of the root dialog. currentBotUserData.botUserEntityContext = botUserEntityContext; await _botSpielUserStateAccessors.BotUserDataAccessor.SetAsync(turnContext, currentBotUserData, cancellationToken); await _botSpielUserStateAccessors.UserState.SaveChangesAsync(turnContext); await dc.PromptAsync(ConfirmPromptId, new PromptOptions { Prompt = MessageFactory.Text($"Please confirm that you want to {botUserEntityContext.entityIntent} {botUserEntityContext.entity}. Is that correct?") }, cancellationToken); } else { await turnContext.SendActivityAsync("OK, Let's choose a different area.", cancellationToken : cancellationToken); await dc.BeginDialogAsync(RootDialogId, null, cancellationToken); } break; case bool botYesNo: if (botYesNo) { switch (currentBotUserData.botUserEntityContext.entity) { case "PickBatchPicking": if (currentBotUserData.botUserEntityContext.entityIntent == "Create") { //Custom Code Start | Replaced Code Block //Replaced Code Block Start //await dc.BeginDialogAsync(CreatePickBatchPickingDialogId, null, cancellationToken); //Replaced Code Block End await dc.BeginDialogAsync(CreatePickBatchPickingDialogId, new PickBatchPickingPost(), cancellationToken); //Custom Code End } break; case "PutAwayHandlingUnits": if (currentBotUserData.botUserEntityContext.entityIntent == "Create") { await dc.BeginDialogAsync(CreatePutAwayHandlingUnitsDialogId, null, cancellationToken); } break; case "SetUpExecutionParameters": if (currentBotUserData.botUserEntityContext.entityIntent == "Create") { await dc.BeginDialogAsync(CreateSetUpExecutionParametersDialogId, null, cancellationToken); } break; case "DropInventoryUnits": if (currentBotUserData.botUserEntityContext.entityIntent == "Create") { await dc.BeginDialogAsync(CreateDropInventoryUnitsDialogId, null, cancellationToken); } break; default: // We shouldn't get here. break; } } else { await turnContext.SendActivityAsync(MessageFactory.Text("OK, let's try again."), cancellationToken); await dc.BeginDialogAsync(RootDialogId, null, cancellationToken); } break; case GetPickBatchesPost getpickbatchesPost: if (currentBotUserData.botUserEntityContext.entityIntent == "Create") { //Custom Code Start | Removed Block //ixGetPickBatch = await _getpickbatchesService.Create(getpickbatchesPost); //await turnContext.SendActivityAsync(MessageFactory.Text($"The GetPickBatch {ixGetPickBatch} was created"), cancellationToken); //currentBotUserData.ixGetPickBatch = ixGetPickBatch; //Custom Code End await _botSpielUserStateAccessors.BotUserDataAccessor.SetAsync(turnContext, currentBotUserData, cancellationToken); await _botSpielUserStateAccessors.UserState.SaveChangesAsync(turnContext); //await dc.BeginDialogAsync(RootDialogId, currentBotUserData.botUserEntityContext, cancellationToken); //Custom Code Start | Added Code Block //We can now set the pick batch status to started var pickbatch = _pickbatchesService.GetPost(_pickbatchesService.IndexDb().Where(x => x.sPickBatch == getpickbatchesPost.sGetPickBatch).Select(x => x.ixPickBatch).FirstOrDefault()); pickbatch.ixStatus = _commonLookUps.getStatuses().Where(x => x.sStatus == "Started").Select(x => x.ixStatus).FirstOrDefault(); pickbatch.UserName = dc.Context.Activity.Conversation.Id; await _pickbatchesService.Edit(pickbatch); _pickbatchpickingPost.sPickBatchPick = getpickbatchesPost.sGetPickBatch; await dc.BeginDialogAsync(CreatePickBatchPickingDialogId, _pickbatchpickingPost, cancellationToken); //Custom Code End } break; case PickBatchPickingPost pickbatchpickingPost: if (currentBotUserData.botUserEntityContext.entityIntent == "Create") { ixPickBatchPick = await _pickbatchpickingService.Create(pickbatchpickingPost); //Custom Code Start | Removed Block //await turnContext.SendActivityAsync(MessageFactory.Text($"The PickBatchPick {ixPickBatchPick} was created"), cancellationToken); //Custom Code End //Custom Code Start | Added Code Block //We check if the batch is complete if (!_picking.isPickBatchComplete(pickbatchpickingPost.ixPickBatch)) { currentBotUserData.ixPickBatchPick = ixPickBatchPick; await _botSpielUserStateAccessors.BotUserDataAccessor.SetAsync(turnContext, currentBotUserData, cancellationToken); await _botSpielUserStateAccessors.UserState.SaveChangesAsync(turnContext); await dc.BeginDialogAsync(CreatePickBatchPickingDialogId, pickbatchpickingPost, cancellationToken); } else { currentBotUserData.ixPickBatchPick = 0; await _botSpielUserStateAccessors.BotUserDataAccessor.SetAsync(turnContext, currentBotUserData, cancellationToken); await _botSpielUserStateAccessors.UserState.SaveChangesAsync(turnContext); //await dc.BeginDialogAsync(RootDialogId, currentBotUserData.botUserEntityContext, cancellationToken); //We can now set the pick batch status to complete var pickbatch = _pickbatchesService.GetPost(pickbatchpickingPost.ixPickBatch); pickbatch.ixStatus = _commonLookUps.getStatuses().Where(x => x.sStatus == "Complete").Select(x => x.ixStatus).FirstOrDefault(); pickbatch.UserName = dc.Context.Activity.Conversation.Id; await _pickbatchesService.Edit(pickbatch); //We begin the drop cycle await dc.BeginDialogAsync(CreateDropInventoryUnitsDialogId, pickbatchpickingPost, cancellationToken); } //Custom Code End } break; case PutAwayHandlingUnitsPost putawayhandlingunitsPost: if (currentBotUserData.botUserEntityContext.entityIntent == "Create") { ixPutAwayHandlingUnit = await _putawayhandlingunitsService.Create(putawayhandlingunitsPost); //Custom Code Start | Removed Block //await turnContext.SendActivityAsync(MessageFactory.Text($"The PutAwayHandlingUnit {ixPutAwayHandlingUnit} was created"), cancellationToken); //Custom Code End currentBotUserData.ixPutAwayHandlingUnit = ixPutAwayHandlingUnit; await _botSpielUserStateAccessors.BotUserDataAccessor.SetAsync(turnContext, currentBotUserData, cancellationToken); await _botSpielUserStateAccessors.UserState.SaveChangesAsync(turnContext); //Custom Code Start | Replaced Code Block //Replaced Code Block Start //await dc.BeginDialogAsync(RootDialogId, currentBotUserData.botUserEntityContext, cancellationToken); //Replaced Code Block End await dc.BeginDialogAsync(CreatePutAwayHandlingUnitsDialogId, null, cancellationToken); //Custom Code End } break; case SetUpExecutionParametersPost setupexecutionparametersPost: if (currentBotUserData.botUserEntityContext.entityIntent == "Create") { //Custom Code Start | Removed Block //ixSetUpExecutionParameter = await _setupexecutionparametersService.Create(setupexecutionparametersPost); //await turnContext.SendActivityAsync(MessageFactory.Text($"The SetUpExecutionParameter {ixSetUpExecutionParameter} was created"), cancellationToken); //currentBotUserData.ixSetUpExecutionParameter = ixSetUpExecutionParameter; //Custom Code End //Custom Code Start | Added Code Block currentBotUserData.ixFacility = setupexecutionparametersPost.ixFacility; currentBotUserData.ixCompany = setupexecutionparametersPost.ixCompany; currentBotUserData.ixFacilityWorkArea = setupexecutionparametersPost.ixFacilityWorkArea; //We check if the user location exists - if not we create it if (_userManager.Users.Where(x => x.UserName == dc.Context.Activity.Conversation.Id).Any()) { if (!_inventorylocationsService.IndexDb().Where(x => x.sInventoryLocation.ToLower().Trim() == dc.Context.Activity.Conversation.Id.ToLower().Trim()).Any()) { InventoryLocationsPost inventoryLocationsPost = new InventoryLocationsPost(); inventoryLocationsPost.sInventoryLocation = dc.Context.Activity.Conversation.Id.ToLower().Trim(); inventoryLocationsPost.ixLocationFunction = _locationfunctionsService.IndexDb().Where(x => x.sLocationFunctionCode == "PE").Select(x => x.ixLocationFunction).FirstOrDefault(); inventoryLocationsPost.ixFacility = currentBotUserData.ixFacility; inventoryLocationsPost.ixFacilityFloor = _inventorylocationsService.FacilityFloorsDb().Select(x => x.ixFacilityFloor).FirstOrDefault(); inventoryLocationsPost.ixFacilityZone = _inventorylocationsService.FacilityZonesDb().Select(x => x.ixFacilityZone).FirstOrDefault(); inventoryLocationsPost.ixFacilityWorkArea = _inventorylocationsService.FacilityWorkAreasDb().Select(x => x.ixFacilityWorkArea).FirstOrDefault(); inventoryLocationsPost.ixFacilityAisleFace = _inventorylocationsService.FacilityAisleFacesDb().Select(x => x.ixFacilityAisleFace).FirstOrDefault(); inventoryLocationsPost.nSequence = 0; inventoryLocationsPost.bTrackUtilisation = false; currentBotUserData.ixInventoryLocation = await _inventorylocationsService.Create(inventoryLocationsPost); } else { currentBotUserData.ixInventoryLocation = _inventorylocationsService.IndexDb().Where(x => x.sInventoryLocation.ToLower().Trim() == dc.Context.Activity.Conversation.Id.ToLower().Trim()).Select(x => x.ixInventoryLocation).FirstOrDefault(); var inventoryLocationsPost = _inventorylocationsService.GetPost(currentBotUserData.ixInventoryLocation); inventoryLocationsPost.ixFacility = currentBotUserData.ixFacility; await _inventorylocationsService.Edit(inventoryLocationsPost); } } //Custom Code End await _botSpielUserStateAccessors.BotUserDataAccessor.SetAsync(turnContext, currentBotUserData, cancellationToken); await _botSpielUserStateAccessors.UserState.SaveChangesAsync(turnContext); //Custom Code Start | Removed Block //await dc.BeginDialogAsync(RootDialogId, currentBotUserData.botUserEntityContext, cancellationToken); //Custom Code End //Custom Code Start | Added Code Block await turnContext.SendActivityAsync(MessageFactory.Text($"The setup parameters have been updated. Say/type putaway, pick or cancel."), cancellationToken); //Custom Code End } break; case DropInventoryUnitsPost dropinventoryunitsPost: if (currentBotUserData.botUserEntityContext.entityIntent == "Create") { //Custom Code Start | Removed Block //ixDropInventoryUnit = await _dropinventoryunitsService.Create(dropinventoryunitsPost); //await turnContext.SendActivityAsync(MessageFactory.Text($"The DropInventoryUnit {ixDropInventoryUnit} was created"), cancellationToken); //currentBotUserData.ixDropInventoryUnit = ixDropInventoryUnit; //await _botSpielUserStateAccessors.BotUserDataAccessor.SetAsync(turnContext, currentBotUserData, cancellationToken); //await _botSpielUserStateAccessors.UserState.SaveChangesAsync(turnContext); //await dc.BeginDialogAsync(RootDialogId, currentBotUserData.botUserEntityContext, cancellationToken); //Custom Code End await dc.BeginDialogAsync(CreateGetPickBatchesDialogId, null, cancellationToken); } break; default: // We shouldn't get here. break; } } // Proactively send a welcome message to a personal chat the first time // (and only the first time) a user initiates a personal chat. //Custom Code Start | Replaced Code Block //Replaced Code Block Start //if (didBotWelcomeUser == false) //Replaced Code Block End if (true == false) //Custom Code End { // Update user state flag to reflect bot handled first user interaction. await _botSpielUserStateAccessors.DidBotWelcomeUser.SetAsync(turnContext, true); await _botSpielUserStateAccessors.UserState.SaveChangesAsync(turnContext); // the channel should sends the user name in the 'From' object var userName = turnContext.Activity.From.Name; // We give the user the opportunity to say or request something using natural language and funnel through recognizer await turnContext.SendActivityAsync($"What would like to do? You can say things like ... or help me.", cancellationToken : cancellationToken); } //Custom Code Start | Added Code Block else if (!currentBotUserData.bIsInitialSetUpParametersSet) { currentBotUserData.bIsInitialSetUpParametersSet = true; currentBotUserData.botUserEntityContext.module = "Execution"; currentBotUserData.botUserEntityContext.entity = "SetUpExecutionParameters"; currentBotUserData.botUserEntityContext.entityIntent = "Create"; await _botSpielUserStateAccessors.BotUserDataAccessor.SetAsync(turnContext, currentBotUserData, cancellationToken); await _botSpielUserStateAccessors.UserState.SaveChangesAsync(turnContext); await dc.BeginDialogAsync(CreateSetUpExecutionParametersDialogId, null, cancellationToken); } //Custom Code End else if ((dialogTurnResult.Status is DialogTurnStatus.Empty) || turnContext.Activity.Text.ToLowerInvariant() == "putaway" || turnContext.Activity.Text.ToLowerInvariant() == "cancel") { var text = turnContext.Activity.Text.ToLowerInvariant(); // Now attempt to infer the context (NLP) // Placeholder for code to added switch (text) { //Custom Code Start | Removed Block //case "help me": // await turnContext.SendActivityAsync($"You said: {text}.", cancellationToken: cancellationToken); // break; //Custom Code End //Custom Code Start | Added Code Block case "putaway": currentBotUserData.botUserEntityContext.module = "Execution"; currentBotUserData.botUserEntityContext.entity = "PutAwayHandlingUnits"; currentBotUserData.botUserEntityContext.entityIntent = "Create"; await _botSpielUserStateAccessors.BotUserDataAccessor.SetAsync(turnContext, currentBotUserData, cancellationToken); await _botSpielUserStateAccessors.UserState.SaveChangesAsync(turnContext); await dc.BeginDialogAsync(CreatePutAwayHandlingUnitsDialogId, null, cancellationToken); break; case "pick": currentBotUserData.botUserEntityContext.module = "Execution"; currentBotUserData.botUserEntityContext.entity = "PickBatchPicking"; currentBotUserData.botUserEntityContext.entityIntent = "Create"; await _botSpielUserStateAccessors.BotUserDataAccessor.SetAsync(turnContext, currentBotUserData, cancellationToken); await _botSpielUserStateAccessors.UserState.SaveChangesAsync(turnContext); //await dc.BeginDialogAsync(CreatePickBatchPickingDialogId, new PickBatchPickingPost(), cancellationToken); await dc.BeginDialogAsync(CreateGetPickBatchesDialogId, null, cancellationToken); break; case "cancel": await dc.CancelAllDialogsAsync(cancellationToken); break; //Custom Code End default: if (dc.ActiveDialog == null && (dialogTurnResult.Status is DialogTurnStatus.Complete || dialogTurnResult.Status is DialogTurnStatus.Empty || dialogTurnResult.Status is DialogTurnStatus.Cancelled)) { await turnContext.SendActivityAsync("I do not understand, let's try something different.", cancellationToken : cancellationToken); await dc.BeginDialogAsync(RootDialogId, null, cancellationToken); } break; } } } else if (turnContext.Activity.Type == ActivityTypes.ConversationUpdate) { if (turnContext.Activity.MembersAdded.Any()) { // Iterate over all new members added to the conversation foreach (var member in turnContext.Activity.MembersAdded) { if (member.Id != turnContext.Activity.Recipient.Id) { await turnContext.SendActivityAsync($"Hi there - {member.Name}. {WelcomeMessage}", cancellationToken : cancellationToken); } } } } else { // Default behaviour for all other type of activities. await turnContext.SendActivityAsync($"{turnContext.Activity.Type} activity detected"); } // save any state changes made to your state objects. await _botSpielUserStateAccessors.UserState.SaveChangesAsync(turnContext); await _botSpielUserStateAccessors.ConversationState.SaveChangesAsync(turnContext); }
public async Task <DialogTurnResult> PromptAsync(DialogContext dialogContext, string dialogId, PromptOptions options, CancellationToken cancellationToken) => await dialogContext.PromptAsync(dialogId, options);
public async override Task <DialogTurnResult> ContinueDialogAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken)) { var context = dc.Context; // Get turn counter var turnCounter = await _turnCounterAccessor.GetAsync(context, () => new CounterState()); turnCounter.TurnCount = ++turnCounter.TurnCount; // Set updated turn counter await _turnCounterAccessor.SetAsync(context, turnCounter); // See if we have card input. This would come in through onTurnProperty var onTurnProperty = await _onTurnAccessor.GetAsync(context); if (onTurnProperty != null) { if (onTurnProperty.Entities.Count > 0) { // find user name in on turn property var userNameInOnTurnProperty = onTurnProperty.Entities.FirstOrDefault(item => string.Compare(item.EntityName, UserName, StringComparison.Ordinal) == 0); if (userNameInOnTurnProperty != null) { var userName = userNameInOnTurnProperty.Value as string; if (!string.IsNullOrWhiteSpace(userName)) { await UpdateUserProfilePropertyAsync(userName, context); } return(await ContinueDialogAsync(dc)); } } } if (turnCounter.TurnCount >= 1) { // We need to get user's name right. Include a card. var activity = dc.Context.Activity.CreateReply(); activity.Attachments = new List <Attachment> { Helpers.CreateAdaptiveCardAttachment(@".\Dialogs\WhoAreYou\Resources\getNameCard.json"), }; await context.SendActivityAsync(activity); } else if (turnCounter.TurnCount >= 3) { // We are not going to spend more than 3 turns to get user's name. return(await EndGetUserNamePromptAsync(dc)); } // Call LUIS and get results var luisResults = await _botServices.LuisServices[LuisConfiguration].RecognizeAsync(context, cancellationToken); var topLuisIntent = luisResults.GetTopScoringIntent(); var topIntent = topLuisIntent.intent; if (string.IsNullOrWhiteSpace(topIntent)) { // Go with intent in onTurnProperty topIntent = string.IsNullOrWhiteSpace(onTurnProperty.Intent) ? "None" : onTurnProperty.Intent; } // Did user ask for help or said they are not going to give us the name? switch (topIntent) { case NoNameIntent: // Set user name in profile to Human await _userProfileAccessor.SetAsync(context, new UserProfile("Human")); return(await EndGetUserNamePromptAsync(dc)); case GetUserNameIntent: // Find the user's name from LUIS entities list. if (luisResults.Entities.TryGetValue(UserName, out var entity)) { var userName = (string)entity[0]; await UpdateUserProfilePropertyAsync(userName, context); return(await base.ContinueDialogAsync(dc)); } else if (luisResults.Entities.TryGetValue(UserNamePatternAny, out var entity_pattery)) { var userName = (string)entity_pattery[0]; await UpdateUserProfilePropertyAsync(userName, context); return(await base.ContinueDialogAsync(dc)); } else { await context.SendActivityAsync("Sorry, I didn't get that. What's your name ?"); return(await base.ContinueDialogAsync(dc)); } case WhyDoYouAsk: await context.SendActivityAsync("I need your name to be able to address you correctly!"); await context.SendActivityAsync(MessageFactory.SuggestedActions(new List <string> { "I won't give you my name", "What is your name?" })); return(await base.ContinueDialogAsync(dc)); case NoneIntent: await UpdateUserProfilePropertyAsync(context.Activity.Text, context); return(await base.ContinueDialogAsync(dc)); case CancelIntent: // Start confirmation prompt var opts = new PromptOptions { Prompt = new Activity { Type = ActivityTypes.Message, Text = "Are you sure you want to cancel ?", }, }; return(await dc.PromptAsync(ConfirmCancelPrompt, opts)); default: // Handle interruption. var onTurnPropertyValue = await _onTurnAccessor.GetAsync(dc.Context); return(await dc.BeginDialogAsync(InterruptionDispatcher, onTurnPropertyValue)); } }
public async override Task <DialogTurnResult> ContinueDialogAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken)) { var turnContext = dc.Context; var step = dc.ActiveDialog.State; // Get reservation property. var newReservation = await _reservationsAccessor.GetAsync(turnContext, () => new ReservationProperty()); // Get on turn property. This has any entities that mainDispatcher, // or Bot might have captured in its LUIS model. var onTurnProperties = await _onTurnAccessor.GetAsync(turnContext, () => new OnTurnProperty("None", new List <EntityProperty>())); // If on turn property has entities.. ReservationResult updateResult = null; if (onTurnProperties.Entities.Count > 0) { // ...update reservation property with on turn property results. updateResult = newReservation.UpdateProperties(onTurnProperties); } // See if updates to reservation resulted in errors, if so, report them to user. if (updateResult != null && updateResult.Status == ReservationStatus.Incomplete && updateResult.Outcome != null && updateResult.Outcome.Count > 0) { await _reservationsAccessor.SetAsync(turnContext, updateResult.NewReservation); // Return and do not continue if there is an error. await turnContext.SendActivityAsync(updateResult.Outcome[0].Message); return(await base.ContinueDialogAsync(dc)); } // Call LUIS and get results. var luisResults = await _botServices.LuisServices[LuisConfiguration].RecognizeAsync(turnContext, cancellationToken); var topLuisIntent = luisResults.GetTopScoringIntent(); var topIntent = topLuisIntent.intent; // If we don't have an intent match from LUIS, go with the intent available via // the on turn property (parent's LUIS model). if (luisResults.Intents.Count <= 0) { // Go with intent in onTurnProperty. topIntent = string.IsNullOrWhiteSpace(onTurnProperties.Intent) ? "None" : onTurnProperties.Intent; } // Update object with LUIS result. updateResult = newReservation.UpdateProperties(OnTurnProperty.FromLuisResults(luisResults)); // See if update reservation resulted in errors, if so, report them to user. if (updateResult != null && updateResult.Status == ReservationStatus.Incomplete && updateResult.Outcome != null && updateResult.Outcome.Count > 0) { // Set reservation property. await _reservationsAccessor.SetAsync(turnContext, updateResult.NewReservation); // Return and do not continue if there is an error. await turnContext.SendActivityAsync(updateResult.Outcome[0].Message); return(await base.ContinueDialogAsync(dc)); } // Did user ask for help or said cancel or continuing the conversation? switch (topIntent) { case ContinuePromptIntent: // User does not want to make any change. updateResult.NewReservation.NeedsChange = false; break; case NoChangeIntent: // User does not want to make any change. updateResult.NewReservation.NeedsChange = false; break; case HelpIntent: // Come back with contextual help. var helpReadOut = updateResult.NewReservation.HelpReadOut(); await turnContext.SendActivityAsync(helpReadOut); break; case CancelIntent: // Start confirmation prompt. var opts = new PromptOptions { Prompt = new Activity { Type = ActivityTypes.Message, Text = "Are you sure you want to cancel?", }, }; return(await dc.PromptAsync(ConfirmCancelPrompt, opts)); case InterruptionsIntent: default: // If we picked up new entity values, do not treat this as an interruption. if (onTurnProperties.Entities.Count != 0 || luisResults.Entities.Count > 1) { break; } // Handle interruption. var onTurnProperty = await _onTurnAccessor.GetAsync(dc.Context); return(await dc.BeginDialogAsync(InterruptionDispatcher, onTurnProperty)); } // Set reservation property based on OnTurn properties. await _reservationsAccessor.SetAsync(turnContext, updateResult.NewReservation); return(await base.ContinueDialogAsync(dc)); }
private static async Task Waterfall2_Step1(DialogContext dc, object args, SkipStepFunction next) { await dc.Context.SendActivityAsync("step1"); await dc.PromptAsync("number", "Enter a number.", new PromptOptions { RetryPromptString = "It must be a number" }); }