c# - IActivityLogger 不记录 PromptDialog.Choice 文本

标签 c# botframework chatbot

我正在使用 IActivityLogger 来记录机器人和用户之间的对话。 这里记录器正在记录所有消息,除了由 PromptDialog.Choice() 生成的文本

我已经测试了 PromptDialog 的其他方法,例如

PromptDialog.Confirm()
PromptDialog .Text()

这些正在工作,我的意思是正在记录来自这些方法的文本,只有 PromptDialog.Choice 文本没有命中 IActivityLogger。

记录器.cs

public class Logger : IActivityLogger
    {
        public async Task LogAsync(IActivity activity)
        {
            Debug.WriteLine(activity.AsMessageActivity()?.Text);
        }
    }

根对话框.cs

public async Task StartAsync(IDialogContext context)
        {
            string[] choices = new string[]{ "choice 1" , "choice 2"};
            PromptDialog.Choice(context, resumeAfterPrompt, choices, "please choose an option.");
        }

        private async Task resumeAfterPrompt(IDialogContext context, IAwaitable<object> result)
        {
            await context.PostAsync((await result).ToString());
            context.Done<object>(null);
        }

除了来自 RootDialog 的 PromptDialog.Choice() 之外,所有其他来往消息都通过 Logger 类。

最佳答案

the PromptDialog.Choice text is not hitting the IActivityLogger

我创建了一个示例并尝试重现该问题,我发现当我从 PromptDialog.Choice 选项列表中选择一个选项时它可以命中记录器。

根对话框:

[Serializable]
public class RootDialog : IDialog<object>
{
    public Task StartAsync(IDialogContext context)
    {
        context.Wait(MessageReceivedAsync);

        return Task.CompletedTask;
    }

    private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
    {

        string[] choices = new string[] { "choice 1", "choice 2" };
        PromptDialog.Choice(context, resumeAfterPrompt, choices, "please choose an option.");
    }

    private async Task resumeAfterPrompt(IDialogContext context, IAwaitable<string> result)
    {
        string choice = await result;

        await context.PostAsync($"You sent {choice}");
        //context.Done<object>(null);
    }
}

记录器:

public class DebugActivityLogger : IActivityLogger
{
    public async Task LogAsync(IActivity activity)
    {
        Debug.WriteLine(activity.AsMessageActivity()?.Text);
    }
}

模拟器测试结果:

enter image description here

VS 输出窗口:

enter image description here

此外,如果您在 Logger 中设置断点来调试和跟踪事件,您会发现 activity.AsMessageActivity()?.Text 将是 "" 当它呈现一个 HeroCard 以提示用户进行一组选择中的一个。

enter image description here

因此一个空字符串将被写入 VS 输出窗口。

enter image description here

关于c# - IActivityLogger 不记录 PromptDialog.Choice 文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50811364/

相关文章:

artificial-intelligence - 如何创建智能聊天机器人?

javascript - Rivescript:在条件响应中使用关键字触发器

c# - 使用 .NET 时如何限制文件碎片?

c# - 将控制台分成两部分以获得两个输出

azure - 由于 "scp or roles claim"错误消息,无法通过 Teams bot 将文件上传到 OneDrive

azure - 获取 botframework 中建议操作的值

c# - 有没有一种方法可以在不分配任何内存的情况下对数组进行排序?

c# - 在 C# 中使用 Javascript 变量

javascript - BotFramework V4 Nodejs 中的自适应卡(用户输入表单)在用户提交后重新提示

python - OpenAI 身份验证错误 : No API key provided for open ai api