if (!window.oswaldLoaded) { window.oswaldLoaded = true; var oswaldBackendSession = "3c2d5231-d79e-4b4a-99f7-0322072456a9"; var apiUrl = "https://api.oswald.ai"; var time = new Date().getTime(); var matchWindowWidth = window.matchMedia("(max-width: 471px)"); var matchWindowHeight = window.matchMedia("(max-height: 800px)"); var SSOCookie = "SSOOswaldAccessToken"; var UserReferenceCookie = "oswaldAcertaReferenceCookie"; var oswaldIframe = document.createElement("iframe"); oswaldIframe.src = "https://widget.oswald.ai/widget?time=" + time; if ("" === "true") { oswaldIframe.src = oswaldIframe.src + "&noClose=true"; } var oswaldSession = ""; var oswaldBubbleIframe = document.createElement("iframe"); var oswaldCookieTtl = "1000"; var oswaldCookieTtlInt = parseInt(oswaldCookieTtl); var token = "ebc06fc5-58ab-49ca-b879-4f264d2d9bf2"; if ( token && ((token !== "ac213f95-729d-4efb-84a9-2ec246e9bb1f" && token !== "cbf5c5e1-7fa9-4c1f-8f8a-cab32c231861") || token !== "e19d47a6-6e83-43c2-a177-50b332d5411a" || token !== "23ffb67c-8fdd-49ac-aa7f-7afedda1305f") ) { if (oswaldSession.length === 0 && oswaldCookieTtlInt > 0) { if (token === "49e087ef-749f-4a13-9680-ea3613d2c33d") { var d = new Date(); var h = d.getHours(); var m = d.getMinutes(); var s = d.getSeconds(); var secondsUntilEndOfDate = 24 * 60 * 60 - h * 60 * 60 - (m + d.getTimezoneOffset()) * 60 - s; oswaldCookieTtl = secondsUntilEndOfDate.toString(); } var oswaldCookieValue = ( document.cookie.split("; ").find(function (row) { return row.indexOf("oswaldSession=") === 0; }) || "" ).split("=")[1]; oswaldSession = oswaldBackendSession; if (oswaldCookieValue) { oswaldSession = oswaldCookieValue; } else { document.cookie = "oswaldSession=" + oswaldSession + ";max-age=" + oswaldCookieTtl + ";secure;samesite=strict"; } } else if (oswaldSession.length === 0 && oswaldCookieTtlInt === 0) { var oswaldCookieValue = ( document.cookie.split("; ").find(function (row) { return row.indexOf("oswaldSession=") === 0; }) || "" ).split("=")[1]; oswaldSession = oswaldBackendSession; if (oswaldCookieValue) { oswaldSession = oswaldCookieValue; } else { document.cookie = "oswaldSession=" + oswaldSession + ";secure;samesite=strict"; } } else if (oswaldCookieTtlInt < 0) { document.cookie = "oswaldSession=" + oswaldBackendSession + ";max-age=0;secure;samesite=strict"; } } oswaldIframe.frameBorder = "0"; // Working in IE oswaldIframe.style.position = "fixed"; oswaldIframe.style.display = "none"; oswaldIframe.style.zIndex = "2147483646"; // Not working in IE oswaldIframe.style = "position: fixed; z-index: 2147483646; display: none;"; oswaldIframe.setAttribute("id", "oswald-widget"); var widgetComponentToAppend = oswaldIframe; if (false) { widgetComponentToAppend = document.createElement("div"); widgetComponentToAppend.setAttribute("id", "oswald-widget-wrapper"); widgetComponentToAppend.appendChild(oswaldIframe); } document.body.appendChild(widgetComponentToAppend); const checkIfSSOAcertaPermissionOrNot = function (token, oswaldBubbleIframe) { var userReference = "unknown"; if (token !== "49e087ef-749f-4a13-9680-ea3613d2c33d") { var referenceCookie = getCookie(UserReferenceCookie); if (referenceCookie) { userReference = referenceCookie; } } let acertaLanguage = ""; if (token) { acertaLanguage = getCookie("acertaLanguage"); if (acertaLanguage) { acertaLanguage = acertaLanguage.replace(/_.*/, ""); } else { acertaLanguage = navigator.language || navigator.userLanguage; acertaLanguage = acertaLanguage.replace(/-.*/, ""); if ( acertaLanguage !== "en" && acertaLanguage !== "nl" && acertaLanguage !== "fr" ) { acertaLanguage = "nl"; } } } if (oswaldSession) { oswaldBubbleIframe.src = `https://api.oswald.ai/api/v1/chats/${token}/sessions/${oswaldSession}/oauth2/sso/${userReference}?locale=${acertaLanguage}`; } else { oswaldBubbleIframe.src = `https://api.oswald.ai/api/v1/chats/${token}/sessions/${oswaldBackendSession}/oauth2/sso/${userReference}`; } if (token) { fetch(oswaldBubbleIframe.src) .then((resp) => { return resp.json(); }) .then((resp) => { oswaldBubbleIframe.src = resp; oswaldAppendBubble(oswaldBubbleIframe); }); return; } else { oswaldAppendBubble(oswaldBubbleIframe); } }; oswaldBubbleIframe.src = `https://widget.oswald.ai/bubble?token=${token}&startCommand=&startCommandOnLoad=&locale=nl&open=false&session=` + oswaldSession + "&feedback=&forceStartCommand=false&env=production&time=" + time; if (token && isAcertaToken(token)) { checkIfSSOAcertaPermissionOrNot(token, oswaldBubbleIframe); } else if (token && isHelanToken(token)) { oswaldAppendBubble(oswaldBubbleIframe); const sso = `https://api.oswald.ai/api/v1/chats/${token}/sessions/${oswaldSession}/oauth2/forgerock/sso?locale=en`; fetch(sso) .then((resp) => { return resp.json(); }) .then((resp) => { if (resp && resp.includes("ai/bubble")) { // oswaldBubbleIframe.src = resp; // oswaldAppendBubble(oswaldBubbleIframe); } else { const popUp = window.open( resp, "_blank", "location=yes,height=570,width=520,scrollbars=yes,status=yes" ); var timer = setInterval(function () { if (popUp.closed) { // if something should happen after modal is closed. clearInterval(timer); // console.log("closed"); } else { // console.log("open"); } }, 500); } }); } else { oswaldAppendBubble(oswaldBubbleIframe); } function oswaldAppendBubble(oswaldBubbleIframe) { oswaldBubbleIframe.frameBorder = "0"; oswaldBubbleIframe.width = "120px"; oswaldBubbleIframe.height = "100px"; // Working in IEdr oswaldBubbleIframe.style.position = "fixed"; oswaldBubbleIframe.style.right = "0"; oswaldBubbleIframe.style.bottom = "50px"; oswaldBubbleIframe.style.zIndex = "2147483645"; // Not working in IE oswaldBubbleIframe.style = "position: fixed; right:0; bottom:50px; z-index: 2147483645; border:none;"; oswaldBubbleIframe.setAttribute("id", "oswald-widget-bubble"); var bubbleComponentToAppend = oswaldBubbleIframe; if (false) { bubbleComponentToAppend = document.createElement("div"); bubbleComponentToAppend.setAttribute("id", "oswald-bubble-wrapper"); bubbleComponentToAppend.appendChild(oswaldBubbleIframe); } document.body.appendChild(bubbleComponentToAppend); } var windowSizer = function () { var width = Math.min(470, window.innerWidth) + "px", height = "690px", bottom = "120px", right = "0px", bubbleBottom = "20px"; if (matchWindowHeight.matches) { bottom = "70px"; right = "50px"; bubbleBottom = "0px"; height = "85%"; } if (matchWindowWidth.matches) { width = "100%"; height = "100%"; bottom = "0px"; right = "0px"; } oswaldIframe.style.width = width; oswaldIframe.style.height = height; oswaldIframe.style.bottom = bottom; oswaldIframe.style.right = right; oswaldBubbleIframe.style.bottom = bubbleBottom; }; window.addEventListener("resize", windowSizer); windowSizer(); function oswaldAddStylesheetFromString(rule) { var css = document.createElement("style"); css.type = "text/css"; if (css.styleSheet) { // Support for IE css.styleSheet.cssText = rule; } else { // Support for the rest css.appendChild(document.createTextNode(rule)); } document.getElementsByTagName("head")[0].appendChild(css); } // fix for webkit not notifying code-created iframes about unload... window.addEventListener("beforeunload", function () { document.getElementById("oswald-widget").setAttribute("src", ""); }); function sendCurrentUrlToOswald() { document.getElementById("oswald-widget").contentWindow.postMessage( { eventName: "oswald-host-url", oswaldData: { url: "" + window.location, }, }, "*" ); } function checkForOauthQueryParam() { if (typeof URLSearchParams !== "undefined") { const params = new URLSearchParams(window.location.search); if (params.get("oauth")) { params.delete("session"); params.delete("oauth"); if (window.history.replaceState) { var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + "?" + params.toString(); console.warn(`New url will be: ${newurl}`); window.history.pushState({ path: newurl }, "", newurl); } } } } function checkForCookieAndSent() { var cookie = getCookie(SSOCookie); if (cookie) { document.getElementById("oswald-widget").contentWindow.postMessage( { eventName: "oswald-get-sso-cookie", cookie: cookie, }, "*" ); } } function URLSanitizer(url, onSuccess, onFail) { const sanitizerUrl = `${apiUrl}/api/v1/chats/urlValidate?url=${url}&chatbotId=${token}`; const t = new XMLHttpRequest(); t.open("GET", sanitizerUrl); t.onreadystatechange = function () { if ( ((t.status >= 200 && t.status <= 299) || t.status === 304) && t.response ) { onSuccess(t.response); } else if (t.status >= 300) { onFail(); } }; t.send(null); } function setCookie(variable, value, expires_seconds) { var cd = new Date(); cd = new Date(d.getTime() + 1000 * expires_seconds); document.cookie = variable + "=" + value + ";secure;samesite=strict;expires=" + cd.toGMTString() + ";"; } function getCookie(name) { const value = `; ${document.cookie}`; const parts = value.split(`; ${name}=`); if (parts.length === 2) return parts.pop().split(";").shift(); } window.addEventListener("locationchange", function (event) { sendCurrentUrlToOswald(); }); // Sanitize function const sanitizeUserInput = (input) => { // Escape special characters: { } ; @ return input .replace(/[{]/g, "\\{") .replace(/[}]/g, "\\}") .replace(/[;]/g, "\\;") .replace(/[@]/g, "\\@"); }; window.addEventListener( "message", function (event) { if (event.data.eventName === "update-oswald-config") { var oswaldHostCss = event.data.oswaldData && event.data.oswaldData.widget && event.data.oswaldData.widget.hostCss; if (oswaldHostCss) { oswaldAddStylesheetFromString(sanitizeCss(oswaldHostCss)); } document .getElementById("oswald-widget") .contentWindow.postMessage(event.data, "*"); } else if (event.data.eventName === "oswald-open-iframe") { document.getElementById("oswald-widget").style.display = "block"; document.getElementById("oswald-widget").contentWindow.postMessage( { eventName: "oswald-open-widget", widgetClosed: false, }, "*" ); } else if (event.data.eventName === "oswald-session-change") { document .getElementById("oswald-widget-bubble") .contentWindow.postMessage( { eventName: "oswald-session-change", data: event.data.data, }, "*" ); } else if (event.data.eventName === "oswald-close-iframe") { document.getElementById("oswald-widget").style.display = "none"; document.getElementById("oswald-widget").contentWindow.postMessage( { eventName: "oswald-close-widget", widgetClosed: true, }, "*" ); } else if (event.data.eventName === "oswald-iframe-closed") { document.getElementById("oswald-widget").style.display = "none"; document .getElementById("oswald-widget-bubble") .contentWindow.postMessage( { eventName: "oswald-iframe-closed", widgetClosed: true, }, "*" ); } else if (event.data.eventName === "oswald-cookie-return") { checkForCookieAndSent(); } else if (event.data.eventName === "oswald-widget-ready") { window.oswaldWidgetReady = true; document .getElementById("oswald-widget-bubble") .contentWindow.postMessage( { eventName: "oswald-widget-loaded" }, "*" ); sendCurrentUrlToOswald(); checkForOauthQueryParam(); } else if (event.data.eventName === "oswald-widget-initialised") { if (event.data.bubbleReady) { this.bubbleReady = true; } if (event.data.widgetReady) { this.widgetReady = true; } if (this.widgetReady && this.bubbleReady) { document .getElementById("oswald-widget-bubble") .contentWindow.postMessage( { eventName: "oswald-widget-initialised" }, "*" ); } } else if (event.data.eventName === "oswald-set-sso-cookie") { setCookie(SSOCookie, event.data.oswaldData); } else if (event.data.eventName === "oswald-user-reference-cookie") { setCookie(UserReferenceCookie, event.data.oswaldData); } else if ( event.data.eventName === "oswald-authorization-redirect" && event.data.data && typeof event.data.data === "string" ) { URLSanitizer( event.data.data, (url) => (window.location.href = url), () => { // something went wrong how should we handle it? } ); } }, true ); if (window.history) { window.history.pushState = (function (f) { return function pushState() { var ret = f.apply(this, arguments); window.dispatchEvent(new Event("locationchange")); return ret; }; })(window.history.pushState); window.history.replaceState = (function (f) { return function replaceState() { var ret = f.apply(this, arguments); window.dispatchEvent(new Event("locationchange")); return ret; }; })(window.history.replaceState); } window.addEventListener("popstate", function () { window.dispatchEvent(new Event("locationchange")); }); } function isAcertaToken(token) { return ( token === "ac213f95-729d-4efb-84a9-2ec246e9bb1f" || token === "cbf5c5e1-7fa9-4c1f-8f8a-cab32c231861" || token === "e19d47a6-6e83-43c2-a177-50b332d5411a" || token === "49e087ef-749f-4a13-9680-ea3613d2c33d" || token === "23ffb67c-8fdd-49ac-aa7f-7afedda1305f" ); } function isHelanToken(token) { return ( token === "0c86a312-02d8-4c88-9cc3-978890e5ca2c" || token === "f01e0e85-e63a-4467-b432-3df0e4165dfc" || token === "9c6a626e-836d-438b-846a-4189f3949baa" ); } // TODO: find a better way function sanitizeCss(css) { // Create a temporary style element var style = document.createElement("style"); style.textContent = css; // Append it to the document head (this won't affect the page styles yet) document.head.appendChild(style); // Access the CSS rules parsed by the browser var sheet = style.sheet; var rules = sheet.cssRules || sheet.rules; // Iterate over the rules and remove any @import rules for (var i = rules.length - 1; i >= 0; i--) { if (rules[i].type === CSSRule.IMPORT_RULE) { sheet.deleteRule(i); } } // Extract the sanitized CSS from the remaining rules var sanitizedCss = ""; for (var i = 0; i < rules.length; i++) { sanitizedCss += rules[i].cssText + "\n"; } // Clean up by removing the temporary style element document.head.removeChild(style); return sanitizedCss; }