Botframework-sdk: How can i get all the chat history of bot and the user ?

Created on 20 Jan 2017  路  34Comments  路  Source: microsoft/botframework-sdk

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

Most helpful comment

https://github.com/Manacola/msbotframework-mongo-middlelayer i created video also to demonstrate process. you can find code and video link in github page

All 34 comments

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

}

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?

@msft-shahins I already stored data using TableBotDataStore class of Microsoft.Bot.Builder.Azure in Azure table storage but i want to retrived that and diplay when user back again in his chat

when i open chat again then Post method of MessagesController again called and then it goes into HandleSystemMessage() method....then it get ActivityTypes.ConversationUpdate as ActivityType and it's execution finished....my questions is how i get data from Azure table storage....

@msft-shahins I understand that Implementing the causes triggers the logging. What I am looking for is a way to conditionally log the Message Received from the User not the bot. There are certain question that the bot will ask the user that we do not want to log.

I tried injectint IBotData into my implementation of IActivityLogger but I noticed that on a message received, (from user) the BotData.ConversationData is null. The reason I need BotaData.ConversationData was to set a flag on the last question sent to not log its next response.

Is there a better way to do this? I think what I have feels clunky

I have mine connected to the Twilio channel which keeps a log of all sms to my bot.

https://github.com/Manacola/msbotframework-mongo-middlelayer i created video also to demonstrate process. you can find code and video link in github page

I dont see any videos on your page aakashkag.

@yojimbot find video in above link

Thanks the video is good but Im sorry to say the audio is really bad. Can you dub or at least subtitle?

Thanks for feedback. But I don't have enough time to to this.. you can read description and run my code. Fyi video was just bonus to quick understand

I was able to log chat bot conversations to MongoDB. If you want to see how I did it, visit here. I'm new to the open source community so if you found my work helpful, please let me know :sweat_smile: !

@matvelloso @willportnoy
Can you please tell me how to access this activity logger later to display a previous prompt to the user?

@matvelloso I tried the code but nothing is displayed in console. Can you give some more information?

Hi @vinayak99999

This is a closed issue. Please direct your question to Stack Overflow with the code you are using, and someone from the Bot Framework Support team will help you out asap.

how about in python? everyone

Was this page helpful?
0 / 5 - 0 ratings