/// <summary> /// Composes a main dialog for our bot. /// </summary> /// <returns>A new main dialog.</returns> private static DialogSet ComposeMainDialog() { var dialogs = new DialogSet(); dialogs.Add(RootDialog, new WaterfallStep[] { // Duplicate the following row if your dialog will have // multiple turns. In this case, we just have one async(dc, args, next) => { // Get the state of the conversation var conversation = ConversationState <ConversationInfo> .Get(dc.Context); // If Regex picks up on anything, store it var recognizedIntents = dc.Context.Services.Get <IRecognizedIntents>(); // Based on the recognized intent, direct the conversation switch (recognizedIntents.TopIntent?.Name) { case "search": // switch to SearchDialog await dc.Begin(SearchDialog.Id); break; case "share": // respond that you're sharing the photo await RootResponses.ReplyWithShareConfirmation(dc.Context); break; case "order": // respond that you're ordering await RootResponses.ReplyWithOrderConfirmation(dc.Context); break; case "help": // show help await RootResponses.ReplyWithHelp(dc.Context); break; default: // respond that you don't understand await RootResponses.ReplyWithConfused(dc.Context); break; } } }); // Add our child dialogs (in this case just one) dialogs.Add(SearchDialog.Id, SearchDialog.Instance); return(dialogs); }
/// <summary> /// Continue the topic, method which is routed to while this topic is active /// </summary> /// <param name="context"></param> /// <returns></returns> public async Task <bool> ContinueTopic(ITurnContext context) { var conversation = ConversationState <ConversationData> .Get(context); var recognizedIntents = context.Services.Get <IRecognizedIntents>(); switch (context.Activity.Type) { case ActivityTypes.Message: switch (recognizedIntents.TopIntent?.Name) { case "search": // switch to search topic conversation.ActiveTopic = new SearchTopic(); return(await conversation.ActiveTopic.StartTopic(context)); case "share": // show that you're sharing await RootResponses.ReplyWithShareConfirmation(context); return(true); case "order": // show that you're ordering await RootResponses.ReplyWithOrderConfirmation(context); return(true); case "help": // show help await RootResponses.ReplyWithHelp(context); return(true); default: // adding app logic when Regex doesn't find an intent // respond saying we don't know await RootResponses.ReplyWithConfused(context); return(true); } } return(true); }
/// <summary> /// Continue the topic, method which is routed to while this topic is active /// </summary> /// <param name="context"></param> /// <returns></returns> public async Task <bool> ContinueTopic(ITurnContext context) { var conversation = ConversationState <ConversationData> .Get(context); var recognizedIntents = context.Services.Get <IRecognizedIntents>(); switch (context.Activity.Type) { case ActivityTypes.Message: switch (recognizedIntents.TopIntent?.Name) { case "search": // switch to search topic conversation.ActiveTopic = new SearchTopic(); return(await conversation.ActiveTopic.StartTopic(context)); case "share": // show that you're sharing await RootResponses.ReplyWithShareConfirmation(context); return(true); case "order": // show that you're ordering await RootResponses.ReplyWithOrderConfirmation(context); return(true); case "help": // show help await RootResponses.ReplyWithHelp(context); return(true); default: // adding app logic when Regex doesn't find an intent - consult LUIS var result = context.Services.Get <RecognizerResult>(LuisRecognizerMiddleware.LuisRecognizerResultKey); var topIntent = result?.GetTopScoringIntent(); switch ((topIntent != null) ? topIntent.Value.intent : null) { case null: // Add app logic when there is no result. await RootResponses.ReplyWithConfused(context); break; case "None": await RootResponses.ReplyWithConfused(context); await RootResponses.ReplyWithLuisScore(context, topIntent.Value.intent, topIntent.Value.score); break; case "Greeting": await RootResponses.ReplyWithGreeting(context); await RootResponses.ReplyWithHelp(context); await RootResponses.ReplyWithLuisScore(context, topIntent.Value.intent, topIntent.Value.score); break; case "OrderPic": await RootResponses.ReplyWithOrderConfirmation(context); await RootResponses.ReplyWithLuisScore(context, topIntent.Value.intent, topIntent.Value.score); break; case "SharePic": await RootResponses.ReplyWithShareConfirmation(context); await RootResponses.ReplyWithLuisScore(context, topIntent.Value.intent, topIntent.Value.score); break; case "SearchPics": // Check if LUIS has identified the search term that we should look for. var entity = result?.Entities; var obj = JObject.Parse(JsonConvert.SerializeObject(entity)).SelectToken("facet"); // if no entities are picked up on by LUIS, go through SearchTopic if (obj == null) { conversation.ActiveTopic = new SearchTopic(); await RootResponses.ReplyWithLuisScore(context, topIntent.Value.intent, topIntent.Value.score); } // if entities are picked up by LUIS, skip SearchTopic and process the search else { facet = obj.ToString().Replace("\"", "").Trim(']', '[', ' '); await ProceedWithSearchAsync(context, facet); await RootResponses.ReplyWithLuisScore(context, topIntent.Value.intent, topIntent.Value.score); break; } return(await conversation.ActiveTopic.StartTopic(context)); default: await RootResponses.ReplyWithConfused(context); break; } return(true); } } return(true); }
/// <summary> /// Composes a main dialog for our bot. /// </summary> /// <returns>A new main dialog.</returns> private static DialogSet ComposeMainDialog() { var dialogs = new DialogSet(); dialogs.Add(RootDialog, new WaterfallStep[] { // Duplicate the following row if your dialog will have // multiple turns. In this case, we just have one async(dc, args, next) => { // Get the state of the conversation var conversation = ConversationState <ConversationInfo> .Get(dc.Context); // If Regex picks up on anything, store it var recognizedIntents = dc.Context.Services.Get <IRecognizedIntents>(); // Based on the recognized intent, direct the conversation switch (recognizedIntents.TopIntent?.Name) { case "search": // switch to SearchDialog await dc.Begin(SearchDialog.Id); break; case "share": // respond that you're sharing the photo await RootResponses.ReplyWithShareConfirmation(dc.Context); break; case "order": // respond that you're ordering await RootResponses.ReplyWithOrderConfirmation(dc.Context); break; case "help": // show help await RootResponses.ReplyWithHelp(dc.Context); break; default: // adding app logic when Regex doesn't find an intent - consult LUIS var result = dc.Context.Services.Get <RecognizerResult>(LuisRecognizerMiddleware.LuisRecognizerResultKey); var topIntent = result?.GetTopScoringIntent(); switch ((topIntent != null) ? topIntent.Value.intent : null) { case null: // Add app logic when there is no result. await RootResponses.ReplyWithConfused(dc.Context); break; case "None": await RootResponses.ReplyWithConfused(dc.Context); await RootResponses.ReplyWithLuisScore(dc.Context, topIntent.Value.intent, topIntent.Value.score); break; case "Greeting": await RootResponses.ReplyWithGreeting(dc.Context); await RootResponses.ReplyWithHelp(dc.Context); await RootResponses.ReplyWithLuisScore(dc.Context, topIntent.Value.intent, topIntent.Value.score); break; case "OrderPic": await RootResponses.ReplyWithOrderConfirmation(dc.Context); await RootResponses.ReplyWithLuisScore(dc.Context, topIntent.Value.intent, topIntent.Value.score); break; case "SharePic": await RootResponses.ReplyWithShareConfirmation(dc.Context); await RootResponses.ReplyWithLuisScore(dc.Context, topIntent.Value.intent, topIntent.Value.score); break; case "SearchPics": // Check if LUIS has identified the search term that we should look for. var entity = result?.Entities; var obj = JObject.Parse(JsonConvert.SerializeObject(entity)).SelectToken("facet"); // if no entities are picked up on by LUIS, go through SearchDialog if (obj == null) { await dc.Begin(SearchDialog.Id); await RootResponses.ReplyWithLuisScore(dc.Context, topIntent.Value.intent, topIntent.Value.score); } // if entities are picked up by LUIS, skip SearchDialog and process the search else { var facet = obj.ToString().Replace("\"", "").Trim(']', '[', ' '); await RootResponses.ReplyWithLuisScore(dc.Context, topIntent.Value.intent, topIntent.Value.score); await SearchResponses.ReplyWithSearchConfirmation(dc.Context, facet); await StartAsync(dc.Context, facet); break; } break; default: await RootResponses.ReplyWithConfused(dc.Context); break; } break; } } }); // Add our child dialogs (in this case just one) dialogs.Add(SearchDialog.Id, SearchDialog.Instance); return(dialogs); }