1
votes

How can i track if LUIS intent has already been triggered ??
Channel used: Facebook

Scenario
User : Audi TT details
Bot : [car details....]
User : Thank you
Bot : Would you like us to contact you? (provide yes or no prompt)
User : [select options (yes or no)]...
Next time same user chats...or later in same conversation
User : do you have parts for Audi TT?
Bot : Yes, we have the following parts available
User : Great thanks!
Bot : Glad to help -> Bot must not provide "Would you like us to contact you?" prompt again

I'm using LUIS intent to detect if user is saying 'thank you' and then trigger the prompt. How can I track if the intent has already been triggered

[LuisIntent ("Gratitude")]  
public async Task Gratitude(IDialogContext context, IAwaitable<IMessageActivity> message, LuisResult result)  
{               
    if( intent_has_not_been_triggered_for_user)
       PromptDialog.Choice(context,
             ResumeAfterGratitude,
             new[] { "Yes", "No"},
             "Thank you. Would you like us to contact you?",
             promptStyle: PromptStyle.Keyboard, attempts: 4
           );

   else  
      await context.PostAsync("Glad to help");  
}
1

1 Answers

2
votes

You can make use of the context.UserData to store data associated with a user.

In your case, you can set the value in case the value is not present in UserData by using a key, something like GratitudeTriggered, and every time check if the key exists in the User data. You can also customize the logic as per your needs like to match a particular value, existence of the value, etc.

Sample code:

[LuisIntent("Gratitude")]
public async Task Gratitude(IDialogContext context, IAwaitable<IMessageActivity> message, LuisResult result)
{
    if (context.UserData.TryGetValue("GratitudeTriggered", out bool gratitudeTriggered))
    {
        //Triggered for the first time, store it in UserData that the Gratitude is triggered
        context.UserData.SetValue("GratitudeTriggered", "yes");

        PromptDialog.Choice(context,
              ResumeAfterGratitude,
              new[] { "Yes", "No" },
              "Thank you. Would you like us to contact you?",
              promptStyle: PromptStyle.Keyboard, attempts: 4
            );
    }
    else
        await context.PostAsync("Glad to help");
}