0

I am trying to create a process after selecting "None of the above" by a user.

As you know, QnA Maker replies related multiple questions list when the user input a fuzzy message. At the bottom of the list, we can see "None of the above".

I would like to create a process after the user selects "None of the above" box. I have already tried to override BasicQnAMakerDialog(), but cannot do it.

If someone knows about how to do it, please tell me.

zx485
  • 28,498
  • 28
  • 50
  • 59
Gon
  • 93
  • 1
  • 7
  • You said you tried to override the BasicQnAMakerDialog(); can you post the code for us, please? – JJ_Wailes Jul 10 '18 at 17:47
  • Thanks for your quick reply. – Gon Jul 11 '18 at 01:41
  • public class BasicQnAMakerDialog : QnAMakerDialog { public BasicQnAMakerDialog() : base(new QnAMakerService(new QnAMakerAttribute(ConfigurationManager.AppSettings["QnAAuthKey"], ConfigurationManager.AppSettings["QnAKnowledgebaseId"], "No good match in FAQ.", 0, 5, ConfigurationManager.AppSettings["QnAEndpointHostName"]))) { } protected override async Task RespondFromQnAMakerResultAsync(IDialogContext context, IMessageActivity message, QnAMakerResults result) { } } } – Gon Jul 11 '18 at 01:43
  • I am so sorry that I am not sure how to upload the cord to this site. But actual code is like this. I supposed I need to make a certain method which override BasicQnAMakerDialog(). Is it correct? – Gon Jul 11 '18 at 01:47
  • I have already tried to add like "if(message.Text.Equals("None of the above."))". But cannot do it. – Gon Jul 11 '18 at 01:51

1 Answers1

1

I would like to create a process after the user selects "None of the above" box.

You can try to override DefaultWaitNextMessageAsync method and detect if user select "None of the above" option, the following code snippet is for your reference.

protected override async Task DefaultWaitNextMessageAsync(IDialogContext context, IMessageActivity message, QnAMakerResults result)
{
    if (message.Text.Equals("None of the above."))
    {
        // your code logic

        await context.PostAsync("You selected 'None of the above.'");
    }

    await base.DefaultWaitNextMessageAsync(context, message, result);
}

Test result:

enter image description here

Update:

"What kind of thing do you want to ask?" -> user inputs "blah blah blah"

You can sent "What kind of thing do you want to ask?" to user inside DefaultWaitNextMessageAsync method, and wait for user inputs.

Complete sample code:

namespace Microsoft.Bot.Sample.QnABot
{
    [Serializable]
    public class RootDialog : IDialog<object>
    {
        public async Task StartAsync(IDialogContext context)
        {
            /* Wait until the first message is received from the conversation and call MessageReceviedAsync 
            *  to process that message. */
            context.Wait(this.MessageReceivedAsync);
        }

        private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
        {
            /* When MessageReceivedAsync is called, it's passed an IAwaitable<IMessageActivity>. To get the message,
             *  await the result. */
            var message = await result;

            context.ConversationData.SetValue<bool>("isnotdefaultmes", false);

            var qnaAuthKey = GetSetting("QnAAuthKey");
            //var qnaKBId = Utils.GetAppSetting("QnAKnowledgebaseId");
            var qnaKBId = ConfigurationManager.AppSettings["QnAKnowledgebaseId"];
            var endpointHostName = ConfigurationManager.AppSettings["QnAEndpointHostName"];

            // QnA Subscription Key and KnowledgeBase Id null verification
            if (!string.IsNullOrEmpty(qnaAuthKey) && !string.IsNullOrEmpty(qnaKBId))
            {
                // Forward to the appropriate Dialog based on whether the endpoint hostname is present
                if (string.IsNullOrEmpty(endpointHostName))
                    await context.Forward(new BasicQnAMakerPreviewDialog(), AfterAnswerAsync, message, CancellationToken.None);
                else
                    await context.Forward(new BasicQnAMakerDialog(), AfterAnswerAsync, message, CancellationToken.None);
            }
            else
            {
                await context.PostAsync("Please set QnAKnowledgebaseId, QnAAuthKey and QnAEndpointHostName (if applicable) in App Settings. Learn how to get them at https://aka.ms/qnaabssetup.");
            }

        }

