Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get rid of the warning "Bot Framework State API is not recommended for production environments, and may be deprecated in a future release."

I have seen a lot of articles recommending not to use the default bot state data storage because microsoft will certainly shutdown this service in march 2018.

I am currently developping a stateless bot and don't need any storage.

I have tried to create a fake one

internal class DummyDataStore : IBotDataStore<BotData>
{
    public DummyDataStore()
    {
    }

    public Task<bool> FlushAsync(IAddress key, CancellationToken cancellationToken)
    {
        return Task.FromResult(true);
    }

    public Task<BotData> LoadAsync(IAddress key, BotStoreType botStoreType, CancellationToken cancellationToken)
    {
        return Task.FromResult(new BotData());
    }

    public Task SaveAsync(IAddress key, BotStoreType botStoreType, BotData data, CancellationToken cancellationToken)
    {
        return Task.CompletedTask;
    }
}

And registered it with autofac in global.asax

        Conversation.UpdateContainer(
        builder =>
        {
            //Registration of message logger
            builder.RegisterType<BotMessageLogger>().AsImplementedInterfaces().InstancePerDependency();
            //Registration of dummy data storage
            var store = new DummyDataStore();
            builder.Register(c => store).As<IBotDataStore<BotData>>().AsSelf().SingleInstance();
        });

But it seems to mess with the context and bot doesn't respond to any context.wait() methods

I also tried this:

        Conversation.UpdateContainer(
        builder =>
        {
            var store = new InMemoryDataStore();
            builder.Register(c => store)
                               .Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
                               .AsSelf()
                               .SingleInstance();
        });

Still have the warning

Bot emulator

like image 970
B. Lec Avatar asked Jan 18 '18 16:01

B. Lec


1 Answers

Dialogs are automatically serialized into the state store. The Bot Builder SDK itself is restful, and the state store is used to enable .Wait(methodName) to resume at the methodName on the next call.

If your bot is not concerned with persisting state across server restarts, you can use the
InMemoryDataStore: https://github.com/Microsoft/BotBuilder/blob/db2b8f860a3d8f7744a378930f93c4b0baa97978/CSharp/Library/Microsoft.Bot.Builder/ConnectorEx/BotData.cs#L90

builder.RegisterModule(new AzureModule(Assembly.GetExecutingAssembly()));
var store = new InMemoryDataStore();

builder.Register(c => store)
                .Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
                .AsSelf()
                .SingleInstance();

builder.Register(c => new CachingBotDataStore(store,
                      CachingBotDataStoreConsistencyPolicy.ETagBasedConsistency))
                    .As<IBotDataStore<BotData>>()
                    .AsSelf()
                    .InstancePerLifetimeScope();

Edit: You can also register the InMemoryDataStore without using the AzureModule:

var memorystore = new InMemoryDataStore();
    builder
         .RegisterType<InMemoryDataStore>()
         .Keyed<IBotDataStore<BotData>>(typeof(ConnectorStore));

    builder.Register(c => new CachingBotDataStore(memorystore, CachingBotDataStoreConsistencyPolicy.ETagBasedConsistency))
           .As<IBotDataStore<BotData>>()
           .AsSelf()
           .SingleInstance();
like image 60
Eric Dahlvang Avatar answered Oct 17 '22 11:10

Eric Dahlvang