Hello when i prompt the user with a confirm prompt or a yes or no prompt. Luis is detecting "no" as cancel intent which cancel my whole dialog. And then i deleted "no" from the cancel intent but now "no is being detected by luis as a greeting intent. There is not even a "no" word from the greeting intent. As much as possible i do not want to disable luis because a user can cancel anytime. How can i fix this? thanks!
Here is the code.
public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken)
{
var dc = await _dialogs.CreateContextAsync(turnContext, cancellationToken);
var activity = turnContext.Activity;
var userstate = await _basicAccessors.BasicUserStateAccessor.GetAsync(turnContext, () => new BasicUserState(), cancellationToken);
var state = await _basicAccessors.BasicStateAccessor.GetAsync(turnContext, () => new BasicState(), cancellationToken);
if (turnContext.Activity.Type == ActivityTypes.Message)
{
turnContext.TurnState.Add("BasicAccessors", _basicAccessors);
string text = string.IsNullOrEmpty(turnContext.Activity.Text) ? string.Empty : turnContext.Activity.Text.ToLower();
var luisResults = await _services.LuisServices[LuisConfiguration].RecognizeAsync(dc.Context, cancellationToken);
var topScoringIntent = luisResults?.GetTopScoringIntent();
var topIntent = topScoringIntent.Value.intent;
string userName = string.Empty;
if (activity.From.Name != null)
{
userName = activity.From.Name;
}
userstate.Name = userName;
await _basicAccessors.BasicUserStateAccessor.SetAsync(turnContext, userstate);
await _basicAccessors.BasicStateAccessor.SetAsync(turnContext, state);
var interrupted = await IsTurnInterruptedAsync(dc, topIntent);
if (interrupted)
{
// Bypass the dialog.
// Save state before the next turn.
await _basicAccessors.ConversationState.SaveChangesAsync(turnContext, false, cancellationToken);
await _basicAccessors.UserState.SaveChangesAsync(turnContext, false, cancellationToken);
return;
}
// Continue the current dialog
var dialogResult = await dc.ContinueDialogAsync();
// if no one has responded,
if (!dc.Context.Responded)
{
// examine results from active dialog
switch (dialogResult.Status)
{
case DialogTurnStatus.Empty:
switch (topIntent)
{
case GreetingIntent:
await dc.BeginDialogAsync(MainDialogId);
break;
case "loan calculator":
case "loan calc":
await dc.BeginDialogAsync(MainDialogId);
break;
case NoneIntent:
default:
await dc.Context.SendActivityAsync("I didn't understand what you just said to me.");
break;
}
break;
case DialogTurnStatus.Waiting:
// The active dialog is waiting for a response from the user, so do nothing.
break;
case DialogTurnStatus.Complete:
await dc.EndDialogAsync();
break;
default:
await dc.CancelAllDialogsAsync();
break;
}
}
}
else if (activity.Type == ActivityTypes.ConversationUpdate)
{
if (activity.MembersAdded != null)
{
// Iterate over all new members added to the conversation.
foreach (var member in activity.MembersAdded)
{
// Greet anyone that was not the target (recipient) of this message.
// To learn more about Adaptive Cards, see https://aka.ms/msbot-adaptivecards for more details.
if (member.Id != activity.Recipient.Id)
{
await SendWelcomeMessageAsync(turnContext, cancellationToken);
}
}
}
}
await _basicAccessors.ConversationState.SaveChangesAsync(turnContext, false, cancellationToken);
await _basicAccessors.UserState.SaveChangesAsync(turnContext, false, cancellationToken);
}
private async Task<bool> IsTurnInterruptedAsync(DialogContext dc, string topIntent)
{
// See if there are any conversation interrupts we need to handle.
if (topIntent.Equals(CancelIntent))
{
if (dc.ActiveDialog != null)
{
await dc.CancelAllDialogsAsync();
await dc.Context.SendActivityAsync("Ok. I've canceled our last activity.");
}
else
{
await dc.Context.SendActivityAsync("I don't have anything to cancel.");
}
return true; // Handled the interrupt.
}
if (topIntent.Equals(HelpIntent))
{
await dc.Context.SendActivityAsync("Let me try to provide some help.");
await dc.Context.SendActivityAsync("I understand greetings, being asked for help, or being asked to cancel what I am doing.");
if (dc.ActiveDialog != null)
{
await dc.RepromptDialogAsync();
}
return true; // Handled the interrupt.
}