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#.
endDialogAsync() ends the current dialog on the stack returning control to the parent dialog, if present, or to the turn handler. Additionally, it can be called from anywhere the dialog context is accessible. Best practice is to call it at the end of every dialog.
In the Bot Framework, every message has its unique activity identifier. Messages can be deleted using the Bot Framework's DeleteActivity method. To delete a message, pass that activity's ID to the DeleteActivityAsync method of the TurnContext class.
STATE is an acronym and stands for:S – Share your facts. T – Tell your story. A – Ask for the other's paths. T – Talk Tentatively. E – Encourage Testing.
Chatbot conversations can be stored in a SQL database that is hosted on a cloud platform. For example, if you were planning on creating a chatbot within the Microsoft Teams platform, you could use CosmosDB, a noSQL database with open APIs, to store your conversations and use PowerBI to visualize the reports.
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."));
}
}
I resolved this by overriding the DefaultWaitNextMessageAsync method and ending the conversation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With