This usecase describes example steps for using the API to retreive chat history for existing logged-in users. Additionally, visitor sessions should only last for the duration of their browser session. A logout function will reset the chat to an empty state and treat the visitor as a new customer.
1. Setup Session-Based ID
To achieve this, Chatvisor has to be switched to "Session-Based IDs", which are stored in sessionstorage and deleted once the user closes the browser window.
More information on this setting can be found here.
2. Add tagging code to application
On a page where the user is signed-in, add a call to the tagging method with user data available from your application. This adds user information to an existing browser session.
In your logout function, include a call like this in order to reset the user session. This removes the current chat history from their chat window and treats the user as a new customer from then on.
If you want to assign a customer to a specific agent, you can include the assignedUser property like this:
3. Check results
With this setup done, any user who visits the page will always receive a fresh Session ID, and thus will see an empty chat.
A user who logs in will automatically have their chat history retreived and visible in the chat window.
A user who logs out will not see their chat history anymore and instead be treated as a new customer.