Created
August 1, 2016 21:48
-
-
Save BrightnBubbly/0158890b31d2e4349e8bf047f46ac425 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- begin SnapEngage code --> | |
<script type="text/javascript"> | |
var uid; | |
var id; | |
(function() { | |
var se = document.createElement('script'); se.type = 'text/javascript'; se.async = true; | |
se.src = '//storage.googleapis.com/code.snapengage.com/js/f53fc276-9ebe-4093-a1ac-3fcbf85a03c0.js'; | |
var done = false; | |
se.onload = se.onreadystatechange = function() { | |
if (!done&&(!this.readyState||this.readyState==='loaded'||this.readyState==='complete')) { | |
done = true; | |
/* Place your SnapEngage JS API code below */ | |
/* SnapEngage.allowChatSound(true); Example JS API: Enable sounds for Visitors. */ | |
SnapEngage.setCallback('ChatMessageReceived', function (agent, msg) { | |
switch (agent) { | |
case 'Kelsey': | |
uid = 11576622; | |
break; | |
case 'Maricela': | |
uid = 14485590; | |
case 'Alberto': | |
uid = 14485520; | |
default: | |
uid = null; | |
} | |
// To update variables throughout the chat, use SnapEngage.updateCase("var1=val1,var2=val2"); | |
// the tricky thing is formatting that parameter value which might be beyond some people | |
if (uid) { | |
//id = uid; <-- this doesn't update the value of id | |
SnapEngage.updateCase(id=uid); | |
SnapEngage.updateCase("id="+uid); | |
console.log(uid); | |
console.log(id); | |
} | |
}); | |
} | |
}; | |
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(se, s); | |
})(); | |
</script> | |
<!-- end SnapEngage code --> |
Calling updateCase twice in a row like this may cause problems. Only the second call is necessary.
You'll also want to add another conditional to the if statement so that updateCase isn't called repeatedly. Something like this should work:
if (uid && id != uid) {
id = uid;
SnapEngage.updateCase("id");
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You'll want to add a
break;
after each case statement, otherwise the logic will just fall through each time unless the agent is 'Kelsey'