2

How to change default answer when QnAmaker does not have any response to display a prompt dialog.

For example:

User1: Hello
Bot : Hello there !!
User1: Do you sell cars?
Bot : No good match found !

Instead of No good match found, the bot should propose a list of services available.

Also, anytime a match is not found, the bot should again propose a list of services available.

How can this be achieve?

Norwen
  • 63
  • 6
  • 1
    It would be awesome if you could provide a [mcve]. – mjwills May 09 '18 at 12:43
  • Depends, there's a few ways to do this. It kind of depends how you've got your framework set up. For example are you using a simple azure service for the QnAmaker bot, or are you using a custom API to support the botframework etc. – JoeTomks May 09 '18 at 12:45
  • Hello @Digitalsa1nt, i'm using simple azure service. Please find below code extract./***** Code Extract ****/public class BasicQnAMakerDialog : QnAMakerDialog { public BasicQnAMakerDialog() : base(new QnAMakerService(new QnAMakerAttribute(Utils.GetAppSetting("QnASubscriptionKey"), Utils.GetAppSetting("QnAKnowledgebaseId"),"",0.30,8))) {} } – Norwen May 09 '18 at 12:47
  • Ah I see, If you're using the prebuilt one in azure, which it looks like you might be, then you will need to edit some of the code in azure around the framework. I'll see If I can find a good example shortly. – JoeTomks May 09 '18 at 12:53

2 Answers2

2

QnAMakerAttribute has a defaultMessage parameter allowing you to customize the 'no match' response text: https://github.com/Microsoft/BotBuilder-CognitiveServices/blob/7866f5a1bc970bdd0be341b9ba24c74067edf57c/CSharp/Library/QnAMaker/QnAMaker/QnAMakerService/QnAMakerAttribute.cs

public class BasicQnAMakerDialog : QnAMakerDialog 
{ 
  public BasicQnAMakerDialog() : base(
         new QnAMakerService(
                new QnAMakerAttribute(
                      Utils.GetAppSetting("QnASubscriptionKey"),
                      Utils.GetAppSetting("QnAKnowledgebaseId"),
                      "**List of services: one, two three**",
                      0.30,
                      8))) {} 
}

There is also a pull request waiting to be merged that will allow overriding sending the default message: https://github.com/Microsoft/BotBuilder-CognitiveServices/pull/87 Until then, it seems your only option is to duplicate the QnAMakerDialog in your own code base: QnAMakerDialog source

Eric Dahlvang
  • 8,252
  • 4
  • 29
  • 50
  • Hello Eric, thank you for your response and providing info on the pull request . However, having the prompt dialog would better as it would provide better ux. – Norwen May 10 '18 at 17:25
1

Because there's a few different ways to use the QnA maker alongside the botframework there's quite a few differing suggestions for the issue you have at the moment but not as many proper guidelines from Microsoft around it at this time. (At least not that I've found)

I came across this issue listed against the QnA makers git repository: found here. There are a few different suggestions, so I'll list them below from least to most effort.

Option 1: [Assumes you're creating a base dialog class that connects to the QnA maker]

public BasicQnAMakerDialog() : base(new QnAMakerService(new QnAMakerAttribute(ConfigurationManager.AppSettings["QnASubscriptionKey"], ConfigurationManager.AppSettings["QnAKnowledgebaseId"], "No good match in FAQ")))

Option 2: [Simply look out for the specific string that's returned by default and 'override' it]

protected override async Task RespondFromQnAMakerResultAsync(IDialogContext context, IMessageActivity message, QnAMakerResults result)
{
    var answer = result.Answers.First().Answer;
    Activity reply = ((Activity)context.Activity).CreateReply();
    if (reply.Text.equals("Not Match Found!))
         reply.Text = "No good match in FAQ";
    await context.PostAsync(reply);
}   

There were instances back when QnAMaker was still in it's preview that option 1 wouldn't work as expected. Option 2 is not as neat in my opinion but it's a decent work around.

As Eric has said in his answer, there is an active pull request awaiting a merge against this issue in their git repo. So eventually this will be an easier thing to deal with. Until then hopefully the above two options will help.

JoeTomks
  • 3,243
  • 1
  • 18
  • 42
  • Hello DigitalsaInt, tried option2 but bot does not seem to capture the default message when no response is found. Works only when there is a match. I'm using the facebook channel – Norwen May 10 '18 at 17:26