How to register chat conversation with Bot Framework C # Bot Builder

I would like to record my bot conversations (in a text file or DB). I want to capture all the input and output of the bot, including any text created by FormFlow, Confirms, etc. I do not need graphic elements such as maps, but it would be nice to have text from them too.

It does not seem advisable to add registration reports after each input / output in my application, in particular, since I can’t say exactly what text was sent to the user FormFlow.

What is the best way to do this?

+4
source share
2 answers

( ) Middleware.

# IActivityLogger , LogAsync.

:

public class DebugActivityLogger : IActivityLogger
{
    public async Task LogAsync(IActivity activity)
    {
        Debug.WriteLine($"From:{activity.From.Id} - To:{activity.Recipient.Id} - Message:{activity.AsMessageActivity()?.Text}");
    }
}

, AutoFact - ( global.asax):

var builder = new ContainerBuilder();
builder.RegisterType<DebugActivityLogger>().AsImplementedInterfaces().InstancePerDependency();
builder.Update(Conversation.Container);

nodejs, :

const logUserConversation = (event) => { console.log('message: ' + event.text + ', user: ' + event.address.user.name);
};
// Middleware for logging
bot.use({
    receive: function (event, next) {
        logUserConversation(event);
        next();
    },
    send: function (event, next) {
        logUserConversation(event);
        next();
    }
});
+10

Source: https://habr.com/ru/post/1664736/


All Articles