xatkit-bot-platform / xatkit-chat-widget

(React) Chat widget for Xatkit
https://xatkit.com
MIT License
5 stars 2 forks source link

Persist conversation when changing page #5

Closed gdaniel closed 4 years ago

gdaniel commented 4 years ago

If the bot is installed on a website (i.e. accessible from multiple pages of the same site) the conversation is forgotten every time the user navigates to a different page. It would be nice to persist the current conversation and display it once the new page has been rendered (maybe using local storage?).

The same issue applies when reloading an existing page. This is partially caused by using socket.io random ids for sessions (meaning that a new socket.io session is created each time the page is reloaded), but even with persistent ids we would still have to persist the conversation somehow.

hamzaed commented 4 years ago

This is now supported by the widget using either LocalStorageor SessionStorage. The session id is also stored. We need to create a new action in socket.io to retrieve a particular session using the session id and the server has to confirm that session otherwise a new session should be created. Also we need to define the lifetime of a session specially for localStorage where we need to clear the session manually. This is also tricky on the server side (we need to create a garbage collector that destroys old sessions).

gdaniel commented 4 years ago

As we discussed I am not sure we need a new action to retrieve a session, we can maybe use the socket.io parameters to request a specific session when we create the client. This is something I need to check.

Looking at session life cycle, I did an experiment in xatkit-runtime using Caffeine's time-based caches to store Xatkit sessions. It worked fine, although it's not committed for the moment. This will ease our life on the server side. Not sure how we can deal with it on the client side though, the options I see are 1) to use a similar library/implement it manually 2) the server can send an event when the session is deleted (assuming we can get this information from the cache) to tell the client to update the session list.