问题描述
我正在使用Microsoft的Bot Framework制作机器人,我注意到当我进行更改并将其部署到Microsoft Teams时,它使用相同的对话状态,因此我必须编写"/deleteprofile"以清除状态./p>
我想清除代码中的状态,但不知道执行此操作的好方法.我不确定要使用哪个文件和哪些代码来清除对话状态.
作为参考,我目前正在使用C#.
有不同的方法可以完成此操作,具体取决于您希望从何处执行此操作.
一种方法是简单地从对话框中调用context.EndConversation("Conversation Ended");
.
另一个比较复杂,但是它将完成相同的操作,这里是您可以调整以适合您的需要的实现:
public static async Task AbortConversation(Activity message)
{
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(); //<-- could clear userdata as well
botData.ConversationData.Clear();
botData.PrivateConversationData.Clear();
await botData.FlushAsync(token);
var botToUser = scope.Resolve<IBotToUser>();
await botToUser.PostAsync(message.CreateReply("Conversation aborted."));
}
}
I am making a bot using Microsoft's Bot Framework, and I've noticed that when I make changes and deploy to Microsoft Teams, it uses the same conversation state and I have to write "/deleteprofile" to clear the state.
I want to clear the state within my code, but don't know a good way to do this. I am not sure which file and what code to use to clear the conversation state.
For reference, I am currently using C#.
there are different ways to accomplish this depending on where you would like to do this from.
one way would be to simply call context.EndConversation("Conversation Ended");
from a dialog.
The other is a bit more complicated but it will accomplish the same thing here is an implementation you can tweak to suit your needs:
public static async Task AbortConversation(Activity message)
{
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(); //<-- could clear userdata as well
botData.ConversationData.Clear();
botData.PrivateConversationData.Clear();
await botData.FlushAsync(token);
var botToUser = scope.Resolve<IBotToUser>();
await botToUser.PostAsync(message.CreateReply("Conversation aborted."));
}
}
这篇关于Microsoft Bot Framework-清晰的对话状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!