gachCoder
gachCoder

Reputation: 185

Azure Bot Framework, QnA Maker API, How to get query text in QnA Dialogue

In QnA Maker API, when no result found, it returns some default message or we can change that message, But I want to run a function/method when no result fount. Below is the code.

public QnaDialog(): base(
        new QnAMakerService(new QnAMakerAttribute(ConfigurationManager.AppSettings["QnaSubscriptionKey"], 
        ConfigurationManager.AppSettings["QnaKnowledgebaseId"], "Hmm, I wasn't able to find any relevant content. Can you try asking in a different way? or try with typing help.", 0.5)))
    {
        //this is what i want to call, this is working but **i am not able to get query text here**
        SendEmail email = new SendEmail();
        email.SendEmailtoAdmin("Query_Text", "Email ID");
    }

Upvotes: 3

Views: 582

Answers (1)

Nicolas R
Nicolas R

Reputation: 14599

Have a look to the QnaMakerDialog implementation here on GitHub.

You will see that you have several options, the easier would be to override the DefaultWaitNextMessageAsync method which is called after Qna search.

protected virtual async Task DefaultWaitNextMessageAsync(IDialogContext context, IMessageActivity message, QnAMakerResults result)
    {
        if (result.Answers.Count == 0)
        {
            // Here you have the query text in message.Text so:
            SendEmail email = new SendEmail();
            email.SendEmailtoAdmin(message.Text, "Email ID");
        }

        context.Done(true);
    }

Please note that if you want to avoid the message sent about no Qna found, you should override MessageReceivedAsync instead and change the code inside the block if (sendDefaultMessageAndWait)

Upvotes: 5

Related Questions