public async Task OnTurn(ITurnContext turnContext) { try { Dictionary <string, object> state = null; DialogContext dc = null; switch (turnContext.Activity.Type) { case ActivityTypes.Message: if (turnContext.Activity.Text == "signout") { var botframeworkAdapter = turnContext.Adapter as BotFrameworkAdapter; await botframeworkAdapter.SignOutUser(turnContext, _connectionSettingName); await turnContext.SendActivity("You are now signed out."); } else { state = ConversationState <Dictionary <string, object> > .Get(turnContext); dc = _dialogs.CreateContext(turnContext, state); await dc.Continue(); // Check to see if anyone replied. If not then start dialog if (!turnContext.Responded) { await dc.Begin("displayToken"); } } break; case ActivityTypes.Event: case ActivityTypes.Invoke: // Create dialog context and continue executing the "current" dialog, if any. // This is important for OAuthCards because tokens can be received via TokenResponse events state = ConversationState <Dictionary <string, object> > .Get(turnContext); dc = _dialogs.CreateContext(turnContext, state); await dc.Continue(); break; } } catch (Exception e) { await turnContext.SendActivity($"Exception: {e.Message}"); } }
public async Task WaterfallPrompt() { var activities = TranscriptUtilities.GetFromTestContext(TestContext); var convState = new ConversationState(new MemoryStorage()); var testProperty = convState.CreateProperty <Dictionary <string, object> >("test", () => new Dictionary <string, object>()); TestAdapter adapter = new TestAdapter() .Use(convState); await new TestFlow(adapter, async(turnContext) => { if (turnContext.Activity.Type == ActivityTypes.Message) { var state = await testProperty.GetAsync(turnContext); var dialogs = new DialogSet(); dialogs.Add("test-waterfall", Create_Waterfall2()); dialogs.Add("number", new NumberPrompt <int>(Culture.English)); var dc = dialogs.CreateContext(turnContext, state); await dc.ContinueAsync(); if (!turnContext.Responded) { await dc.BeginAsync("test-waterfall"); } } }) .Test(activities) .StartTestAsync(); }
public async Task OnTurn(ITurnContext context) { // This bot is only handling Messages if (context.Activity.Type == ActivityTypes.Message) { // Get the conversation state from the turn context var state = context.GetConversationState <Dictionary <string, object> >(); var dc = _dialogs.CreateContext(context, state); // Bump the turn count. // state.TurnCount++; // Echo back to the user whatever they typed. // await context.SendActivity($"Hello World"); await dc.Continue(); if (!context.Responded) { await dc.Begin("RootDialog"); } } else { await HandleSystemMessageAsync(context); } }
public async Task OnTurn(ITurnContext context) { if (context.Activity.Type == ActivityTypes.ConversationUpdate && context.Activity.MembersAdded.FirstOrDefault()?.Id == context.Activity.Recipient.Id) { await context.SendActivity(GreetingMessage); } else if (context.Activity.Type == ActivityTypes.Message) { var state = context.GetConversationState <Dictionary <string, object> >(); var dialogContext = _dialogs.CreateContext(context, state); if (!context.Responded) { await dialogContext.Continue(); if (!context.Responded) { var luisResult = context.Services.Get <RecognizerResult>(LuisRecognizerMiddleware.LuisRecognizerResultKey); var(intent, score) = luisResult.GetTopScoringIntent(); var intentResult = score > LuisIntentTreshold ? intent : DefaultIntent; await dialogContext.Begin(intent, luisResult.Properties); } } } }
public async Task OnTurn(ITurnContext turnContext) { try { switch (turnContext.Activity.Type) { case ActivityTypes.Message: var state = ConversationState <Dictionary <string, object> > .Get(turnContext); var dc = _dialogs.CreateContext(turnContext, state); await dc.Continue(); if (!turnContext.Responded) { await dc.Begin("waterfall"); } break; case ActivityTypes.ConversationUpdate: foreach (var newMember in turnContext.Activity.MembersAdded) { if (newMember.Id != turnContext.Activity.Recipient.Id) { await turnContext.SendActivity("Hello and welcome to the waterfall and prompt bot."); } } break; } } catch (Exception e) { await turnContext.SendActivity($"Exception: {e.Message}"); } }
public async Task NumberPrompt() { TestAdapter adapter = new TestAdapter() .Use(new ConversationState <Dictionary <string, object> >(new MemoryStorage())); await new TestFlow(adapter, async(turnContext) => { var dialogs = new DialogSet(); dialogs.Add("test-prompt", new NumberPrompt <int>(Culture.English)); var state = ConversationState <Dictionary <string, object> > .Get(turnContext); var dc = dialogs.CreateContext(turnContext, state); await dc.Continue(); var dialogResult = dc.DialogResult; if (!dialogResult.Active) { if (dialogResult.Result != null) { var numberResult = (NumberResult <int>)dialogResult.Result; await turnContext.SendActivity($"Bot received the number '{numberResult.Value}'."); } else { await dc.Prompt("test-prompt", "Enter a number."); } } }) .Send("hello") .AssertReply("Enter a number.") .Send("42") .AssertReply("Bot received the number '42'.") .StartTest(); }
public async Task WaterfallNested() { var activities = TranscriptUtilities.GetFromTestContext(TestContext); var convState = new ConversationState(new MemoryStorage()); var testProperty = convState.CreateProperty <Dictionary <string, object> >("test"); var adapter = new TestAdapter() .Use(convState); await new TestFlow(adapter, async(turnContext, cancellationToken) => { if (turnContext.Activity.Type == ActivityTypes.Message) { var state = await testProperty.GetAsync(turnContext, () => new Dictionary <string, object>()); var dialogs = new DialogSet(); dialogs.Add("test-waterfall-a", Create_Waterfall3()); dialogs.Add("test-waterfall-b", Create_Waterfall4()); dialogs.Add("test-waterfall-c", Create_Waterfall5()); var dc = dialogs.CreateContext(turnContext, state); await dc.ContinueAsync(); if (!turnContext.Responded) { await dc.BeginAsync("test-waterfall-a"); } } }) .Test(activities) .StartTestAsync(); }
public async Task OnTurn(ITurnContext context) { // This bot is only handling Messages if (context.Activity.Type == ActivityTypes.Message) { var state = context.GetConversationState <DnDState>(); var dialogContext = _dialogs.CreateContext(context, state); await dialogContext.Continue(); // Additional logic can be added to enter each dialog depending on the message received string activityText = context.Activity.Text.ToLowerInvariant(); if (!context.Responded) { if (activityText.Contains("recom") || activityText.Contains("class") || activityText.Contains("race") || activityText.Contains("char") || activityText.Contains("yes") || activityText.Contains("sure")) { await dialogContext.Begin("characterBuilder"); } else { await context.SendActivity($"Hello! Do you want me to suggest a character to play in D&D 5e?"); } } } }
public async Task OnTurn(ITurnContext context) { var state = context.GetConversationState <Dictionary <string, object> >(); var dialogCon = dialogs.CreateContext(context, state); switch (context.Activity.Type) { case ActivityTypes.ConversationUpdate: foreach (var newMember in context.Activity.MembersAdded) { if (newMember.Id != context.Activity.Recipient.Id) { await dialogCon.Begin("introDialog"); } } break; case ActivityTypes.Message: await dialogCon.Continue(); if (!context.Responded) { await dialogCon.Begin("mainDialog"); } break; } }
public async Task WaterfallNested() { TestAdapter adapter = new TestAdapter() .Use(new ConversationState <Dictionary <string, object> >(new MemoryStorage())); await new TestFlow(adapter, async(turnContext) => { var dialogs = new DialogSet(); dialogs.Add("test-waterfall-a", Create_Waterfall3()); dialogs.Add("test-waterfall-b", Create_Waterfall4()); dialogs.Add("test-waterfall-c", Create_Waterfall5()); var state = ConversationState <Dictionary <string, object> > .Get(turnContext); var dc = dialogs.CreateContext(turnContext, state); await dc.Continue(); if (!turnContext.Responded) { await dc.Begin("test-waterfall-a"); } }) .Send("hello") .AssertReply("step1") .AssertReply("step1.1") .Send("hello") .AssertReply("step1.2") .Send("hello") .AssertReply("step2") .AssertReply("step2.1") .Send("hello") .AssertReply("step2.2") .StartTest(); }
public async Task OnTurn(ITurnContext context) { if (context.Activity.Type == ActivityTypes.Message) { // The type parameter PropertyBag inherits from // Dictionary<string,object> var state = ConversationState <Dictionary <string, object> > .Get(context); var dc = dialogs.CreateContext(context, state); await dc.Continue(); // Additional logic can be added to enter each dialog depending on the message received string activityText = context.Activity.Text.ToLowerInvariant(); if (!context.Responded) { if (activityText.Contains("recommend") || activityText.Contains("movie")) { await dc.Begin("movieRecommendation"); } else { await context.SendActivity($"You said '{context.Activity.Text}'; maybe you could ask me to recommend you movie?"); } } } }
public async Task WaterfallNested() { var activities = TranscriptUtilities.GetFromTestContext(TestContext); TestAdapter adapter = new TestAdapter() .Use(new ConversationState <Dictionary <string, object> >(new MemoryStorage())); await new TestFlow(adapter, async(turnContext) => { var dialogs = new DialogSet(); dialogs.Add("test-waterfall-a", Create_Waterfall3()); dialogs.Add("test-waterfall-b", Create_Waterfall4()); dialogs.Add("test-waterfall-c", Create_Waterfall5()); var state = ConversationState <Dictionary <string, object> > .Get(turnContext); var dc = dialogs.CreateContext(turnContext, state); await dc.Continue(); if (!turnContext.Responded) { await dc.Begin("test-waterfall-a"); } }) .Test(activities) .StartTestAsync(); }
public async Task OnTurn(ITurnContext context) { Dictionary <string, object> state = ConversationState <Dictionary <string, object> > .Get(context); DialogContext dc = dialogos.CreateContext(context, state); await dc.Continue(); if (context.Activity.Type == ActivityTypes.Message) { RecognizerResult resultado = context.Services.Get <RecognizerResult>(LuisRecognizerMiddleware.LuisRecognizerResultKey); var intencaoMaisPontuada = resultado?.GetTopScoringIntent(); if (!context.Responded) { IDictionary <string, object> argumentos = new Dictionary <string, object>(); if (this.ObterEntidade <string>(resultado, "Cidade") != null) { argumentos.Add("Cidade", this.ObterEntidade <string>(resultado, "Cidade")); } if (this.ObterEntidade <string>(resultado, "Tamanho") != null) { argumentos.Add("Tamanho", this.ObterEntidade <string>(resultado, "Tamanho")); } if (this.ObterEntidade <string>(resultado, "Sabor") != null) { argumentos.Add("Sabor", this.ObterEntidade <string>(resultado, "Sabor")); } switch ((intencaoMaisPontuada != null) ? intencaoMaisPontuada.Value.intent : null) { case "None": await context.SendActivity("Não entendi."); break; case "PedirPizza": await dc.Begin("pedirPizza", argumentos); break; case "PrevisaoTempo": await dc.Begin("previsaoTempo", argumentos); break; case "MarcarConsulta": await dc.Begin("marcarConsulta"); break; } } } }
private static async Task createAndBeginDialogs(ITurnContext context, DialogSet dialogs) { var dialogContext = dialogs.CreateContext(context, context.GetConversationState <EchoState>()); await dialogContext.Continue(); if (!context.Responded) { await dialogContext.Begin("firstRun"); } }
public async Task OnTurn(ITurnContext context) { var state = context.GetConversationState <ReservationData>(); var dialogContext = _dialogs.CreateContext(context, state); await dialogContext.Continue(); // This bot is only handling Messages if (context.Activity.Type == ActivityTypes.Message) { // Get the conversation state from the turn context // var state = context.GetConversationState<EchoState>(); // Bump the turn count. // state.TurnCount++; // Echo back to the user whatever they typed. // await context.SendActivity($"Turn {state.TurnCount}: You sent '{context.Activity.Text}'"); if (!context.Responded) { var result = context.Services.Get <RecognizerResult>(LuisRecognizerMiddleware.LuisRecognizerResultKey); var topIntent = result?.GetTopScoringIntent(); switch (topIntent != null ? topIntent.Value.intent : null) { case "TodaysSpecialty": // await context.SendActivity($"For today we have the following options: {string.Join(", ", BotConstants.Specialties)}"); await TodaysSpecialtiesHandler(context); break; case "ReserveTable": var amountPeople = result.Entities["AmountPeople"] != null ? (string)result.Entities["AmountPeople"]?.First : null; var time = GetTimeValueFromResult(result); ReservationHandler(dialogContext, amountPeople, time); break; case "GetDiscounts": await GetDiscountsHandler(context); break; default: await context.SendActivity("Sorry, I didn't understand that."); break; } } } else if (context.Activity.Type == ActivityTypes.ConversationUpdate && context.Activity.MembersAdded.FirstOrDefault()?.Id == context.Activity.Recipient.Id) { var msg = "Hi! I'm a restaurant assistant bot. I can help you with your reservation."; await context.SendActivity(msg, _ttsService.GenerateSsml(msg, BotConstants.EnglishLanguage)); } }
public async Task OnTurn(ITurnContext context) { var state = context.GetConversationState <Dictionary <string, object> >(); var dialogCtx = dialogs.CreateContext(context, state); switch (context.Activity.Type) { case ActivityTypes.ConversationUpdate: foreach (var newMember in context.Activity.MembersAdded) { if (newMember.Id != context.Activity.Recipient.Id) { await context.SendActivity("Bot says hello"); var quickReplies = MessageFactory.SuggestedActions(new CardAction[] { new CardAction(title: "Yeah!", type: ActionTypes.ImBack, value: "Yes"), new CardAction(title: "Nope!", type: ActionTypes.ImBack, value: "No") }, text: "Do you want to see what I can do?"); Thread.Sleep(1500); await context.SendActivity(quickReplies); } } break; case ActivityTypes.Message: await dialogCtx.Continue(); switch (context.Activity.Text) { case "Yes": await dialogCtx.Begin("initial"); break; case "No": await dialogCtx.Context.SendActivity("Ok, your loss mate!"); break; default: if (!dialogCtx.Context.Responded) { var convo = ConversationState <Dictionary <string, object> > .Get(dialogCtx.Context); await dialogCtx.Context.SendActivity($"I'm ignoring you {convo["Name"]}..."); } break; } break; default: break; } }
public async Task NumberPromptValidator() { TestAdapter adapter = new TestAdapter() .Use(new ConversationState <Dictionary <string, object> >(new MemoryStorage())); PromptValidator <NumberResult <int> > validator = async(ctx, result) => { if (result.Value < 0) { result.Status = PromptStatus.TooSmall; } if (result.Value > 100) { result.Status = PromptStatus.TooBig; } await Task.CompletedTask; }; await new TestFlow(adapter, async(turnContext) => { var dialogs = new DialogSet(); dialogs.Add("test-prompt", new NumberPrompt <int>(Culture.English, validator)); var state = ConversationState <Dictionary <string, object> > .Get(turnContext); var dc = dialogs.CreateContext(turnContext, state); await dc.Continue(); var dialogResult = dc.DialogResult; if (!dialogResult.Active) { if (dialogResult.Result != null) { var numberResult = (NumberResult <int>)dialogResult.Result; await turnContext.SendActivity($"Bot received the number '{numberResult.Value}'."); } else { await dc.Prompt("test-prompt", "Enter a number.", new PromptOptions { RetryPromptString = "You must enter a positive number less than 100." }); } } }) .Send("hello") .AssertReply("Enter a number.") .Send("150") .AssertReply("You must enter a positive number less than 100.") .Send("64") .AssertReply("Bot received the number '64'.") .StartTest(); }
public async Task BasicChoicePrompt() { TestAdapter adapter = new TestAdapter() .Use(new ConversationState <Dictionary <string, object> >(new MemoryStorage())); await new TestFlow(adapter, async(turnContext) => { var dialogs = new DialogSet(); dialogs.Add("test-prompt", new ChoicePrompt(Culture.English) { Style = ListStyle.Inline }); var state = ConversationState <Dictionary <string, object> > .Get(turnContext); var dc = dialogs.CreateContext(turnContext, state); await dc.Continue(); var dialogResult = dc.DialogResult; if (!dialogResult.Active) { if (dialogResult.Result != null) { var choiceResult = (ChoiceResult)dialogResult.Result; await turnContext.SendActivity($"Bot received the choice '{choiceResult.Value.Value}'."); } else { var promptOptions = new ChoicePromptOptions { Choices = new List <Choice> { new Choice { Value = "red" }, new Choice { Value = "green" }, new Choice { Value = "blue" }, } }; await dc.Prompt("test-prompt", "favorite color?", promptOptions); } } }) .Send("hello") .AssertReply("favorite color? (1) red, (2) green, or (3) blue") .Send("green") .AssertReply("Bot received the choice 'green'.") .StartTest(); }
public async Task OnTurn(ITurnContext context) { var state = context.GetConversationState <Dictionary <string, object> >(); var dialogCtx = _dialogs.CreateContext(context, state); if (context.Activity.Type == ActivityTypes.ConversationUpdate) { var newUserName = context.Activity.MembersAdded.FirstOrDefault()?.Name; if (!string.Equals("Bot", newUserName)) { //await dialogCtx.Begin("addUserInfo"); } } if (context.Activity.Type == ActivityTypes.Message) { await dialogCtx.Continue(); var message = context.Activity.Text.Trim(); var indexOfSpace = message.IndexOf(" ", StringComparison.Ordinal); var command = indexOfSpace != -1 ? message.Substring(0, indexOfSpace).ToLower() : message.ToLower(); switch (command) { case "tobase64": context.Activity.Text = indexOfSpace >= 0 ? context.Activity.Text.Substring(indexOfSpace + 1, message.Length - indexOfSpace - 1) : String.Empty; await dialogCtx.Begin("tobase64"); break; case "frombase64": context.Activity.Text = indexOfSpace >= 0 ? context.Activity.Text.Substring(indexOfSpace + 1, message.Length - indexOfSpace - 1) : String.Empty; await dialogCtx.Begin("frombase64"); break; case "cards": context.Activity.Text = indexOfSpace >= 0 ? context.Activity.Text.Substring(indexOfSpace + 1, message.Length - indexOfSpace - 1) : String.Empty; await dialogCtx.Begin("cards"); break; } } }
/// <summary> /// </summary> /// <param name="context">Turn scoped context containing all the data needed /// for processing this conversation turn. </param> public async Task OnTurn(ITurnContext context) { messageSent = false; if (context.Activity.Type == ActivityTypes.Message) { // The type parameter PropertyBag inherits from // Dictionary<string,object> //var dialogs = new DialogSet(); var state = ConversationState <Dictionary <string, object> > .Get(context); //var state2 = ConversationState<Dictionary<string, object>>.Get(context); var dc = dialogsT.CreateContext(context, state); var dcS = dialogSas.CreateContext(context, state); await dc.Continue(); await dcS.Continue(); // Additional logic can be added to enter each dialog depending on the message received if (!context.Responded) { var stuff = context.Activity.Text.ToLowerInvariant(); if (stuff.Contains("reserve table")) { await dc.Begin("reserveTable"); } else if (stuff.Contains("party")) { try { await dcS.Begin("sassyText"); } catch { await context.SendActivity("Sorry, had trouble in sassyText"); } } else { await context.SendActivity($"You said '{context.Activity.Text}'"); } } } //else //{ // if (!messageSent) // await context.SendActivity("Hello! Type 'reserve table' to begin your reservation."); // messageSent = true; //} }
private (UserInfo, DialogContext) CreateContext(ITurnContext context) { var dialogs = new DialogSet(); dialogs.AddCatalogDialog(dialogFactory); dialogs.AddCatalogFilterDialog(dialogFactory); var userState = context.GetUserState <UserInfo>(); var state = context.GetConversationState <eShopBotState>(); var dialogCtx = dialogs.CreateContext(context, state); return(userState, dialogCtx); }
public async Task TextPromptValidator() { TestAdapter adapter = new TestAdapter() .Use(new ConversationState <Dictionary <string, object> >(new MemoryStorage())); PromptValidator <TextResult> validator = async(ctx, result) => { if (result.Value.Length <= 3) { result.Status = PromptStatus.TooSmall; } await Task.CompletedTask; }; await new TestFlow(adapter, async(turnContext) => { var dialogs = new DialogSet(); dialogs.Add("test-prompt", new TextPrompt(validator)); var state = ConversationState <Dictionary <string, object> > .Get(turnContext); var dc = dialogs.CreateContext(turnContext, state); await dc.Continue(); var dialogResult = dc.DialogResult; if (!dialogResult.Active) { if (dialogResult.Result != null) { var textResult = (TextResult)dialogResult.Result; await turnContext.SendActivity($"Bot received the text '{textResult.Value}'."); } else { await dc.Prompt("test-prompt", "Enter some text.", new PromptOptions { RetryPromptString = "Make sure the text is greater than three characters." }); } } }) .Send("hello") .AssertReply("Enter some text.") .Send("hi") .AssertReply("Make sure the text is greater than three characters.") .Send("hello") .AssertReply("Bot received the text 'hello'.") .StartTest(); }
public async Task OnTurn(ITurnContext context) { if (context.Activity.Type == ActivityTypes.ConversationUpdate && context.Activity.MembersAdded.FirstOrDefault()?.Id == context.Activity.Recipient.Id) { await context.SendActivity(_greetingMessage); } else if (context.Activity.Type == ActivityTypes.Message) { var userState = context.GetUserState <UserState>(); if (userState.EpisodeInquiries == null) { userState.EpisodeInquiries = new List <EpisodeInquiry>(); } var state = context.GetConversationState <Dictionary <string, object> >(); var dialogContext = dialogs.CreateContext(context, state); var utterance = context.Activity.Text.ToLowerInvariant(); if (utterance == "cancel") { if (dialogContext.ActiveDialog != null) { await context.SendActivity("Ok... Cancelled"); dialogContext.EndAll(); } else { await context.SendActivity("Nothing to cancel."); } } if (!context.Responded) { await dialogContext.Continue(); if (!context.Responded) { var luisResult = context.Services.Get <RecognizerResult>(LuisRecognizerMiddleware.LuisRecognizerResultKey); var(intent, score) = luisResult.GetTopScoringIntent(); var intentResult = score > LUIS_INTENT_THRESHOLD ? intent : "None"; await dialogContext.Begin(intent, new Dictionary <string, object> { { "LuisResult", luisResult } }); } } } }
public async Task OnTurn(ITurnContext turnContext) { if (turnContext.Activity.Type == ActivityTypes.Message) { var state = ConversationState <Dictionary <string, object> > .Get(turnContext); var dc = dialogs.CreateContext(turnContext, state); await dc.Continue(); if (!turnContext.Responded) { await dc.Begin("orderCoffee"); } } }
public async Task OnTurn(ITurnContext context) { var state = context.GetConversationState <Dictionary <string, object> >(); var dialogContext = dialogs.CreateContext(context, state); if (context.Activity.Type == ActivityTypes.Message) { await dialogContext.Continue(); if (!context.Responded) { await dialogContext.Begin("cardSelector"); } } }
public async Task OnTurn(ITurnContext context) { Dictionary <string, object> state = ConversationState <Dictionary <string, object> > .Get(context); DialogContext dc = dialogos.CreateContext(context, state); await dc.Continue(); if (context.Activity.Type == ActivityTypes.Message) { if (!context.Responded) { await dc.Begin("PedirPizaa"); } } }
public async Task OnTurn(ITurnContext turnContext) { if (turnContext.Activity.Type == ActivityTypes.Message) { var state = turnContext.GetConversationState <Dictionary <string, object> >(); var dialogCtx = dialogs.CreateContext(turnContext, state); await dialogCtx.Continue(); if (!turnContext.Responded) { await dialogCtx.Begin("mainDialog"); } } }
/// <summary> /// Main bot OnTurn Implementation /// </summary> /// <param name="context">Turn scoped context containing all the data needed for processing this conversation turn. </param> public async Task OnTurn(ITurnContext context) { if (context.Activity.Type == ActivityTypes.ConversationUpdate && context.Activity.MembersAdded.FirstOrDefault()?.Id == context.Activity.Recipient.Id) { await context.SendActivity("Hi! Welcome to the Mcbeev Commerce Bot."); await context.SendActivity("How can we help you today?\n\nWould you like to **Place a new Order**, **Check your Order History** or **Find an Order Tracking Number**? Or is there something else we can help with?"); } else if (context.Activity.Type == ActivityTypes.Message) { var userState = context.GetUserState <UserState>(); var state = context.GetConversationState <Dictionary <string, object> >(); var dialogContext = dialogs.CreateContext(context, state); var utterance = context.Activity.Text.ToLowerInvariant(); if (utterance == "cancel") { if (dialogContext.ActiveDialog != null) { await context.SendActivity("Ok... Cancelled"); dialogContext.EndAll(); } else { await context.SendActivity("Nothing to cancel."); } } if (!context.Responded) { var dialogArgs = new Dictionary <string, object>(); await dialogContext.Continue(); if (!context.Responded) { var luisResult = context.Services.Get <RecognizerResult>(LuisRecognizerMiddleware.LuisRecognizerResultKey); var(intent, score) = luisResult.GetTopScoringIntent(); var intentResult = score > LUIS_INTENT_THRESHOLD ? intent : "None"; dialogArgs.Add("LuisResult", luisResult); await dialogContext.Begin(intent, dialogArgs); } } } }
public async Task WaterfallPrompt() { TestAdapter adapter = new TestAdapter() .Use(new ConversationState <Dictionary <string, object> >(new MemoryStorage())); await new TestFlow(adapter, async(turnContext) => { var dialogs = new DialogSet(); dialogs.Add("test-waterfall", Create_Waterfall2()); dialogs.Add("number", new NumberPrompt <int>(Culture.English)); var state = ConversationState <Dictionary <string, object> > .Get(turnContext); var dc = dialogs.CreateContext(turnContext, state); await dc.Continue(); var dialogResult = dc.DialogResult; if (!dialogResult.Active) { if (dialogResult.Result != null) { await turnContext.SendActivity((string)dialogResult.Result); } else { await dc.Begin("test-waterfall"); } } }) .Send("hello") .AssertReply("step1") .AssertReply("Enter a number.") .Send("hello again") .AssertReply("It must be a number") .Send("42") .AssertReply("Thanks for '42'") .AssertReply("step2") .AssertReply("Enter a number.") .Send("apple") .AssertReply("It must be a number") .Send("orange") .AssertReply("It must be a number") .Send("64") .AssertReply("Thanks for '64'") .AssertReply("step3") .AssertReply("All Done!") .StartTest(); }
public async Task OnTurn(ITurnContext turnContext) { var state = turnContext.GetConversationState <BotState>(); var dialogContext = dialogSet.CreateContext(turnContext, state); if (dialogContext.Context.Activity.Type == ActivityTypes.Message) { await dialogContext.Continue(); if (!dialogContext.Context.Responded) { await dialogContext.Begin(Constants.DialogSteps.MainDialog.ToString()); } } }