Azure Bot Framework、QnA Maker API、如何在 QnA 对话中获取查询文本
Azure Bot Framework, QnA Maker API, How to get query text in QnA Dialogue
在 QnA Maker API 中,当找不到结果时,它 returns 一些默认消息或者我们可以更改该消息,但我想 运行 一个 function/method当没有结果时。下面是代码。
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");
}
查看 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)
在 QnA Maker API 中,当找不到结果时,它 returns 一些默认消息或者我们可以更改该消息,但我想 运行 一个 function/method当没有结果时。下面是代码。
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");
}
查看 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)