Ir para o conteúdo

How to Automatically Open the Chat Upon Page Load

If you find it necessary to have the chat with an agent automatically open for visitors upon loading the site, follow the instructions below.

In the Rox.Chat service, there is no feature to make such changes at the button settings level in the Agent Workspace, so you need to make changes directly in the page code.

Add the following JS code to the desired page:

<script type="text/javascript">
  var roxchatChatStartParams = {'first-question' : '<Visitor's first message>',
                          'department-key' : '<Department key to which the chat will be directed>'};
  roxchat.api.chat.start(roxchatChatStartParams);
</script>

N.B.

You need to add the call roxchat.api.init() after the full page load.

The department-key parameter will only work if the force-without-department parameter is absent or if this parameter is set to false.

There is another option: to open the chat on the page only by clicking on a link with the corresponding qs-parameters. To implement this, you can use, for example, the following code:

const urlParams = new URLSearchParams(window.location.search);

let roxchatChatStartParams = {};
for (const roxchatChatStartParamName of ['first-question', 'mode', 'department-key']) {
    if (urlParams.has(roxchatChatStartParamName)) {
        roxchatChatStartParams[roxchatChatStartParamName] = urlParams.get(roxchatChatStartParamName);
    }
}

if (Object.keys(roxchatChatStartParams).length > 0) {
    roxchat.api.chat.start(roxchatChatStartParams);
}

This implementation assumes that the names of the link's qs-parameters are analogous to the names of the parameters passed to the chat start function through roxchatChatStartParams.