我设置了一个具有常规对话框堆栈的机器人,每个对话框在Azure的Cosmos DB中存储一些状态数据。对话框结束时,我使用OnEndDialogAsync删除特定于该对话框的数据。
我的问题是,如何检测整个对话何时结束,以便删除整个对话?还是对话永无止境?
我当前的代码,该代码最终删除了每个对话框数据:
string myString = "1.05";
// This throws exception:
double myParsedDouble = double.Parse(myString);
// This gives you more control over the conversion:
double? myResult = null;
if (double.TryParse(myString, out double _myResult))
myResult = _myResult;
if (myResult == null)
{
throw new ArgumentException("Not a valid double!");
}
删除整个内容的代码为:
protected override async Task OnEndDialogAsync(ITurnContext context, DialogInstance instance, DialogReason reason, CancellationToken cancellationToken)
{
DialogStateDictionary dictionary = await Dependencies.StateAccessor.GetAsync(context, () => null);
if (dictionary != null && dictionary.ContainsKey(DialogID) == true)
{
dictionary[DialogID] = null;
}
await Dependencies.StateAccessor.SetAsync(context, dictionary);
}
答案 0 :(得分:1)
对话“结束”的概念将针对特定频道。在网络聊天中,您可以让机器人知道您的客户端对浏览器离开页面的响应。在类似Teams之类的渠道中,对话实际上是永久的,但是您始终可以通过使漫游器像执行操作一样重置其状态来随时将对话中的任何点定义为“终点”。也许您会有一个确认提示,询问用户“这将是全部吗?”并且如果用户说“是”,则漫游器可能会说“再见”或类似的内容。
答案 1 :(得分:0)
不确定您使用的是哪个频道,建议查看endofconversation活动类型。