in 002-IntroToAzureAI/Coach/Solutions/Challenge-2.2-Building-Bots/Code/FinishedPictureBot-Part4/PictureBot/PictureBot/Topics/RootTopic.cs [64:145]
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;
}