Question

When a chat session is timed out, and the visitor requests a new chat, the new chat request does not retain the department assigned from the previous session. Is there a way to reapply the department assigned from the previous chat?

Answer

Disclaimer: This article is provided for instructional purposes only. Zendesk does not support or guarantee the code. Post any issues you have in the comments section or try searching for a solution online.

It is expected behavior for a new chat session to not reapply the department automatically after a visitor timeout.  As a workaround, use the on chat:connected API callback to identify the reconnection event and update the user settings with updateSettings API to set the department for the new chat session.

The API is applied when the reconnect event occurs after a visitor time out but before the new message is sent by the visitor. This ensures the department gets assigned to the new session.

Note: This workflow is not possible when you use triggers to set the department. There is no way to re-fire a chat trigger when the visitor reconnects.

Below is an example API script that uses these methods to reapply the Shopping Cart department whenever a visitor first connects or reconnects from a timed-out session.

<script id="ze-snippet" 
src="https://static.zdassets.com/ekr/snippet.js?key=ACCOUNT_KEY"> </script>

<script type="text/javascript">
zE('webWidget:on', 'chat:connected', function() {
  zE('webWidget', 'updateSettings', {
    webWidget: {
    chat: {
        departments: {
      select: 'Shopping Cart'
        }
    }
    }
  });
});
</script>
Powered by Zendesk