Search code examples
c#azurebotframeworkbotsazure-storage

How to store a message from the user in a table storage? (Microsoft Bot Framework SDK4 & C#)


Im building a bot with the Microsoft Bot Framework SDK4 at the moment. The Bot itself is based on C#. I want the message written by the user to be entered and stored in my own table storage in Azure.

I have seen this tutorial (https://learn.microsoft.com/en-us/azure/bot-service/bot-builder-howto-v4-storage?view=azure-bot-service-4.0&tabs=csharp) where the bot saves the message in a file in the Blob Storage, but I need to implement this with the table storage.

It would be super cool if someone knows or has a simple example how to do this :)


Solution

  • You could store Bot's state data in Azure table storage.

    For V3 (Deprecated) :

    var store = new TableBotDataStore(ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);
    

    Here in this sample github : https://github.com/Microsoft/BotBuilder-Azure/tree/master/CSharp/Samples/AzureTable

    Also reference : https://learn.microsoft.com/en-us/azure/bot-service/dotnet/bot-builder-dotnet-state-azure-table-storage?view=azure-bot-service-3.0

    For V4 :

    The provider for table storage was removed from the SDK. The below are the currently available ones.

    enter image description here

    However, there is an IStorage abstraction that would allow you to write your own implementation if that's something you think you need.

    Something like this :

    https://github.com/Microsoft/botbuilder-dotnet/blob/73d1d98173a82da84f3795cbdd0d473ca97bef4f/libraries/Microsoft.Bot.Builder.Azure/AzureTableStorage.cs

    The above is the last version that existed before it was removed from the SDK.