Newer Version Available
Direct-to-Agent Routing Code Sample
Implement direct-to-agent routing using the Deployment API.
The following code sample shows you how to set up direct-to-agent so your agents can send visitors a “Chat with Me” link.
1<apex:page standardController="User" showHeader="false">
2 <h1>Direct-to-Agent Chat with {!user.name}</h1>
3
4 <!-- dta_online is displayed whenever the specific agent is available to chat. -->
5 <div id="dta_online" style="display: none;">
6
7 <!-- A valid button is required here even though it's direct-to-agent - some button settings still apply. -->
8 <!-- {!left(user.id,15)} is needed to truncate an 18-char ID to the 15-char version that Chat uses. -->
9 <a href="javascript://Chat" onclick="liveagent.startChat('573D01234567890', '{!left(user.id,15)}')">Chat with {!user.name}!</a>
10
11 </div>
12
13 <!-- dta_offline is displayed if the specific agent is unavailable. -->
14 <div id="dta_offline" style="display: none;">
15
16 <!-- button_online is displayed if any agents are available to chat for the button. -->
17 <div id="button_online" style="display: none;">Sorry, {!user.name} is not available. If you’d like, you can
18 <a href="javascript://Chat" onclick="liveagent.startChat('573D01234567890')">start a chat with another agent</a>.
19 </div>
20
21 <!-- button_offline is displayed if no agents are available to chat for the button. -->
22 <div id="button_offline" style="display: none;">Sorry, all agents (including {!user.name}) appear to be unavailable.</div>
23
24 </div>
25
26 <!-- Change the domain name to the correct one for your org. -->
27 <script type='text/javascript' src='https://MyDomainName.my.salesforcescrt.com/content/g/deployment.js'></script>
28
29 <script type='text/javascript'>
30 /* The following calls pass the user ID as the first argument and show whether the agent is online.*/
31 liveagent.showWhenOnline('{!left(user.id,15)}', document.getElementById('dta_online'));
32 liveagent.showWhenOffline('{!left(user.id,15)}', document.getElementById('dta_offline'));
33
34 /* The following calls pass the button ID as the first argument and show whether
35 any agents are available to handle chats from the button. */
36 liveagent.showWhenOnline('573D01234567890', document.getElementById('button_online'));
37 liveagent.showWhenOffline('573D01234567890', document.getElementById('button_offline'));
38
39 /* This domain and the IDs are specific to your org, so replace these with your own. */
40 liveagent.init('https://MyDomainName.my.salesforcescrt.com/chat', '572D01234567890', '00DD01234567890');
41 </script>
42</apex:page>When you use this code sample with your org and call it ChatWithMe, agents can create a link that sends a chat request directly to them.
http://your.website/ChatWithMe?id=005D01234567890
You can make it even easier for agents to send a “chat with me” link by creating a Quick Text message that any agent can use:
http://your.website/ChatWithMe?id={!User_ID}
The User ID spot in the link is automatically filled with the User ID of any agent who uses the Quick Text.