Clear chatbot user session (BotUserSession) from web application

Hi there,

How can I clear BotUserSession from web application?

Scenario -
I am logged into my web application where my bot is integrated.
When I access my bot, bot user session is created and with each user utterance, I am adding some data to BotUserSession object so that I can use it later in the same user session conversation.
Now if I log out of my web application then ideally, bot user session should also be cleared as the session for logged in user is closed.

Is there any way to tell bot to close the current user session?

Thanks,
Neha Sheikh

Hi @nehamsheikh,

Ideally, the botUsersession is persisted till 15mins of the idle time on the chat and then in the 16th minute, the session is destroyed.
So, once the user logs off from the web application, the botUsersession is persisted for 15mins more.

In case, if the user logs in within the 15mins, he/she will still have the previous chat session continued.

If you do not want the botUsersession to be carried when the user opens the chatwindow after logging in, then please follow the below step:

1- On the onConnect event in the Default conversation >> event handlers, select the option to run script.
runscript

Here, you can add a snippet to set the botUserSession key “undefined”.

Let us know if you need any further clarification.

Regards,
Yoga Ramya.

I am on Bot builder version 6.2.3.
In this version, we do not have on connect event.

Any other way to do so?

Also, how and when this onConnect will be fired?
Bot connection is acceptable but in case if gets fired on reload of chat window then it also won’t help.

Thanks,
Neha Sheikh

Hi @nehamsheikh,

You can also achieve this scenario by sending a message to the bot through BotKit when the chat window is closed and then validate in the bot, for message “xyz”(from botKit) set the botUserSession to undefined.

Please integrate BotKit and try to implement. We will be there in case of you face any errors/issues while implementing.

Regards,
Yoga Ramya.

Hey,

I figured the other work around.

I added one method to chatwindow.js file for clearing user session which I call in case user logs out. This method is calling sendMessage with intent to clear user session.

Thanks,
Neha Sheikh

1 Like

Hi @nehamsheikh,

We appreciate your work!!

Thank you for the information.

Regards,
Yoga Ramya.

Does anyone have an example snippet to set the botUserSession key to “undefined” via the onConnect event in the Default Conversation?

Also, does anyone know of a manner in which to have the bot clear the onscreen transcript after 5 minutes of inactivity without having to close the chatbot?

Thank you in advance,
Richard

@rpittman
If you only want to do it on screen and not in the backend, you can use chatwindow.js . I cannot provide any ready code but you will need to play with the events in that file.
If you want to do it from backend like chat data purge, we have these APIs -
https://developer.kore.ai/docs/bots/api-guide/delete-customer-data-api/
https://developer.kore.ai/docs/bots/api-guide/delete-customer-data-status-api/