【问题标题】:How to check the messages posted by the Bot in dialog for Microsoft botbuilder?如何在 Microsoft botbuilder 对话框中检查 Bot 发布的消息?
【发布时间】:2018-12-17 15:03:07
【问题描述】:

我正在使用 Microsoft botbuilder 在 .NET 中创建一个聊天机器人,并将 Web 应用程序机器人代码用作我的模板。 我找不到包含从机器人发布给 qna 制造商的用户的文本的变量。我目前正在每次机器人回答用户问题后创建另一个对话框,但我不希望机器人在发布默认消息时执行此操作。 当我调试时,我似乎无法找到 qnamaker 的答案存储在哪里。

如果有人知道答案存储在哪里以及如何访问它,这将非常有帮助,或者可能检查对话框中的最新消息。

目前我的根对话框有这个 sn-p:

await context.Forward(new BasicQnAMakerDialog(), AfterAnswerAsync, message, CancellationToken.None);

转发的方法是:

private async Task AfterAnswerAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
        {
            context.Call(new PostAnswerDialog(), AfterPost);

        }

我想检查机器人是否在 context.Call(new PostAnswerDialog(), AfterPost) 之前使用默认消息进行响应,如果它已经做了其他事情。

【问题讨论】:

  • check if the bot responds with the default message before the context.Call(new PostAnswerDialog(), AfterPost) and if it has then do something else QnAMaker Dialog 应该能够响应用户输入,你能澄清一下你的实际情况吗?你想在 PostAnswerDialog 中做什么?
  • PostAnswerDialog 只是一个回答后调查,但如果它只是用默认消息响应,我不希望它启动对话,因为那时它在 qna 制造商中找不到任何东西。我在 context.Call 之前找不到默认消息。我检查了上下文和结果参数,上下文存储了用户在字符串中键入的内容,但结果只包含将其连接到 qna 制造商的信息,而不是返回的实际字符串。

标签: c# azure botframework chatbot


【解决方案1】:

您必须自定义您的QnAMakerDialog。可通过here 获取资源以了解其工作原理。

例如,您可以覆盖在进程结束时调用的DefaultWaitNextMessageAsync 方法(无论是否匹配):

// 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(ConfigurationManager.AppSettings["QnAAuthKey"], ConfigurationManager.AppSettings["QnAKnowledgebaseId"], "No good match in FAQ.", 0.5, 1, ConfigurationManager.AppSettings["QnAEndpointHostName"])))
    {
    }

    protected override async Task DefaultWaitNextMessageAsync(IDialogContext context, IMessageActivity message, QnAMakerResults result)
    {
        if (result.Answers.Count > 0)
        {
            // DO YOUR LOGIC HERE
            await context.PostAsync("Case where you have matching results");
        }

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-20
    • 1970-01-01
    • 2017-08-20
    • 2020-01-30
    • 2017-03-24
    • 1970-01-01
    相关资源
    最近更新 更多