Clear chatbot user session (BotUserSession) from web application


(Neha Sheikh) #1

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


(Yoga Ramya Mendu) #2

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.


(Neha Sheikh) #3

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


(Yoga Ramya Mendu) #4

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.


(Neha Sheikh) #5

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


(Yoga Ramya Mendu) #6

Hi @nehamsheikh,

We appreciate your work!!

Thank you for the information.

Regards,
Yoga Ramya.


(Richard Pittman) #7

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


(Swagat) #8

@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/