/// <summary> /// Handles the escalation intent through LUIS. /// </summary> /// <param name="turnContext">Turn context for the bot.</param> /// <param name="dialogContext">Dialog context for the bot.</param> /// <param name="cancellationToken">Cancellation token.</param> /// <returns>Returns true when escalated to manager; Otherwise false.</returns> private async Task <bool> HandleEscalationProtocol( ITurnContext turnContext, DialogContext dialogContext, CancellationToken cancellationToken) { var intentRecognizer = _botServices.GetRecognizer("luis"); var intents = await intentRecognizer.RecognizeAsync(turnContext, cancellationToken); var topIntent = intents.GetTopScoringIntent(); // Detect whether the user wants to escalate the conversation to a manager. // This is where we provide an escape from the regular route. if (topIntent.intent == "escalate" && topIntent.score >= 0.7) { await turnContext.SendActivityAsync( "Euhm, okay, but Al is not around to help right now. " + "You can write down your complaint and dump it in the idea box over here."); await dialogContext.CancelAllDialogsAsync(cancellationToken); return(true); } return(false); }
/// <summary> /// Creates the dialog to handle the main menu in the bot. /// </summary> /// <returns>Returns the dialog structure.</returns> private Dialog CreateMenuDialog() { var steps = new WaterfallStep[] { async(stepContext, cancellationToken) => { var data = await _conversationData.GetAsync( stepContext.Context, () => new ConversationData(), cancellationToken); var promptOptions = new PromptOptions { Prompt = MessageFactory.Text(data.ReturningCustomer ? "Is there anything else I can help you with?" : "How can I help you today?"), }; // Flag the customer so that we know he/she was here before. // Store the result in the conversation state property. data.ReturningCustomer = true; await _conversationData.SetAsync(stepContext.Context, data); return(await stepContext.PromptAsync(PromptNames.MenuItem, promptOptions)); }, async(stepContext, cancellationToken) => { var intents = await _botServices.GetRecognizer("luis").RecognizeAsync( stepContext.Context, cancellationToken); var topIntent = intents.GetTopScoringIntent().intent.ToLower(); if (topIntent == "checkin") { return(await stepContext.BeginDialogAsync(DialogNames.CheckinDialog)); } return(await stepContext.ReplaceDialogAsync(DialogNames.MainMenuDialog)); }, async(stepContext, cancellationToken) => { return(await stepContext.ReplaceDialogAsync(DialogNames.MainMenuDialog)); }, }; return(new WaterfallDialog(DialogNames.MainMenuDialog, steps)); }