        private async Task AfterAnswerAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
        {
            // wait for the next user message
            context.Wait(MessageReceivedAsync);
        }

        public static string GetSetting(string key)
        {
            //var value = Utils.GetAppSetting(key);
            var value = ConfigurationManager.AppSettings[key];

            if (String.IsNullOrEmpty(value) && key == "QnAAuthKey")
            {
                //value = Utils.GetAppSetting("QnASubscriptionKey"); // QnASubscriptionKey for backward compatibility with QnAMaker (Preview)
                value = ConfigurationManager.AppSettings["QnASubscriptionKey"];
            }
            return value;
        }
    }

    // Dialog for QnAMaker Preview service
    [Serializable]
    public class BasicQnAMakerPreviewDialog : QnAMakerDialog
    {
        // Go to https://qnamaker.ai and feed data, train & publish your QnA Knowledgebase.
        // Parameters to QnAMakerService are:
        // Required: subscriptionKey, knowledgebaseId, 
        // Optional: defaultMessage, scoreThreshold[Range 0.0 – 1.0]
        public BasicQnAMakerPreviewDialog() : base(new QnAMakerService(new QnAMakerAttribute(RootDialog.GetSetting("QnAAuthKey"), ConfigurationManager.AppSettings["QnAKnowledgebaseId"], "No good match in FAQ.", 0.5)))
        { }
    }

    // Dialog for QnAMaker GA service
    [Serializable]
    public class BasicQnAMakerDialog : QnAMakerDialog
    {
        // Go to https://qnamaker.ai and feed data, train & publish your QnA Knowledgebase.
        // Parameters to QnAMakerService are:
        // Required: qnaAuthKey, knowledgebaseId, endpointHostName
        // Optional: defaultMessage, scoreThreshold[Range 0.0 – 1.0]
        public BasicQnAMakerDialog() : base(new QnAMakerService(new QnAMakerAttribute(RootDialog.GetSetting("QnAAuthKey"), ConfigurationManager.AppSettings["QnAKnowledgebaseId"], "No good match in FAQ.", 0.5, 5, ConfigurationManager.AppSettings["QnAEndpointHostName"])))
        { }


        protected override async Task DefaultWaitNextMessageAsync(IDialogContext context, IMessageActivity message, QnAMakerResults result)
        {
            if (message.Text.Equals("None of the above."))
            {
                // your code logic
                await context.PostAsync("What kind of thing do you want to ask?");
                //await context.PostAsync("You selected 'None of the above.'");
            }

            await base.DefaultWaitNextMessageAsync(context, message, result);
        }
    }
}

Test result:

enter image description here

Fei Han
  • 26,415
  • 1
  • 30
  • 41
  • I really appreciate your answer >< I could realize it successfully! Thanks a lot! – Gon Jul 11 '18 at 03:51
  • Hi @Gon, if the reply help you solve the problem, you can mark it as accepted answer, which can also help other community members quickly find the answer and solve the similar problem. – Fei Han Jul 17 '18 at 02:51
  • Hi @Fei Han. Can I ask one more question? After the user selected "None of the above", I want the user to input comments, like "What kind of thing do you want to ask?" -> user inputs "blah blah blah". Can I add this kinds of function? – Gon Jul 17 '18 at 11:21
  • I think I cannot call other method in DefaultWaitNextMessageAsync. I wanna use context.Wait(), but cannot do it. If you know how to do it, tell me please. – Gon Jul 17 '18 at 11:24
  • And, in addition, I do not know how to accept the answer on this web site. Please tell me how to do it. Sorry for disturbing you. – Gon Jul 17 '18 at 11:25
  • Hi @Gon, you can check [this link](https://stackoverflow.com/help/someone-answers) to know how to accept an answer. – Fei Han Jul 18 '18 at 02:38
  • Hi @Fei Han. Thanks for the link. Anyway, could you answer my question posted last night? I need your help. – Gon Jul 18 '18 at 05:00
  • Thank you so much. – Gon Jul 18 '18 at 05:30