使用中间件的聊天记录

Chat Logs using Middleware

我已经包含 中间件 以在 firebase 数据库中记录聊天。现在我可以在用户向机器人发送一些文本然后在机器人将数据发送给用户后调用一次中间件。在之前的版本bot framework v3activity payload会改变message.text 从和到 作为 user-bot/bot-user。但是现在在 bot framework v4 中,当 bot 向用户发送 message/response 时,我找不到有效载荷中任何地方发送的数据. 有没有办法保存来自 bot-user 的数据。请给我任何想法。

如果你想从一个中间件中获取从 bot 向外发送的活动,你会想像这样连接到 ITurnContext::OnSendActivities

public class MyActivityLoggingMiddleware : IMiddleware
{
    public async Task OnTurnAsync(ITurnContext turnContext, NextDelegate next, CancellationToken cancellationToken = default(CancellationToken))
    {
        // log incoming activity from turnContext.Activity here

        // Hook the turn context's OnSendActivities
        turnContext.OnSendActivities(HandleSendActivities);

        await next(cancellationToken);
    }

    private async Task<ResourceResponse[]> HandleSendActivities(ITurnContext turnContext, List<Activity> activities, Func<Task<ResourceResponse[]>> next)
    {
        // log activities being sent here

        return await next();
    }
}