Skip to main content


Reject All Live Agent Invites with One Click

What is Live Agent?

The Live Agent app for Salesforce’s Service Cloud Agent Console is a versatile and highly customizable web chat utility. One side is the external website where your customers visit, it can be a Customer Community with authenticated users or any web page where the deployment JavaScript is placed. Salesforce provides the code on the settings page for the deployment.

There are two types of buttons provided so the visitor may initiate a chat with the Service Cloud agent. First is a standard button, comprised of an online image and an offline image. Again, in the settings of the button Salesforce will provide the necessary JavaScript for placement of the button on the webpage.

The other type of button is an auto-invite. This is an image, which will appear on the screen once a set of rules are satisfied. This image has a red X in the upper right corner placed by the Live Agent Engine so that the invite may be rejected. There is no need for additional code for placement of auto-invites because they are handled completely by the Live Agent engine. One short fall of the configuration is that there is not a setting which automatically rejects all auto-invites once one invite is rejected.

Salesforce does supply a full API for the Live Agent which we can utilize to accomplish this task with a few steps. First, we will want to capture the event of the visitor clicking on the red “X” to reject the invite. Then we will create a cookie to indicate if a chat has been rejected. Next, on the page load there needs to be some code to check the value of the cookie and pass that to the Live Agent. Lastly, in the rules of the auto-invite we will check the value before deciding to display the invite.

Capturing Events of the Live Agent

The Live Agent REST API provides a web developer the means of extending standard capabilities of the Live Agent engine. Full documentation may be found in this PDF. For this example we want to capture the event which fires when a button is rejected. And that can be accomplished with a line like this which will have to be repeated for each button to be rejected.

liveagent.addButtonEventHandler('[Button ID]', buttonCallback);

The first parameter is the Salesforce ID of the button and the second is the function which will be run when there is a Live Agent event. The function main responsibility is to delegate the event to the correct function for each event. Here we are only testing the reject event, and if it is true,  calling the RejectChatInvite. The function only creates a cookie for this example but you could add any JS you wish to update the UI.

function buttonCallback(e) {
if (e == liveagent.BUTTON_EVENT.BUTTON_REJECTED) {
function RejectChatInvite(){
document.cookie = "DisplayLiveChat=FALSE";

Communicating Values to Salesforce

The purpose of creating a cookie is to save state in the browser. Go ahead and use your own method if you are managing state elsewhere. What is necessary is to pass a message to Live Agent onLoad of the page. We do this with the following lines:

function getRejectedChatInvite(){
var name = "DisplayLiveChat=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++){
var c = ca[i];
if (c.indexOf(name) != -1) return c.substring(name.length, c.length);
return "TRUE";
var b=getRejectedChatInvite();

There are a couple things happening here. First we want to check if there is a cookie and if so return its value. The next task is to pass that value to Live Agent via the setCustomVariable method which accepts a key-value pair. This should be done when the page loads and before the liveagent.init method supplied by Salesforce is called.

Now in the configuration of the invitation buttons you can create a rule for displaying the invite. The rule type is Custom Variable. So set the name to DisplayInvite and value to “NOT EQUALS FALSE”. Be aware the Invite rules are case sensitive so you need to match the exact text being passed.


This technique allows you to supply the reject one/reject all rule to your Live Agent deployment. Hopefully this also serves a doorway for you to enhance the behavior of Live Agent on your site.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Clayton Bruckert

Over 17 years IT experience focusing on cloud architecture and web-based applications that integrate with Specialties include improving development processes, establishing best practices for teams and interface with business stake holders. Experienced in both custom development on platform as well as doing product development.

More from this Author

Follow Us