Skip to content

Commit

Permalink
Added env variables to both hide close button and automatically open …
Browse files Browse the repository at this point in the history
…the chat window when in embed mode
  • Loading branch information
jolzee committed May 7, 2020
1 parent eb92067 commit 6dae7a4
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ VUE_APP_AUTH_MS_TENANT=
VUE_APP_AUTH_MS_DOMAIN_HINT=
VUE_APP_IP_URL=
VUE_APP_GEO_URL=
VUE_APP_EMBED_INITIAL_STATE_OPEN=true
VUE_APP_EMBED_SHOW_CLOSE_BUTTON=false
8 changes: 0 additions & 8 deletions public/embed-example.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
message: "This was sent from the customer's web site"
};
</script>
<style>
.highlight:focus {
border: 3px solid red;
}
</style>
</head>
<body>
<!-- (function() {
Expand All @@ -29,10 +24,7 @@
b.appendChild(scr);
})(); -->
<!-- use the full url to static/embed-leopard.js below | https://domain.com/static/embed-leopard.js -->
<input type="button" class="highlight" />
<input type="button" class="highlight" />
<div id="leopardChatWindow"></div>
<input type="button" class="highlight" />
<script src="static/embed-leopard.js"></script>
</body>
</html>
16 changes: 13 additions & 3 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@
<v-icon>{{ `mdi-${emergencyConfig.icon}` }}</v-icon>
</v-btn>
</v-fab-transition>
<template v-if="embed">
<template v-if="embedAndShowClose">
<span @click="closeChatEmbedded">
<v-fab-transition>
<v-btn
Expand All @@ -363,6 +363,7 @@
</v-fab-transition>
</span>
</template>
<template v-else-if="embed"></template>
<!-- Handle close button in demo mode -->
<template v-else>
<v-fab-transition v-if="!embed || isLiveAgentAssist">
Expand Down Expand Up @@ -755,7 +756,11 @@ export default {
"isChatOpen",
"socialAuthEnabled"
]),
embedAndShowClose() {
let showCloseButton = this.embed && window.leopardConfig.embed.showCloseButton;
logger.debug("EMBED: Show close button?", showCloseButton);
return showCloseButton;
},
hasDifferentHistory() {
if (this.getLatestDialogHistory.length !== this.dialogs.length) {
logger.debug(`Should show 'History' menu option`);
Expand Down Expand Up @@ -956,13 +961,18 @@ export default {
);
},
isChatOpenLocalStorage() {
let isChatOpen = localStorage.getItem("isChatOpen");
if (isChatOpen === null) {
isChatOpen = false;
} else {
isChatOpen = JSON.parse(isChatOpen);
}
if (window.leopardConfig.embed.isInitialStateOpen) {
isChatOpen = true;
}
let result = false;
logger.debug(`isChatOpenLocalStorage: ${isChatOpen}`);
if (isChatOpen) {
Expand Down Expand Up @@ -1041,7 +1051,7 @@ export default {
localStorage.setItem("isChatOpen", "false");
sendMessageToParent("hideLeopard");
this.calculateMobileHeight(); // only called on mobile devices
if (window.leopardConfig.killSessionOnCloseEmbed) {
if (window.leopardConfig.embed.killSessionOnCloseEmbed) {
this.loginPerformed = false;
}
logger.debug("Close Chat Embedded");
Expand Down
6 changes: 5 additions & 1 deletion src/utils/leopardConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ const getEnvValue = (name, fallback = "") => {

export default {
isProduction: getEnvValue("NODE_ENV", "production") === "production",
killSessionOnCloseEmbed: getEnvValue("VUE_APP_EMBED_KILL_SESSION_ON_CLOSE", false),
embed: {
isInitialStateOpen: getEnvValue("VUE_APP_EMBED_INITIAL_STATE_OPEN", false),
showCloseButton: getEnvValue("VUE_APP_EMBED_SHOW_CLOSE_BUTTON", true),
killSessionOnCloseEmbed: getEnvValue("VUE_APP_EMBED_KILL_SESSION_ON_CLOSE", false)
},
solutionConfig: {
buildConfig: getEnvValue("VUE_APP_SOLUTION_CONFIG", {})
},
Expand Down
2 changes: 1 addition & 1 deletion src/utils/postMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default class PostMessage {
this.store.commit("HIDE_CHAT_WINDOW_DISPLAY_EMBED");
setTimeout(
function () {
if (this.config.EMBED && window.leopardConfig.killSessionOnCloseEmbed) {
if (this.config.EMBED && window.leopardConfig.embed.killSessionOnCloseEmbed) {
// should kill the session and clear dialog history
logger.info("Killing Teneo Session");
this.store.dispatch("endSession");
Expand Down

0 comments on commit 6dae7a4

Please sign in to comment.