Update a custom LiveChat button text based state change

I created a custom LiveChat button. And I used the LiveChat API to open up the chat window from that button. I have a

tag inside the button that has some text that I would like to update based on if LiveChat is on or not. I have been working it out for my client from maheenandco for quite a while now.

I’m trying to check the data.state to see what it’s set to and then update the text accordingly.

Hi!
For accomplishing something like this, you’d need to:

  1. Use the getter state that you will need to trigger whenever the page is loaded for the first time/reloaded to get the current status of the group and, based on that, render the online or offline button. The getter is described here: Chat Widget JS API | LiveChat Platform Docs & API Reference
  2. Then you would need to listen to the onAvailabilityChanged callback that will be triggered when the chat will detect the group’s status change. You can use it to shift the state of the custom button → this callback is described here: Chat Widget JS API | LiveChat Platform Docs & API Reference

You an also use our built-in Chat buttons that can detect the state of the group upon the page load, it will save you some trouble.