Sathish vp
Sathish vp

Reputation: 72

how to end coversation in bot framework using node js

i'm using trigger action and end conversation to end my chat..but it closes the current dialog of the chat... i want end the chat history or data ....

and i'm trying this code..

bot.dialog('/end', function (session) {
session.endConversation("End Conversation");
}).triggerAction({ matches: /^(exit)|(quit)/i });

Upvotes: 1

Views: 1746

Answers (4)

Alexander Lavrinovich
Alexander Lavrinovich

Reputation: 36

You can use this simple middleware to clear userData/conversationData bags:

export interface IResetDataSettings {
    resetCommand: RegExp;
}

export class ResetMiddleware {
    public static data(settings: IResetDataSettings): IMiddlewareMap {
        return {
            botbuilder: (session, next) => {
                if (settings.resetCommand && session.message.text && settings.resetCommand.test(session.message.text)) {
                    session.userData = {};
                    session.conversationData = {};
                    session.privateConversationData = {};
                    session.endConversation("Your conversation state was reset.");
                } else {
                    next();
                }
            }
        };
    }
}

Then setup it like this:

this.bot.use(ResetMiddleware.data({ resetCommand: /^reset data$/i }));

Upvotes: 1

Sathish vp
Sathish vp

Reputation: 72

delete session.userData;

This is worked for me.

Upvotes: 0

Eric Dahlvang
Eric Dahlvang

Reputation: 8292

You can use the command “/deleteprofile” to delete the User/PrivateConversation bot data bag state and reset your bot. Note, some channels interpret slash-commands natively, so it may be necessary to send the command with a space in front (“ /deleteprofile”)

From here: https://docs.botframework.com/en-us/technical-faq#my-bot-is-stuck--how-can-i-reset-the-conversation

Upvotes: 0

Ezequiel Jadib
Ezequiel Jadib

Reputation: 14787

You could try using

session.clearDialogStack()

or

session.reset();
session.endDialog();

Here you will find info about reset and here about clearDialogStack.

Upvotes: 4

Related Questions