Microsoft Bot Framework:例外:数据已更改 [英] Microsoft Bot Framework: Exception: The data is changed

查看:57
本文介绍了Microsoft Bot Framework:例外:数据已更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有以下对话场景的机器人:

I have a bot with the following conversation scenario:

  1. 发送文本到LUIS
  2. LUIS意向调用context.Call(...)以启动对话框
  3. 此对话框终止,将一些信息保存在userData中:

  1. Send text to LUIS
  2. LUIS intent calls context.Call(...) to launch a Dialog
  3. This dialog terminates, save some info in the userData:

private static async Task storeBotData(IDialogContext context, BotData userData) { Activity activity = (Activity)context.Activity; StateClient sc = activity.GetStateClient(); await sc.BotState.SetUserDataAsync(activity.ChannelId, activity.From.Id, userData); }

private static async Task storeBotData(IDialogContext context, BotData userData) { Activity activity = (Activity)context.Activity; StateClient sc = activity.GetStateClient(); await sc.BotState.SetUserDataAsync(activity.ChannelId, activity.From.Id, userData); }

然后调用另一个对话框,再次单击context.Call(...).

And after it call another dialog, again with context.Call(...).

然后最后一个对话框运行并终止.

Then the last dialog runs and terminates.

我的问题是,在第一个对话框的末尾(步骤3)更新用户数据时,我在Bot Framework Channel Emulator中遇到以下异常:

My problem is that when updating the user data at the end of the first dialog (step 3), I have the following exception in the Bot Framework Channel Emulator:

         `Exception: The data is changed [File of type 'text/plain']`...

这里发生了什么?我认为,当对话框终止时,它会自己调用setUserData,但是我不明白为什么我无法在代码中的任何地方更新userData ...

What happens here ? I think that when a dialog terminates, it call setUserData by itself, but I don't understand why I can't update userData anywhere in the code...

我试图捕获异常,但是什么也没捕获..但是我知道userData已更新,因为当我尝试取回它时,它已更新...

I have tried to catch the exception, but nothing is catched.. But I know that the userData is updated, because when I try to retrieve it back, it is updated...

欢迎任何帮助:)

谢谢

推荐答案

Botframework在每次活动后恢复/保存对话状态,因此,在幕后,典型流程如下所示:

Botframework restores/saves state of conversation after each act of activity, so under the covers typical flow looks like the following:

[23:15:40] <- GET 200 getUserData 
[23:15:47] <- GET 200 getConversationData 
[23:15:47] <- GET 200 getPrivateConversationData 
...
[23:16:42] <- POST 200 setConversationData 
[23:16:42] <- POST 200 setUserData 
[23:16:42] <- POST 200 setPrivateConversationData 

此处:These botData objects will fail to be stored if another instance of your bot has changed the object already.因此,在您的情况下,异常发生在对话框终止时,即框架自己调用setUserData并指出BotData已更改(通过显式调用BotState.SetUserDataAsync).我想这就是为什么您无法捕捉到异常的原因.

As it is mentioned here : These botData objects will fail to be stored if another instance of your bot has changed the object already. So in your case the exception occurs at the termination of dialog, when framework calls setUserData by himself and figures out that the BotData has been changed already (by your explicit call of BotState.SetUserDataAsync). I suppose that's why you were not able to catch the exception.

解决方案: 我使用了以下代码,并解决了该问题:

Solution: I used the following code and it fixed the issue:

private static void storeBotData(IDialogContext context, BotData userData)
{
        var data = context.UserData;
        data.SetValue("field_name", false);            
}

它起作用的原因是我们修改了UserData的对象,但允许botFramework自己提交"它,所以没有冲突

The reason it works is that we modify the object of UserData but allow botFramework to "commit" it himself, so there is no conflict

这篇关于Microsoft Bot Framework:例外:数据已更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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