I setup a bot that have a normal stack of dialog with each dialog storing some state data in Cosmos DB in Azure. When a dialog end, I use the OnEndDialogAsync to delete the data specific to that dialog.
My question is, how do I detect when the entire conversation end so that I can delete the whole thing? Or does conversation never end?
My current code that delete each dialog data on end:
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);
}
The code to delete the entire thing would be:
await Dependencies.StateAccessor.SetAsync(context, null);