API to check visibility criteria for Sprinklr Live Chat

Updated 

You can control the visibility of the Sprinklr Live Chat depending upon three conditions - Business Hours, Pending Cases in the Queue, and Agent's Availability.

You can use this SDK to check the availability of the live chat widget based on the visibility configuration in the Live Chat builder. You can use the SDK to get the availability status of the live chat and use it to determine the status of external website CTA i.e., enable it if available and disable if not available.

const handleChatAvailability = (isChatVisible) => {// isChatVisible -- true mean that chat is available // isChatVisible -- false mean that chat is not availableif (isChatVisible) {// enable a button or any other action preferred by brandreturn;} else {// disable a button or any other action preferred by brand}};window.sprChat("onAvailabilityChange", handleChatAvailability);// subscribe availability event from live chat widget.This needs to be used when you want to get events from Live Chatwindow.sprChat('offAvailabilityChange', handleChatAvailability);// unsubscribe availability event from live chat widget.This needs to be used when you want to get events from Live Chat

This SDK script has to be embedded along with the live chat embed code and can’t be used independently i.e. without the live chat embedded code.

Note:

The below mentioned approach has been deprecated.

Sprinklr API is exposed to read the visibility criteria.

This is a public API for which you don’t need any auth token. All you need to do is make this GET API call from your website.

https://prod-live-chat.sprinklr.com/api/livechat/handshake/check-visibility/5f620760106b347fa8f6555a_app_600016940

Just replace the appId in the URL above and ensure the URL is for your environment, i.e. prod/prod2/prod4, etc.

GET Check Visibility

Live Chat visibility depends on the following three conditions:

  1. Business Hours 

  2. Agents' Availability

  3. No. of Pending Cases

If any of the above conditions don't match, API will return false. Based on this, you can take several actions, for example, changing the “Chat Now” button on your website to “Email Us”.
If any of the above conditions are not set, API will assume that the unset condition is satisfied.

API Endpoint

/livechat/handshake/check-visibility/{appId}

Header

The following set of HTTP header fields provide required information about the request or response, or about the object sent in the message body. Both request headers and response headers can be controlled using these endpoints.

Key

Value

Description

content-type

application/json

Request format should be JSON as the endpoint expects a JSON body.

origin

http://chat.sprinklr.com

URL of the host website.

referer

http://chat.sprinklr.com

URL of the host website.

*Either origin or referer required.

Path Parameter

Parameter

Required/Optional

Description

Type

{applicationId}

Required

Id of the Live Chat Application.

String

Response

Value

Type

Status

true/false

boolean

200

Example

  1. In case you want to test over terminal, you can use the curl

    curl --location --request GET ‘https://qa4-live-chat.sprinklr.com/api/livechat/handshake/check-visibility/5f620760106b347fa8f6555a_app_600016940’ \
    --header ‘referer: http://chat.abhishekpriyam.com/’ \

    Note: Please update environment, app ID in URL, and page referrer accordingly.

  2. If you are using JS to get availability detail, you can use a code like this.

    ​<script>​​
    ​​function httpGet(theUrl)​​
    ​​{​​
    ​​ var xmlHttp = new XMLHttpRequest();​​
    ​​ xmlHttp.open( "GET", theUrl, false ); // false for synchronous request​​
    ​​ xmlHttp.send( null );​​
    ​​ return xmlHttp.responseText;​​
    ​​}​​
    ​​​​​
    ​​var response = httpGet("https://prod-live-chat.sprinklr.com/api/livechat/handshake/check-visibility/5f620760106b347fa8f6555a_app_600016940");​​
    ​​console.log("Chat available: "+response); //do anything with the response - it's true for available, false for un-available​​
    ​​​​​
    ​​</script>

    Note: Please update environment, app ID in URL accordingly.