End Zopim chat on inactivity

403 views Asked by At

I would like to end a chat if the user has been inactive for x seconds/minutes in order to free up our agents from having to wait for the chat to close on its own. I would also like to attach a tag to the chat before ending it so I can see that it was due to inactivity.

1

There are 1 answers

0
razaclas On

Credits to johnnyRose for this one, which you can find here https://stackoverflow.com/a/34516735/11499604 and to vijay for inspiring him!

The majority of this is his code with the zopim javascript inserted. This was the only code that I was able to get to play nice with zopim's javascript API. I saw a lot of people looking for triggers to end chat so I hope this helps others.

The trigger for this code is a user's inactivity. After 10 seconds of being idle on the page, it adds a tag to the user and ends the chat.

You can use this Zopim Javascript page for reference on other things you can do. https://api.zopim.com/files/meshim/widget/controllers/LiveChatAPI-js.html

    <script>
(function () { 
    var minutes = false; // true = minutes; false = seconds
    var interval = minutes ? 60000 : 1000; 
    var IDLE_TIMEOUT = 10; // 10 seconds in this example
    var idleCounter = 0;

    window.onmousemove = window.onkeypress = function () {
        idleCounter = 0;
    };

    window.setInterval(function () {
        if (++idleCounter >= IDLE_TIMEOUT) {
              $zopim(function() {
    $zopim.livechat.addTags('timeOut');
    $zopim.livechat.endChat();
  }); // or whatever you want to do
        }
    }, interval);
}());
</script>