--- title: "Chat Button" slug: "visitor-side-api-chat-button" updated: 2022-03-11T09:12:45Z published: 2022-03-11T09:12:45Z canonical: "developer.comm100.com/visitor-side-api-chat-button" --- > ## Documentation Index > Fetch the complete documentation index at: https://developer.comm100.com/llms.txt > Use this file to discover all available pages before exploring further. # Chat Button ## Chat Button ### Visibility #### Get To know whether a specific button is visible or not, you could use the following API: ``` /** @type {string} */ const campaignId = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'; /** @type {boolean} */ const isVisible = Comm100API.get('livechat.button.isVisible', campaignId); ``` You need to provide campaign ID of button you are interested in. If no campaign id is provided, the first campaign ID returned by `Comm100API.get('livechat.campaignIds')` will be used as default value. #### Set Meanwhile, you could update visibility of button as well: ``` /** @type {boolean} */ const isVisible = true; /** @type {string} */ const campaignId = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'; Comm100API.set('livechat.button.isVisible', isVisible, campaignId); ``` Similarly, if campaign ID is not provided, the first campaign ID returned by `Comm100API.get('livechat.campaignIds')` will be used as default value. #### Event You could also listen to changes of visibility: ``` Comm100API.on('livechat.button.show', function (button) { }); Comm100API.on('livechat.button.hide', function (button) { }); ``` The first callback will be triggered when one button is shown; The second callback will be triggered when one button is hidden. When callback is triggered, info of chat button will be provided as an object, which looks like: ``` const button = { id: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', // string, campaign id of button type: 'adaptive', // string, type of button }; ``` Possible types of chat buttons are: `"adaptive"`, `"float"`, `"image"`, `"text"`: - `"adaptive"`: Adaptive button - `"float"`: Float image button - `"image"`: Static image button - `"text"`: Text button ### Online Status #### Get To know whether specific button is online or offline, you could use: ``` /** @type {string} */ const campaignId = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'; /** @type {"online" | "offline"} */ const status = Comm100API.get('livechat.button.status', campaignId); ``` If campaign ID is not provided, the first campaign ID returned by `Comm100API.get('livechat.campaignIds')` will be used as default value. The return value of this API is string, either `"online"` or `"offline"`. #### Event You could use the following APIs to listen to changes of button online status: ``` Comm100API.on('livechat.button.online', function (button) { }); Comm100API.on('livechat.button.offline', function (button) { }); ``` Informaiton of button will be provided as an object. The structure of this object is the same as `"livechat.buttons.show"` event, which can be found [here](/docs/visitor-side-api-chat-button#event-2) ### Open Chat Window You can only specific chat window by clicking on corresponding chat button, or use the following API: ``` /** @type {string} */ const campaignId = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'; Comm100API.do('livechat.button.click', campaignId); ``` If `campaignId` is not proivded, the first campaign ID returned by `Comm100API.get('livechat.campaignIds')` will be used as default value. This is a sync action, thus no return value for this API. Please also notice that if there is already an opened chat window, calling this API might trigger nothing.