How can i get all the chat history of bot and the user ?
@msgits2 @matvelloso @msft-shahins @msftgits I need all the chat history of an user and the bot in a session , how can i get the data ? Please help me out in this .
Unless your bot is actually logging this data somewhere, the bot framework won't do that for you automatically. This has privacy implications and many bots simply can't allow that in their scenarios.
How can i log the data ? @matvelloso , please help me out , i need to fix this ASAP
Node or C#?
C# @matvelloso
You will need to implement an activity logger along the lines of this sample, then decide where you will store that. Also important to let your users know that their conversation is being logged:
//Sample of how to log messages
[BotAuthentication]
public class MessagesController : ApiController
{
public sealed class WillActivityLogger : IActivityLogger
{
async Task IActivityLogger.LogAsync(IActivity activity)
{
//log here
var x = activity;
}
}
static MessagesController()
{
var builder = new ContainerBuilder();
builder.RegisterType<WillActivityLogger>().AsImplementedInterfaces().InstancePerDependency();
builder.Update(Conversation.Container);
}
Also here is an implementation of IActivityLogger using Azure table storage: https://github.com/Microsoft/BotBuilder-Azure/blob/master/CSharp/Library/Microsoft.Bot.Builder.Azure/TableLogger.cs#L60
and here is a test consuming the azure table logger and showing its usage: https://github.com/Microsoft/BotBuilder-Azure/blob/master/CSharp/Tests/Microsoft.Bot.Builder.Azure.Tests/LoggerTests.cs#L160
I'm going to close this issue for now, but feel free to open a new issue for further discussion.
what about node js.. How we can achieve same thing in node js???
@aakashvit you might consider using Node's send/receive middleware to log messages.
More specifically:
server.post('/api/messages', connector.listen()); var bot = new builder.UniversalBot(connector); // Middleware for logging bot.use({ botbuilder: function (session, next) { myMiddleware.logIncomingMessage(session, next); }, send: function (event, next) { myMiddleware.logOutgoingMessage(event, next); } })
and:
module.exports = { logIncomingMessage: function (session, next) { console.log(session.message.text); next(); }, logOutgoingMessage: function (event, next) { console.log(event.text); next(); } }
Warning CS0618 'ContainerBuilder.Update(IContainer)' is obsolete: 'Containers should generally be considered immutable. Register all of your dependencies before building/resolving. If you need to change the contents of a container, you technically should rebuild the container. This method may be removed in a future major release.'
So what should we be using?
@willportnoy do we need to update this C# sample?
ContainerBuilder.Update is marked obsolete starting version of 4.2.1 of Autofac: https://github.com/autofac/Autofac/issues/811. Bot builder is dependent on version 3.5.2: https://github.com/Microsoft/BotBuilder/blob/master/CSharp/Library/Microsoft.Bot.Builder/Microsoft.Bot.Builder.nuspec#L25 and for now this shouldn't impact our usage of Autofac in builder. In the long run, we are considering resolving this or moving to other standard dependency injection frameworks, for example asp.net dependency injection.
Maybe I'm doing something wrong, but my logger isn't trigger when i call SendToConversationAsync:
ConnectorClient connector = new ConnectorClient(new Uri(message.ServiceUrl));
await connector.Conversations.SendToConversationAsync(message);
It is called when I use await context.PostAsync(message) inside a dialog. Whats missing?
@J4S0Nc logging happens in bot builder using LogPostToBot and LogBotUser. If you want to use the connector SDK directly your code is responsible to log the messages.
thanks! working like as charm
please can you show an example of storing the conversation in custom db.. i have case, I need to store our conversation in our own sql server database. on premises. can you show me how shall I use IActivityLogger..
https://github.com/Microsoft/BotBuilder/issues/2073#issuecomment-273982401 above has some examples - you would need to write code to use your sql server.
@ashay-88 did you get it?
@msft-shahins How can i see the specific messages from bot to user and user to bot?
If I am using the web chat channel, is all the chat history persisted? Where? Must be as I can use the following link : https://webchat.botframework.com/embed/BOTNAME?t=TOKEN to view past conversations for a particular session?