node.jsreactjsexpressdialogflow-essessionid

Is there a way in dialogflow, to retain chat history of a session after reloading the web page?


I build a chatbot using expressjs, reactjs and dialogflow. What I want to do is, the chat history to be remained when the page is refreshed. Is there a way to do that? (Might be using sessionID?)


Solution

  • I did find a way to do this with just a few lines of code

    var messageList = document.querySelector('df-messenger') .shadowRoot.querySelector('df-messenger-chat') .shadowRoot.querySelector('df-message-list').shadowRoot.querySelector('#messageList');

    ..

    then save the contents of the messageList to a localStorage object in the browser then on page load just load it in to the messageList element

    ...

    on new message received event

    window.localStorage.setItem('chatBotHistory', messageList.innerHTML);

    ...

    onload event of new page

    document.querySelector('df-messenger') .shadowRoot.querySelector('df-messenger-chat') .shadowRoot.querySelector('df-message-list').shadowRoot.querySelector('#messageList').innerHTML = window.localStorage.getItem('chatBotHistory');