Search code examples
botframeworkdirect-line-botframework

Is there a way to read all the messages which are already posted in the bot without knowing their respective Conversation IDs


I am using directline V3 for testing out a bot inside MS Teams. This is a bot showing some messages inside MS Teams. Is there a way to read all the messages which are already posted in the bot without knowing their respective Conversation IDs. How to read all the conversations from the bot show in the attached screenshot.


Solution

  • On bot side, if we want to save and retrieve all the conversation history, in C# we can implement the IActivityLogger interface, and log the data in Task LogAsync(IActivity activity) for example:

    public class ActivityLogger : IActivityLogger
    {
        public Task LogAsync(IActivity activity)
        {
            IMessageActivity msg = activity.AsMessageActivity();
            //log here
            return null;
        }
    }
    

    So if you save data in Azure SQL Database, you can refer to Saving Bot Activities in Azure SQL Database, and here are some official examples.

    Then in node.js, you can intercept and log messages using middleware:

    bot.use({
        botbuilder: function (session, next) {
            myMiddleware.logIncomingMessage(session, next);
        },
        send: function (event, next) {
            myMiddleware.logOutgoingMessage(event, next);
        }
    })