Home | Basic chat with an onUnreadChange handler

Front Chat

Basic chat functionality with an onUnreadChange handler. Send a message to start automated replies that will increment the counter.


Unread Counter: 0

Code used on this page:

Unread Counter: <span id="counter">0</span>

<script src="https://chat-assets.frontapp.com/v1/chat.bundle.js"></script>
<script>
  const sleep = (delay) => new Promise((resolve) => setTimeout(resolve, delay))
  window.FrontChat('init', {chatId: 'cc6cd1eb09b189fa6a6f8a2c0cd0d63c', useDefaultLauncher: true});
  const registerHandler = async () => {
    await sleep(1000)
    window.FrontChat('onUnreadChange', function (event) {
      let counter = document.getElementById('counter');
      counter.innerHTML = event.unread_count;
    });  
  }
  registerHandler();
</script>