本文介绍了Bot框架412“数据是变化的".与路易斯联系时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Luis的帮助下,我有一个简单的机器人.这是非常基本的代码,我不知道在向Luis intent传递消息后为什么会出现412错误.我的代码如下:
I have a simple bot with help of Luis. It's very basic code and I don't know why I get 412 error after I past message to Luis intent. My code look like:
MessageController:
MessageController:
if (activity.Type == ActivityTypes.Message)
{
// Get any saved values
StateClient sc = activity.GetStateClient();
await sc.BotState.GetUserDataAsync(activity.ChannelId,activity.From.Id);
var haveGreeting = userData.GetProperty<bool>("HaveGreeting");
// Create text for a reply message
StringBuilder strReplyMessage = new StringBuilder();
if (haveGreeting == false)
{
strReplyMessage.Append($"Hi, how are you today?");
userData.SetProperty("HaveGreeting", true);
}
else
{
await Conversation.SendAsync(activity, () => new MeBotLuisDialog());
}
// Save BotUserData
var botaData = await sc.BotState.SetUserDataAsync(activity.ChannelId,
activity.From.Id, userData);
// Create a reply message
ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
Activity replyMessage = activity.CreateReply(strReplyMessage.ToString());
await connector.Conversations.ReplyToActivityAsync(replyMessage);
}
路易斯意图:
[LuisIntent("HowAreYou")]
public async Task HowAreYou(IDialogContext context, IAwaitable<IMessageActivity> activity, LuisResult result)
{
await context.PostAsync("Great! Thank for asking");
context.Wait(MessageReceived);
}
请帮助!
推荐答案
尝试在您的Global.asax.cs
文件中添加以下代码
Try adding the following code in your Global.asax.cs
file
var builder = new ContainerBuilder();
builder
.Register(c => new CachingBotDataStore(c.Resolve<ConnectorStore>(), CachingBotDataStoreConsistencyPolicy.LastWriteWins))
.As<IBotDataStore<BotData>>()
.AsSelf()
.InstancePerLifetimeScope();
builder.Update(Conversation.Container);
并且,请查看有关此问题的相关技术常见问题解答:
And please, review the relevant technical FAQs around this issue:
- What is an ETag? How does it relate to bot data bag storage?
- What causes "precondition failed" (412) or "conflict" (409) HTTP errors?
- How can I fix "precondition failed" (412) or "conflict" (409) HTTP errors?
这篇关于Bot框架412“数据是变化的".与路易斯联系时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!