I am integrating a third-party site with Salesforce LiveAgent to include passing in an external ID for a Contact record.
Following the instructions at this site I have a simple web page set up (omitting irrelevant portions, IDs and URLs sanitized):
<script type="text/javascript" src="https://XXXXXX.salesforceliveagent.com/content/g/js/31.0/deployment.js"></script>
<script type="text/javascript">
// What do I do with this variable?
var externalId = ...;
if (!window._laq) { window._laq = []; }
window._laq.push(function(){
liveagent.showWhenOnline('XXXXXXXXXXXXXXX', document.getElementById('liveagent_button_online'));
liveagent.showWhenOffline('XXXXXXXXXXXXXXX', document.getElementById('liveagent_button_offline'));
});
</script>
<script type="text/javascript">
liveagent.init('https://XXXXXX.salesforceliveagent.com/chat', 'XXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXX');
</script>
<div><a id="liveagent_button_online" href="javascript://Chat" style="display: none;"
onclick="liveagent.startChat('XXXXXXXXXXXXXXX')">Chat is Online, click here to initiate a chat.</a></div>
<div id="liveagent_button_offline" style="display: none;">Chat is currently offline.</div>
This works: it brings up a chat window and it connects correctly. However, I need to pass the externalId
variable into LiveAgent somewhere: this functionality is not covered by any documentation or tutorial that I can find.
How do I pass the external ID through the JavaScript API? If there is a way in Apex to have Salesforce automatically pull up the Contact based on a field name/value as a side effect that would be a nice bonus, but technically beyond the scope of this question.