迁移的机器人状态提供程序,但仍在调用state.botframework.com [英] Migrated bot state provider but calls to state.botframework.com are still being made

查看:69
本文介绍了迁移的机器人状态提供程序,但仍在调用state.botframework.com的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我迁移到Table Azure Provider来管理Microsoft bot框架状态.

I migrated to a Table Azure Provider for managing Microsoft bot framework state.

在遥测中,我看到对新的Table Azure Storage进行了依赖项调用,但是我仍然看到对state.botframework.com进行了很多调用,并且有些调用具有通常的随机慢响应时间.

In my telemetry, I see dependencies call being made to my new Table Azure Storage however I still see a lot of calls being made to state.botframework.com and some have the usual random slow response time.

这似乎不正常,因为我希望所有呼叫都将定向到我的新私有状态提供者:

This does not seem normal as I would have expect all calls to be directed to my new private state provider:

示例: https://state.botframework.com/v3/botstate/facebook/users/999999999999

呼叫新的私人国家提供者的示例: https://xxxxxxxxxx.table.core.windows.net:443/botdata( PartitionKey = 'facebook:private',RowKey ='XXXXXXXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXX

Example of call to new private state provider: https://xxxxxxxxxx.table.core.windows.net:443/botdata(PartitionKey='facebook:private',RowKey='XXXXXXXXXXXXXXX-XXXXXXXXXXXXXXXXXXXX

其他潜在的相关信息:

  • 该应用程序在使用Microsoft State provider之前已经存在了一段时间,然后切换到表Azure存储
  • 我不会在机器人状态下仅保留与用户对话的状态下的任何关键任务信息;我可以放开它,而不会产生重大影响.
  • 机器人使用保存在自定义SQL数据库中的恢复cookie发送通知.
  • 这是表Azure提供程序在Autofac模块中的注册方式:
  • The application was live for a while using Microsoft State provider before switching to a table azure storage
  • I do not persist any mission critical information in the bot state only the state of a dialog with a user; and I can loose that without significant impact.
  • The bot sends notification using a resumption cookie saved in a custom SQL database.
  • This is how the Table Azure Provider is registered in a Autofac Module:
protected override void Load(ContainerBuilder builder)
{
    base.Load(builder);

    //Register custom datastore
    builder
        .RegisterKeyedType<TableBotDataStore, IBotDataStore<BotData>>()
        .Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
        .WithParameter((pi, c) => pi.Name == "connectionString",
                            (pi, c) => 
        ConfigurationManager.ConnectionStrings["X"].ConnectionString)
        .SingleInstance();

    builder.RegisterAdapterChain<IBotDataStore<BotData>>
            (
                typeof(TableBotDataStore),
                typeof(CachingBotDataStore)

            )
            .InstancePerLifetimeScope();
}

  • 我有以下方法检查与运行的服务版本相比保存的状态版本.之所以引入此代码,是因为有时用户会具有一个序列化的对话框状态,该状态与使用新版本的对话框中所做的更改不兼容.
  • public static async Task CheckClientVersion(Activity activity)
    {    
        StateClient stateClient = activity.GetStateClient();
        BotData userData = stateClient.BotState.GetUserData(activity.ChannelId, activity.From.Id);
        if (userData?.GetProperty<string>("version")?.CompareTo(Assembly.GetExecutingAssembly().GetName().Version.ToString()) != 0)
        {
    
            string[] result = await stateClient.BotState.DeleteStateForUserAsync(activity.ChannelId, activity.From.Id, CancellationToken.None);
            userData = stateClient.BotState.GetUserData(activity.ChannelId, activity.From.Id);
            userData.SetProperty<string>("version", Assembly.GetExecutingAssembly().GetName().Version.ToString());
            await stateClient.BotState.SetUserDataAsync(activity.ChannelId, activity.From.Id, userData);
        }
    }
    

    推荐答案

    您的第二个代码段是Dialog还是MessagesController中的代码段?问题是您正在使用activity.GetStateClient,该总是调用默认状态客户端,而不是您自己的自定义客户端.

    Is your second Code Snippet is that from a Dialog or MessagesController? the issue is you are using activity.GetStateClient which Always calls the default state client rather than your own custom one.

    如果要在MessagesController

    public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
                {
                    if (activity.Type == ActivityTypes.Message)
                    {
    
                        var message = activity as IMessageActivity;
                        using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, message))
                        {
                            var botDataStore = scope.Resolve<IBotDataStore<BotData>>();
                            var key = Address.FromActivity(message);
    
                            var userData = await botDataStore.LoadAsync(key, BotStoreType.BotUserData, CancellationToken.None);
    
                            userData.SetProperty("key 1", "value1");
                            userData.SetProperty("key 2", "value2");
    
                            await botDataStore.SaveAsync(key, BotStoreType.BotUserData, userData, CancellationToken.None);
                            await botDataStore.FlushAsync(key, CancellationToken.None);
                        }
                        await Conversation.SendAsync(activity, () => new Dialogs.RootDialog());
                    }
                }   
    

    要回答您的后续问题:

    using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, message))
                {
                    var token = new CancellationToken();
                    var botData = scope.Resolve<IBotData>();
                    await botData.LoadAsync(token);
    
                    var stack = scope.Resolve<IDialogStack>();
                    stack.Reset();
    
                    botData.UserData.Clear(); 
                    botData.ConversationData.Clear();
                    botData.PrivateConversationData.Clear();
                    await botData.FlushAsync(token);
    
                    var botToUser = scope.Resolve<IBotToUser>();
                    await botToUser.PostAsync(message.CreateReply($"{timerMessage}  Conversation aborted."));
                }
    

    这篇关于迁移的机器人状态提供程序,但仍在调用state.botframework.com的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