botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

Clear session.userData

Open suvamsh opened this issue 10 years ago • 7 comments

I'm testing my bot after deploying to FB/Skype. I'm wondering if there is a way I can clear all session data and test from scratch? I am unable to tests part of my logic since userData is persisted across the conversation.

suvamsh avatar Nov 23 '16 07:11 suvamsh

Follow up: As of now I have a command that my bot recognizes and I can clear the data using that. But I don't want to expose this to users. I would like to do it myself behind the scenes.

suvamsh avatar Nov 23 '16 07:11 suvamsh

@suvamsh If you are using nodejs, you could add this middleware:

        bot.use(botbuilder.Middleware.dialogVersion({
            version: 1.0,
            message: 'Conversation restarted by a main update',
            resetCommand: /^reset/i
        }));

That manages the versioning of a bot dialogs. If I'm not wrong (I'm not 100% sure about it) you can increase the version every time you want to clean all session data. Your bot would also understand "reset" as a command that cleans everything as well.

Please let us know whether it works or not if you try it.

palmerabollo avatar Nov 23 '16 08:11 palmerabollo

@palmerabollo that won't delete userData... @suvamsh can I ask what are you saving in userData that you want to delete? Just wondering if what your storring should really be persisted using userData...

If you want to delete userData for all of your users you'll need to create a piece of middleware similar to dialogVersion() that lets you version userData.

Stevenic avatar Nov 26 '16 05:11 Stevenic

Closing as it appears the question was answered. Please feel free to open a new issue if you'd like to discuss further. Thanks!

dandriscoll avatar Dec 21 '16 18:12 dandriscoll

thats what i did bot.dialog('/delete', (session) => { delete session.userData session.endDialog('Everything has been wiped out')

}) .triggerAction({ matches: /delete all/i, confirmPrompt: "This will wipe everything out. Are you sure?" });

slidenerd avatar Jan 12 '17 09:01 slidenerd

@palmerabollo Your method worked for me. Big thanks

iganbold avatar May 14 '17 05:05 iganbold

@slidenerd It's wrong, read the documentation. https://docs.microsoft.com/en-us/bot-framework/nodejs/bot-builder-nodejs-state#delete-data right way is

bot.dialog('/delete', (session) => { session.userData = {};

//session.privateConversationData = {}; //session.conversationData = {}; //session.dialogData = {}; session.endDialog('Everything has been wiped out') }) .triggerAction({ matches: /delete all/i, confirmPrompt: "This will wipe everything out. Are you sure?" });

n-nik avatar Oct 23 '17 08:10 n-nik