botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

How can i get all the chat history of bot and the user ?

Open Masssluis opened this issue 9 years ago • 34 comments

@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 .

Masssluis avatar Jan 20 '17 05:01 Masssluis

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.

matvelloso avatar Jan 20 '17 05:01 matvelloso

How can i log the data ? @matvelloso , please help me out , i need to fix this ASAP

Masssluis avatar Jan 20 '17 05:01 Masssluis

Node or C#?

matvelloso avatar Jan 20 '17 05:01 matvelloso

C# @matvelloso

Masssluis avatar Jan 20 '17 05:01 Masssluis

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);

}

matvelloso avatar Jan 20 '17 05:01 matvelloso

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

msft-shahins avatar Jan 20 '17 05:01 msft-shahins

I'm going to close this issue for now, but feel free to open a new issue for further discussion.

willportnoy avatar Jan 26 '17 02:01 willportnoy

what about node js.. How we can achieve same thing in node js???

aakashkag avatar Jan 30 '17 15:01 aakashkag

@aakashvit you might consider using Node's send/receive middleware to log messages.

willportnoy avatar Jan 31 '17 16:01 willportnoy

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(); } }

matvelloso avatar Jan 31 '17 19:01 matvelloso

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?

J4S0Nc avatar Feb 06 '17 20:02 J4S0Nc

@willportnoy do we need to update this C# sample?

matvelloso avatar Feb 06 '17 20:02 matvelloso

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.

msft-shahins avatar Feb 06 '17 20:02 msft-shahins

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 avatar Feb 07 '17 14:02 J4S0Nc

@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.

msft-shahins avatar Feb 07 '17 18:02 msft-shahins

thanks! working like as charm

aakashkag avatar Feb 14 '17 12:02 aakashkag

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..

ashay-88 avatar Mar 09 '17 11:03 ashay-88

https://github.com/Microsoft/BotBuilder/issues/2073#issuecomment-273982401 above has some examples - you would need to write code to use your sql server.

willportnoy avatar Mar 09 '17 21:03 willportnoy

@ashay-88 did you get it?

@msft-shahins How can i see the specific messages from bot to user and user to bot?

alokraj68 avatar Apr 19 '17 15:04 alokraj68

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?

am071092 avatar Jun 21 '17 03:06 am071092