Azure Bot Framework,QnA Maker API,如何在QnA对话中获取查询文本

问题描述 投票:2回答:1

在QnA Maker API中,当没有找到结果时,它会返回一些默认消息,或者我们可以更改该消息,但是我想在没有结果fount时运行一个函数/方法。下面是代码。

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");
    }
c# azure botframework azure-bot-service qnamaker
1个回答
4
投票

看看GitHub上的QnaMakerDialog实现here

您将看到有几个选项,更容易覆盖Qna搜索后调用的DefaultWaitNextMessageAsync方法。

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);
    }

请注意,如果您想避免发送有关未找到Qna的消息,则应改为覆盖MessageReceivedAsync并更改块if (sendDefaultMessageAndWait)中的代码

© www.soinside.com 2019 - 2024. All rights reserved.