Newer Version Available
Automated Chat Invitation Code Sample
Test and preview how automated chat invitations can work
on your website using this code sample.
The following code is for an automated chat invitation
that uses the addButtonEventHandler() method to display a customized invitation on a website. This invitation
allows customers to start a chat with an agent when an agent with
the correct skills is available to chat.
1<apex:page>
2<div id="liveagent_invite_button_573x0000000001O" style="display: none;
3 position: fixed; border: 2px solid darkblue; border-radius: 5px;
4 background-color: lightblue; height: 100px; width: 200px;">
5<div style="cursor: pointer; padding: 5px; right: 0px;
6 position: absolute; color: darkred; font-weight: bold;"
7 onclick="liveagent.rejectChat('573x0000000001O')">X</div>
8<div style="cursor: pointer; top: 42px; left: 65px; position: absolute;
9 font-weight: bold; font-size: 16px;"
10 onclick="liveagent.startChat('573x0000000001O')">Start Chat</div>
11</div>
12
13<script type='text/javascript'
14 src='https://c.la1s1.saleforceliveagent.com/content/g/deployment.js'>
15 </script>
16<script type='text/javascript'>
17function buttonCallback(e) {
18 if (e == liveagent.BUTTON_EVENT.BUTTON_AVAILABLE) {
19 document.getElementById('liveagent_invite_button_573x0000000001O').style.display
20 = '';
21 document.getElementById('liveagent_invite_button_573x0000000001O').style.left =
22 '300px';
23 document.getElementById('liveagent_invite_button_573x0000000001O').style.top =
24 '200px';
25 }
26 if (e == liveagent.BUTTON_EVENT.BUTTON_UNAVAILABLE) {
27 document.getElementById('liveagent_invite_button_573x0000000001O').style.display =
28 'none';
29 }
30 if (e == liveagent.BUTTON_EVENT.BUTTON_ACCEPTED) {
31 document.getElementById('liveagent_invite_button_573x0000000001O').style.display =
32 'none';
33 }
34 if (e == liveagent.BUTTON_EVENT.BUTTON_REJECTED) {
35 document.getElementById('liveagent_invite_button_573x0000000001O').style.display =
36 'none';
37 }
38}
39liveagent.addButtonEventHandler('573x0000000001O', buttonCallback);
40liveagent.init('https://d.la1s1.salesforceliveagent.com/chat', '572x00000000001',
41 '00Dx00000001gEH');
42</script>
43</apex:page>The code above results in an invitation that looks like this:
