OvidijusParsiunas / deep-chat

Fully customizable AI chatbot component for your website
https://deepchat.dev
MIT License
1.43k stars 221 forks source link

Save and Retrieve Chat Sessions #49

Closed 7h360df47h3r closed 10 months ago

7h360df47h3r commented 10 months ago

Description:

Overview I would like to propose an enhancement for the ability to save chat sessions to local storage and retrieve them in sync. Currently, if a user refreshes the page, the entire chat session is lost, which can be inconvenient and disrupt the user's flow of interaction.

Feature Description Save Session to Local Storage: Implement functionality that automatically saves the current state of the chat session to the browser's local storage periodically or upon specific user actions (e.g., sending a message).

Retrieve Previous Sessions: Upon returning to the chat or after a page refresh, users should be able to retrieve their previous session. This could be done automatically when the chat interface loads.

Use Case and Benefits

OvidijusParsiunas commented 10 months ago

Thankyou for raising these descriptive feature proposals.

Whilst automatically tracking messages in local storage would be a great addition, there are few issues with it:

Based on the complexities outlined above, this option will currently not be pursued further.

Developers should use the onNewMessage event to track state in their platform and implement it the way they desire. The Playground is actually already using onNewMessage to track its state via local storage.

Perhaps to help developers, I can add an example in the documentation for how to track state.

Thankyou once again for the detailed proposal and it certainly made me think about tracking state. If such a feature is important to you - you can always fork the project and tailor it to your use-case.

To note, I will be doing some work to help load messages from state in the future, so state tracking should be improved.

Thanks again!

7h360df47h3r commented 10 months ago

I understand, please share implementation of how this is being performed in the Playground.

Thanks and appreciate the work you have accomplished so far.

OvidijusParsiunas commented 10 months ago

The Playground adds a function called newestMessages to the onNewMessage property. Link to code

When newestMessages function is triggered it updates the messages property in the webpage's config:

The config is is accessed in the local storage when the user opens the app and is saved before closing. Code 1 Code 2 Code 3

The Playground is a large application so the code may be a little hard to navigate, bug hopefully the above links will help!