Recipe: Automatically route chats based on department online status

Have more questions? Submit a request

23 Comments

  • Intis Kalnins

    Would you just copy the "Using the Zopim chat widget" code above in full and add that to the page? I've tried, but when an agent from the department was online the chat widget didn't appear.
    Thanks.

    0
  • Sergiu Birca

    Hi Intis,

    =1=
    If you want to use the Zopim Chat Widget, then you have to replace in the script the 'Zopim_key' string with the real Account key:

    window.$zopim||(function(d,s){var z=$zopim=function(c){z._.push(c)},$=z.s=
    d.createElement(s),e=d.getElementsByTagName(s)[0];z.set=function(o){z.set.
    _.push(o)};z._=[];z.set._=[];$.async=!0;$.setAttribute("charset","utf-8");
    $.src="//v2.zopim.com/?Zopim_key";z.t=+new Date;$.
    type="text/javascript";e.parentNode.insertBefore($,e)})(document,"script");

    You can find it here:
    https://dl.dropbox.com/s/hk0zpdus0cxyjks/Zopim_copy_account_key.png?dl=0

    =2=
    If you want to use the Zendesk Web Widget, then you will have to replace the 'mysubdomain' string (mysubdomain.zendesk.com) with your Zendesk instance subdomain.

    PS:
    Don't forget to also set the correct department name in the script (currently 'Australia').

    Hope it helps.

    0
  • Charles

    Hi Sergiu,
    what if I don't want to make the widget disappear when the team is offline but switch to the offline "Leave a message" form ?
    Thanks for your advice.
    PS : I'm a Zendesk Enterprise user (not a Zopim standalone user).

    0
  • Sergiu Birca

    Hey Charles,
    If you offer the chat service via the Zendesk Web Widget (second script), then you don't have to do anything (no need to modify the script). If the Contact Form option is enabled in the Web Widget settings, then the system will go straight to the Web Widget Contact form page (will skip the chat step, even if there are online agents in other departments).

    If you do it via the Zopim widget (the first script), then you will just have to remove this line:
    $zopim.livechat.hideAll();

    from the script + enable the Offline Form option in Zopim dashboard / Widget / Forms.

    1
  • Jeremy Pinson

    Hi Sergiu,

    I was sent here by a zopim tech but it doesn't really answer our question. We are trying something similar except we're triggering a proactive chat session. So, our trigger fires and sets a department however, we need to disable the trigger if nobody from the department is online. What currently happens is that if there is nobody online, the trigger still fires and the user ends up trying to chat to nobody. So we still want the user to be able to open a normal chat and talk to our other agents... just not run the proactive chat trigger that goes to a specific department. Hope you can help!

    0
  • Sergiu Birca

    Hi Jeremy,

    You can not identify the status of the department via triggers. It can only be done via a script that uses the $zopim.livechat.departments.getDepartment  endpoint.

     

    Can you pls explain  in more details your use case:

    - Do you want to display the chat widget on the page automatically for all the users at the page load and at the same time if cernain conditions are met, fire a proactive trigger?

    OR

    you want the widget to be hidden by default and display it to specific customers at a specific time only as a result of a proactive trigger.

     

    - When you say "our other agents" => is the task to:

      - try to allocate the chat to a specific department first, and then, it that dept is offline, allocate it to a different department?

     

     

     

    0
  • Jeremy Pinson

    Thanks for your reply, Sergiu. In our current configuration, the widget is hidden by default and users can start a chat by clicking a 'Chat Now' button in our header. We have also created a proactive chat trigger to fire only on a specific page after 30 seconds. It is configured to initiate a chat session with a specific department called 'Professional' however, when Professional is offline the trigger still fires and a chat session starts but the user has nobody to talk to. So, we need a way to disable the trigger on this specific page if the Professional department is offline... and still allow the user to initiate a chat session with any other agent as it currently works.

    0
  • Sergiu Birca

    Hi Jeremy,

    ok, so this is what I suggest:

    =1=

    We will not use the triggers to set the department (it will be done via the script only);

    =2=

    We can not "disable" a trigger. We can only ensure that due to certain conditions, the trigger will not be applied to a chat session;

    =3=

    We will use tags instead. Via the following script, we will check the following conditions:

    a) if the Department1 status is online => add tag1

    b) if the department1 status is offline => check Department2 status.

    c)  if the Department2 status is online => add tag2

    d) if Department2  if offline => potentially hide or disabled (grey out) the 'Chat Now' button (you will have to build this yourself)

     

        $zopim(function() {

            setTimeout(function() {

                    $zopim.livechat.setOnConnected(function() {

                        var department_status = $zopim.livechat.departments.getDepartment('Department1');

                        if (department_status.status == 'offline') {

                            var department_status_2 = $zopim.livechat.departments.getDepartment('Department2');

                            if (department_status_2.status == 'offline') {

                                // hide the Zopim Widget or set the account to offline

                                //$zopim.livechat.hideAll();

                                $zopim.livechat.setStatus('offline');

                            } else {

                                // The department is Online (At least one agent in that department is Online)

                                $zopim.livechat.addTags("dept1_chat_redirected");

                                $zopim.livechat.departments.filter('');

                                $zopim.livechat.departments.setVisitorDepartment('Department2');

                                $zopim.livechat.theme.reload();

                            }

                        } else {

                            $zopim.livechat.addTags("dept1_chat");

                            $zopim.livechat.departments.filter('');

                            $zopim.livechat.departments.setVisitorDepartment('Department1');

                            $zopim.livechat.theme.reload();

                        }

                    });

                }, 3000) //3 secs

        });

     

     

    =4=

    Have 2 triggers in Chat:

    The critical condition in the first trigger: Visitor tag contains:  dept1_chat

    The critical condition in the second trigger:Visitor tag contains:   dept1_chat_redirected

     

     

    As a result of the above, the first trigger will be applied only if via the script, you will have the confirmation that the Dept1 is online (the dept1_chat tag is present), while the second trigger will work only if Dept1 is offline and Dept2 is online(the dept1_chat_redirected tag is present).

     

    Hope it helps.

    0
  • Rameez Munir Bari

    Hi Sergiu,

    I am facing a issue in zopim in which offline zendesk tickets are not creating as my whole department is invisible for whole day. For Example: Department XYZ is Invisible for 23rd,Jan and they receive 20 overall chat during but only 15 offline zendesk tickets are been created there no zendesk ticket against 5. 

    I have talked with Support team of zendesk they say that

    "The way the widget may be working right now is that upon loading the webpage, the widget checks to see if agents are available in that department and if the page is idle for hours before the user tries to initiate a chat, the widget still thinks agents are available even if none are actually available. What we would recommend doing instead is changing your script so that instead of checking for available agents upon page load, have the widget check when the user clicks the widget to initiate a chat"

    We have Zopim triggers enabled that sets the department when the end-user first loads the widget.

    So can you please help what changing should i made in the script or is it some think else is the issue.

     

    Thanks

    0
  • Sergiu Birca

    Hi Rameez,

    Lets take this offline. I will send you an email.

    0
  • Nathan Miller

    Hi Sergiu,

    This solution is terrific; however, we've run into one problem I'm hoping you can help us resolve.  When we use the method described to create a Support department, when all Support agents go Invisible the chat button does go away as it's supposed to.  However, if anybody is currently in a chat with an agent and all agents are invisible the current chat window for the visitor also disappears.

    We want to accommodate the end of the day when agents are going home, so they can go invisible, so no new chats come in, and finish their current chats.  Is there a method you see to accomplish this?

    We did already try changing $zopim.livechat.hideAll(); to $zopim.livechat.button.hide(); but this caused other problems (the contact form pops up on every single page load for visitors when we do that.

    Your help is much appreciated.

    UPDATE!

    It looks like we figured out a way to make this work.  We just wrapped the hideAll() within isChatting().  Example:

    if ($zopim.livechat.isChatting() == false) {
    $zopim.livechat.hideAll();
    }
    0
  • Sergiu Birca

    Hi Nathan,

    yep, that is the solution (I should probably consider this use case as well (the department switching to offline for customers that are already engaged)).

     

    Depending on the implementation, there might be the case of displaying the .window element for customers that are already engaged in a chat, who keep accessing various pages on the website where the script is loaded.

    So potentially you might want to add to your if statement, an else:

    else{

     

    $zopim.livechat.window.show();

    }

    0
  • James Lawrence
    The Line:
    if (department_status.status == 'offline')

    is always giving me an error:
    Uncaught TypeError: Cannot read property 'status' of undefined

    I have double checked the spelling and the case of our departments
    0
  • Sergiu Birca

    Hi @James,

    a couple of reasons for this:

    - The department is disabled (make sure it is enabled);

    - The department name is Case sensitive. Make sure you use the exact name.

     

    Hope it helps.

    0
  • James Lawrence

    Indeed, the department was disabled, thank you for the help.

    0
  • Ifeanyi Obiano

    Thanks for this.

    Can I check for when chat limits has been reached for all agents in a department and reroute?

    on other words, I want to route chats to a default department when all agents in a department has reached chat limits

    0
  • Sergiu Birca

    Hi Ifeanyi,

    There isn't a functionality that would allow you identify this state. The system will add the new customers to the queue and will allocate the first chat from the queue to the first agent that will close a chat (chat limit -1). 

    If you want to have a certain control over this and are ready to invest in dev work (+ your account is on Enterprise), you can check our Real Time API:

    https://developer.zendesk.com/rest_api/docs/chat/apis

    It has a parameter that returns the incoming chats value (number of customers waiting to be served (your queue)). You can use that data in a script.

    pseudocode:

    If (incoming chat value > x)
    {
    // route the current chat to a second department

    else
    {
    // route the current chat to the default department
    }

     

    Hope it helps.

     

    1
  • EskimoJoe

    Hi Guys,

    I am trying to figure out how to get something similar to this to work in Shopify.

    I have tried adding the script in the theme.liquid file, as well as the zendesk-embeddable.js file ,and have had no luck.

    We have 2 brands, with a widget each running on separate sites, and 2 chat departments set up. When there are no agents online in a department I want the chat to show "leave a message"

    Can anyone help with this?

    Thanks!

    0
  • Filiph Petzäll

    Hey @Sergiu and thank you for this helpful post!

    Let me start by saying im not a developer but i hope i can understand more than most of us non-devs (aka mortals). I have a similar case to EskimoJoe, not quite the same though, we dont have Shopify so none of that matters for us. Anyways;

    The setup: We have 2 different sites, 'Site1' & 'Site2'. We run different scripts for the widget on each. Each site have their 3 own departments - lets say 1,2,3 for 'Site1' and 4,5,6 for 'Site2'.

    The problem: when departments 1,2 and 3 is offline the chat is still working and online on Site1, only the pre-chat form is not visible. Im guessing its because there is still agents avalable in departments 4/5/6 (which is departments for Site2). The agents in Site2-departments cannot handle chats for Site1 and vice versa.

    Wanted solution: Make it so when dep.1,2 and 3 is offline, Site1 will show "leave a message" instead of "live-chat" and vice versa for Site2. We do not want to hide the widget or anything since we still use the helpcenter-part of the widget when chat is offline.

    If anyone would be willing to assist me in this matter that would be greatly, greatly appreciated! I tried to make up my own code for this based on your initial post, see below. Would something like this work?

    var dep1 = $zopim.livechat.departments.getDepartment('1');
    var dep2 = $zopim.livechat.departments.getDepartment('2');
    var dep3 = $zopim.livechat.departments.getDepartment('3');

    if (dep1.status == 'offline' && dep2.status == 'offline' && dep3 == 'offline'){
    $zopim.livechat.setStatus('offline');
    }
    else {
    $zopim.livechat.setStatus('online');
    }

     

    0
  • Sergiu Birca

    Hi Filiph,

    when departments 1,2 and 3 is offline the chat is still working and online on Site1, only the pre-chat form is not visible. Im guessing its because there is still agents avalable in departments 4/5/6 (which is departments for Site2). The agents in Site2-departments cannot handle chats for Site1 and vice versa.

     

    Yes, if at least one of the departments is online => the widget will be presented in the online state.

    To avoid this you have to set the entire account as offline:

    $zopim.livechat.setStatus('offline');

     

    pseudo code:


    if (dep1.status == 'offline' && dep2.status == 'offline' && dep3.status == 'offline')
    {

    // Set the account status to 'offline'
    $zopim.livechat.setStatus('offline');

    } else {

    // set everything you want to set if the department(s) is/are online
    }

     

    In case if you offer the chat channel via the Web Widget + other channels as well (HC and/or Contact form), pls have a look at this article as well:
    https://support.zendesk.com/hc/en-us/articles/115000566208-Web-Widget-Chat-advanced-customization

     

    Hope it helps.

    1
  • Filiph Petzäll

    Thank you so much @Sergiu, you are amazing!  

    Just to let you and all the ones who find themselves in a similar situation know that this worked for us and now we're able to control online/offline status of the chat on each site independently based on if agents are avalable! Thanks a lot! 

    Here's some code to help in case someone reads this with the same issue;

    $zopim(function() {
    $zopim.livechat.setOnConnected(function() {
    $zopim.livechat.setOnStatus(function () {
    //Feel free to add however many departments you'd like to this list
    var dep1 = $zopim.livechat.departments.getDepartment('yourDepartmentName');
    var dep2 = $zopim.livechat.departments.getDepartment('yourDepartmentName');
    var dep3 = $zopim.livechat.departments.getDepartment('yourDepartmentName');

    //Check status of each dep. from list above and include && after in the conditions for IF statement
    if (dep1.status == 'offline' && dep2.status == 'offline' && dep3.status == 'offline'){
    //This is what happens if ALL departments is offline
    $zopim.livechat.setStatus('offline');
    } else {
    //This is what happens if one or more departments is online
    $zopim.livechat.setStatus('online');
    }
    });
    });
    });
    0
  • Damian Wallace

    We have another one of those edge cases.  We want to use the chat tool for user assistance pre-sales for a brand, and also for tech support for all of our brands.  We are a multi-brand user. When the support department closes, they do not want people to leave a message but rather open a Zendesk issue.  Pre-Sales wants to have the option to leave a message.  It seems like we can only have one method, and Support is going to win this one.

    Pre-sales works 8 to 4 (1 person)

    Support works 5 to 5 (4 people)

    Through the API we can set the department for the special brand to go only to that agent's department.  But, when 4:01 rolls around, the chat box disappears since the department is closed.   So, is there a way to use the API to somehow still have the chat box appear for pre-sales with the leave a message option while leaving the support team using the default widget behavior?    

    If the widget is set to offline, is that any way to run some other Javascript?

     

      

    0
  • Abisai Rojas

    Entiendo que para ponerlo en mi zendesk chat tengo que copiar el código que viene arriba y queda?

    0

Please sign in to leave a comment.

Powered by Zendesk