@botfabrik/engine-webclient 4.122.0 → 4.123.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -3
- package/dist/client/assets/{index-u0WiQbPl.js → index-CxHubEDR.js} +22 -22
- package/dist/client/assets/{index-u0WiQbPl.js.map → index-CxHubEDR.js.map} +1 -1
- package/dist/client/index.html +1 -1
- package/dist/embed/bundle.js +1 -1
- package/dist/index.js +9 -7
- package/dist/types.d.ts +7 -8
- package/package.json +5 -5
package/dist/client/index.html
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
<meta name="theme-color" content="#000000" />
|
|
14
14
|
<meta name="google" content="notranslate" />
|
|
15
15
|
<title>Bubble Chat Client</title>
|
|
16
|
-
<script type="module" crossorigin src="./assets/index-
|
|
16
|
+
<script type="module" crossorigin src="./assets/index-CxHubEDR.js"></script>
|
|
17
17
|
<link rel="stylesheet" crossorigin href="./assets/index-Q0uFG8V2.css">
|
|
18
18
|
</head>
|
|
19
19
|
|
package/dist/embed/bundle.js
CHANGED
|
@@ -29,4 +29,4 @@
|
|
|
29
29
|
|
|
30
30
|
@media screen and (min-width: 768px) {.chat-button-wrapper.svelte-1xi58vz {top:var(--fab-top, auto);right:var(--fab-right, 1.5em);bottom:var(--fab-bottom, 1.5em);left:var(--fab-left, auto);width:var(--fab-width, var(--fab-size, 6em));height:var(--fab-height, var(--fab-size, 6em));}
|
|
31
31
|
}.chat-button.svelte-1xi58vz {display:block;height:100%;cursor:pointer;border-radius:50%;box-shadow:9px 9px 16px rgba(0, 0, 0, 0.25);transition:transform 100ms,
|
|
32
|
-
box-shadow 100ms;}.chat-button.svelte-1xi58vz:hover {box-shadow:16px 16px 16px rgba(0, 0, 0, 0.2);transform:translateY(-2px);}`};function Ir(e,t){qe(t,!0),gr(e,Fr);function n(e){let n=e.key;(n===`ArrowDown`||n===`ArrowRight`||n===`Enter`||n===` `||n===`Space`)&&(e.stopPropagation(),t.onToggle())}var r=Pr(),i=en(r);Re(r),vn(()=>{Cr(r,`aria-expanded`,t.open?`true`:`false`),Cr(i,`src`,`${t.assetsUrl}/fab.svg`)}),Qn(`click`,r,function(...e){t.onToggle?.apply(this,e)}),Qn(`keydown`,r,n),cr(e,r),Je()}$n([`click`,`keydown`]);var Lr=!1;function Rr(e){Lr=e}function zr(){return Lr}function Br(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)r!==`__proto__`&&(e[r]=n[r])}return e}var Vr={read:function(e){return e[0]===`"`&&(e=e.slice(1,-1)),e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}};function Hr(e,t){function n(n,r,i){if(!(typeof document>`u`)){i=Br({},t,i),typeof i.expires==`number`&&(i.expires=new Date(Date.now()+i.expires*864e5)),i.expires&&=i.expires.toUTCString(),n=encodeURIComponent(n).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var a=``;for(var o in i)i[o]&&(a+=`; `+o,i[o]!==!0&&(a+=`=`+i[o].split(`;`)[0]));return document.cookie=n+`=`+e.write(r,n)+a}}function r(t){if(!(typeof document>`u`||arguments.length&&!t)){for(var n=document.cookie?document.cookie.split(`; `):[],r={},i=0;i<n.length;i++){var a=n[i].split(`=`),o=a.slice(1).join(`=`);try{var s=decodeURIComponent(a[0]);if(s in r||(r[s]=e.read(o,s)),t===s)break}catch{}}return t?r[t]:r}}return Object.create({set:n,get:r,remove:function(e,t){n(e,``,Br({},t,{expires:-1}))},withAttributes:function(e){return Hr(this.converter,Br({},this.attributes,e))},withConverter:function(e){return Hr(Br({},this.converter,e),this.attributes)}},{attributes:{value:Object.freeze(t)},converter:{value:Object.freeze(e)}})}var Ur=Hr(Vr,{path:`/`}),Wr=`bubble-chat-window-state`,Gr=()=>{switch(Ur.get(Wr)){case`open`:return!0;case`closed`:return!1;default:return}},Kr=e=>{let t=new Date(new Date().getTime()+480*60*1e3);Ur.set(Wr,e,{expires:t})},qr=t({closeChatWindow:()=>Zr,enterGuestMessage:()=>ei,isChatbotLoaded:()=>zr,openChatWindow:()=>Xr,restartChat:()=>$r,subscribe:()=>ai,toggleChatWindow:()=>Qr,triggerStory:()=>ti}),Jr=[],Yr=Gr();function Xr(){Yr=!0,Kr(`open`),Jr.forEach(function(e){e.call(window,!0)})}function Zr(){Yr=!1,Kr(`closed`),Jr.forEach(function(e){e.call(window,!1)})}function Qr(){Yr?Zr():Xr()}function $r(){ii({type:`RESTART_CHAT`})}function ei(e){ii({type:`CHAT_MESSAGE_FROM_GUEST`,text:e})}function ti(e){ii({type:`TRIGGER_STORY`,story:e})}function ni(){return document.getElementById(`chat-frame`)}function ri(){let e=ni();if(e?.src)try{return new URL(e.src).origin}catch{return null}return null}function ii(e){let t=ni(),n=ri();if(!n){console.warn(`Cannot send message: chat iframe origin could not be determined`);return}t?.contentWindow?.postMessage(e,n)}function ai(e,t){switch(e){case`ON_CHAT_WINDOW_STATE_CHANGE`:Jr.push(t);break;default:throw Error(`Unsupported event `+e)}}var oi=e=>{if(!e||typeof e!=`object`||Array.isArray(e)){console.warn(`Invalid tracking payload received:`,e);return}`gtag`in window&&typeof window.gtag==`function`?window.gtag(`event`,``,e):`dataLayer`in window&&Array.isArray(window.dataLayer)&&window.dataLayer.push(e)},si=(e,t,n,r,i)=>{let a=()=>{let e=document.getElementById(`chat-frame`);if(e?.src)try{return new URL(e.src).origin}catch{return null}return null},o={CHAT_STARTED:`webclient.chat.started`,CHAT_ENDED:`webclient.chat.ended`,WINDOW_EXPAND:`webclient.window.expand`,WINDOW_CLOSE:`webclient.window.close`,CHANGE_URL:`webclient.change.url`,GOOGLE_TAG_EVENT:`google.tag.event`},s=Object.values(o);window.addEventListener(`message`,c=>{if(!c.data?.type||!s.includes(c.data.type))return;let l=a();if(l&&c.origin!==l){console.warn(`Rejected postMessage from untrusted origin:`,c.origin);return}let u=c.data;switch(u.type){case o.CHAT_STARTED:e();break;case o.CHAT_ENDED:t();break;case o.WINDOW_EXPAND:n(u.devices,u.initial);break;case o.WINDOW_CLOSE:r();break;case o.CHANGE_URL:i(u.url);break;case o.GOOGLE_TAG_EVENT:oi(u.payload);break;default:break}},!1)},ci=e=>new Promise(t=>{let n=document.getElementById(e);n?(n.onload=()=>{t(!0)},n.onerror=()=>{console.error(`Failed to load CSS file: custom.css`),t(!1)}):(console.error(`No custom.css file found`),t(!1))}),li=or(`<link rel="stylesheet"/>`),ui=or(`<div><!> <!></div>`),di={hash:`svelte-1n46o8q`,code:`.bubble-chat.svelte-1n46o8q {font-size:16px;visibility:hidden;opacity:0;}.bubble-chat.chatbot-ready.svelte-1n46o8q {visibility:visible;opacity:1;}`};function fi(e,t){qe(t,!0),gr(e,di);let n=`chatbot-style`,r=Dr(t,`assetsUrl`,19,()=>t.server?t.server.split(`?`)[0]:void 0),i=Dr(t,`linkHandling`,3,`default`),a=Dr(t,`chatStarted`,7,!1),o=Dr(t,`expandChatWindowAtStart`,3,null),s=N(!1),
|
|
32
|
+
box-shadow 100ms;}.chat-button.svelte-1xi58vz:hover {box-shadow:16px 16px 16px rgba(0, 0, 0, 0.2);transform:translateY(-2px);}`};function Ir(e,t){qe(t,!0),gr(e,Fr);function n(e){let n=e.key;(n===`ArrowDown`||n===`ArrowRight`||n===`Enter`||n===` `||n===`Space`)&&(e.stopPropagation(),t.onToggle())}var r=Pr(),i=en(r);Re(r),vn(()=>{Cr(r,`aria-expanded`,t.open?`true`:`false`),Cr(i,`src`,`${t.assetsUrl}/fab.svg`)}),Qn(`click`,r,function(...e){t.onToggle?.apply(this,e)}),Qn(`keydown`,r,n),cr(e,r),Je()}$n([`click`,`keydown`]);var Lr=!1;function Rr(e){Lr=e}function zr(){return Lr}function Br(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)r!==`__proto__`&&(e[r]=n[r])}return e}var Vr={read:function(e){return e[0]===`"`&&(e=e.slice(1,-1)),e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}};function Hr(e,t){function n(n,r,i){if(!(typeof document>`u`)){i=Br({},t,i),typeof i.expires==`number`&&(i.expires=new Date(Date.now()+i.expires*864e5)),i.expires&&=i.expires.toUTCString(),n=encodeURIComponent(n).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var a=``;for(var o in i)i[o]&&(a+=`; `+o,i[o]!==!0&&(a+=`=`+i[o].split(`;`)[0]));return document.cookie=n+`=`+e.write(r,n)+a}}function r(t){if(!(typeof document>`u`||arguments.length&&!t)){for(var n=document.cookie?document.cookie.split(`; `):[],r={},i=0;i<n.length;i++){var a=n[i].split(`=`),o=a.slice(1).join(`=`);try{var s=decodeURIComponent(a[0]);if(s in r||(r[s]=e.read(o,s)),t===s)break}catch{}}return t?r[t]:r}}return Object.create({set:n,get:r,remove:function(e,t){n(e,``,Br({},t,{expires:-1}))},withAttributes:function(e){return Hr(this.converter,Br({},this.attributes,e))},withConverter:function(e){return Hr(Br({},this.converter,e),this.attributes)}},{attributes:{value:Object.freeze(t)},converter:{value:Object.freeze(e)}})}var Ur=Hr(Vr,{path:`/`}),Wr=`bubble-chat-window-state`,Gr=()=>{switch(Ur.get(Wr)){case`open`:return!0;case`closed`:return!1;default:return}},Kr=e=>{let t=new Date(new Date().getTime()+480*60*1e3);Ur.set(Wr,e,{expires:t})},qr=t({closeChatWindow:()=>Zr,enterGuestMessage:()=>ei,isChatbotLoaded:()=>zr,openChatWindow:()=>Xr,restartChat:()=>$r,subscribe:()=>ai,toggleChatWindow:()=>Qr,triggerStory:()=>ti}),Jr=[],Yr=Gr();function Xr(){Yr=!0,Kr(`open`),Jr.forEach(function(e){e.call(window,!0)})}function Zr(){Yr=!1,Kr(`closed`),Jr.forEach(function(e){e.call(window,!1)})}function Qr(){Yr?Zr():Xr()}function $r(){ii({type:`RESTART_CHAT`})}function ei(e){ii({type:`CHAT_MESSAGE_FROM_GUEST`,text:e})}function ti(e){ii({type:`TRIGGER_STORY`,story:e})}function ni(){return document.getElementById(`chat-frame`)}function ri(){let e=ni();if(e?.src)try{return new URL(e.src).origin}catch{return null}return null}function ii(e){let t=ni(),n=ri();if(!n){console.warn(`Cannot send message: chat iframe origin could not be determined`);return}t?.contentWindow?.postMessage(e,n)}function ai(e,t){switch(e){case`ON_CHAT_WINDOW_STATE_CHANGE`:Jr.push(t);break;default:throw Error(`Unsupported event `+e)}}var oi=e=>{if(!e||typeof e!=`object`||Array.isArray(e)){console.warn(`Invalid tracking payload received:`,e);return}`gtag`in window&&typeof window.gtag==`function`?window.gtag(`event`,``,e):`dataLayer`in window&&Array.isArray(window.dataLayer)&&window.dataLayer.push(e)},si=(e,t,n,r,i)=>{let a=()=>{let e=document.getElementById(`chat-frame`);if(e?.src)try{return new URL(e.src).origin}catch{return null}return null},o={CHAT_STARTED:`webclient.chat.started`,CHAT_ENDED:`webclient.chat.ended`,WINDOW_EXPAND:`webclient.window.expand`,WINDOW_CLOSE:`webclient.window.close`,CHANGE_URL:`webclient.change.url`,GOOGLE_TAG_EVENT:`google.tag.event`},s=Object.values(o);window.addEventListener(`message`,c=>{if(!c.data?.type||!s.includes(c.data.type))return;let l=a();if(l&&c.origin!==l){console.warn(`Rejected postMessage from untrusted origin:`,c.origin);return}let u=c.data;switch(u.type){case o.CHAT_STARTED:e();break;case o.CHAT_ENDED:t();break;case o.WINDOW_EXPAND:n(u.devices,u.initial);break;case o.WINDOW_CLOSE:r();break;case o.CHANGE_URL:i(u.url);break;case o.GOOGLE_TAG_EVENT:oi(u.payload);break;default:break}},!1)},ci=e=>new Promise(t=>{let n=document.getElementById(e);n?(n.onload=()=>{t(!0)},n.onerror=()=>{console.error(`Failed to load CSS file: custom.css`),t(!1)}):(console.error(`No custom.css file found`),t(!1))}),li=or(`<link rel="stylesheet"/>`),ui=or(`<div><!> <!></div>`),di={hash:`svelte-1n46o8q`,code:`.bubble-chat.svelte-1n46o8q {font-size:16px;visibility:hidden;opacity:0;}.bubble-chat.chatbot-ready.svelte-1n46o8q {visibility:visible;opacity:1;}`};function fi(e,t){qe(t,!0),gr(e,di);let n=`chatbot-style`,r=Dr(t,`assetsUrl`,19,()=>t.server?t.server.split(`?`)[0]:void 0),i=Dr(t,`linkHandling`,3,`default`),a=Dr(t,`chatStarted`,7,!1),o=Dr(t,`expandChatWindowAtStart`,3,null),s=Dr(t,`fabVisible`,3,!0),c=N(!1),l=N(!1),u=N(F(Gr()));ai(`ON_CHAT_WINDOW_STATE_CHANGE`,function(e){P(u,e,!0)});function d(){a(!0)}function f(){a(!1)}function p(e,t){let n=window.innerWidth,r=e==null||e===`all`||e===`desktop`&&n>=768||e===`mobile`&&n<768;(!t||$(u)!==!1)&&r&&Xr()}function m(){Zr()}function h(e){let t=window.innerWidth,n=window.location.hostname===new URL(e).hostname;t<768&&Zr(),i()===`new-tab`?window.open(e,`_blank`):i()===`existing-tab`||n?document.location.href=e:window.open(e,`_blank`)}function g(){P(l,!0)}si(d,f,p,m,h),fn(()=>{let e=window.innerWidth<768;if($(u)&&e){let e=window.scrollY,t=document.body.style.position,n=document.body.style.width,r=document.body.style.overflow,i=document.body.style.top;return document.body.style.position=`fixed`,document.body.style.width=`100%`,document.body.style.overflow=`hidden`,document.body.style.top=`-${e}px`,()=>{document.body.style.position=t,document.body.style.width=n,document.body.style.overflow=r,document.body.style.top=i,window.scrollTo(0,e)}}}),Or(async()=>{if(P(c,await ci(n),!0),o()&&$(u)!==!1){let e=window.innerWidth,t=o()===`all`,n=o()===`desktop`&&e>=768,r=o()===`mobile`&&e<768;(t||n||r)&&Xr()}});var _=ui();hr(`1n46o8q`,e=>{var t=li();Cr(t,`id`,n),vn(()=>Cr(t,`href`,`${r()}/custom.css`)),cr(e,t)});var v=en(_),y=e=>{Ir(e,{get assetsUrl(){return r()},get open(){return $(u)},get onToggle(){return Qr}})};mr(v,e=>{s()&&e(y)}),Nr(nn(v,2),{get server(){return t.server},get referrer(){return t.referrer},get open(){return $(u)},onLoad:g}),Re(_),vn(()=>yr(_,1,`bubble-chat ${$(c)&&$(l)?`chatbot-ready`:``}`,`svelte-1n46o8q`)),cr(e,_),Je()}var pi=e=>e.replace(/\/embed\/bundle\.js/,``),mi=e=>e.dataset?.server,hi=e=>{if(e&&`src`in e&&typeof e.src==`string`)return mi(e)||pi(e.src)},gi=document.querySelector(`script#chatbot`),_i=hi(gi),vi=gi?.getAttribute(`data-link-handling`)?gi.getAttribute(`data-link-handling`):`default`,yi=gi?.getAttribute(`data-expand-at-start`)?gi.getAttribute(`data-expand-at-start`):null,bi=gi?.getAttribute(`data-fab-visible`)!==`false`;window.chatbot=qr;var xi=()=>{console.log(`Chatbot is loading from`,_i),lr(fi,{target:document.body,props:{server:_i,referrer:window.location.href,linkHandling:vi,expandChatWindowAtStart:yi,fabVisible:bi}}),Rr(!0)},Si=(e=0)=>{e>=3||document.readyState===`complete`?setTimeout(xi,500):setTimeout(()=>{Si(e+1)},500)};Si();var Ci=document.getElementById(`chatbot`);Ci&&`src`in Ci&&typeof Ci.src==`string`&&Ci.src.indexOf(`caller=bookmarklet`)>0&&setTimeout(xi,500)})();
|
package/dist/index.js
CHANGED
|
@@ -56,17 +56,17 @@ export default (clientName, environment, props) => async (bot) => {
|
|
|
56
56
|
res.write(index(serverUrl.toString(), `${server}/embed/bundle.js`));
|
|
57
57
|
res.end();
|
|
58
58
|
});
|
|
59
|
-
if (
|
|
59
|
+
if (isConditionallyEnabled(props)) {
|
|
60
60
|
router.get('/embed/bundle.js', (req, res) => {
|
|
61
61
|
const caller = req.query['caller'];
|
|
62
62
|
const referer = req.get('referer')?.toLowerCase();
|
|
63
|
-
const
|
|
64
|
-
? props.
|
|
63
|
+
const enabledUrls = Array.isArray(props.enabledOnUrls)
|
|
64
|
+
? props.enabledOnUrls
|
|
65
65
|
: [];
|
|
66
66
|
const isEmbedPage = !!referer?.startsWith(bot.webserver.baseUrl.toLowerCase());
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
if (caller === 'bookmarklet' ||
|
|
67
|
+
const isUrlEnabled = isEmbedPage ||
|
|
68
|
+
enabledUrls.some((url) => referer?.startsWith(url.toLowerCase()));
|
|
69
|
+
if (caller === 'bookmarklet' || isUrlEnabled) {
|
|
70
70
|
res.sendFile(`${__dirname}/embed/bundle.js`);
|
|
71
71
|
}
|
|
72
72
|
else {
|
|
@@ -154,7 +154,9 @@ const serveStaticOptions = {
|
|
|
154
154
|
}
|
|
155
155
|
},
|
|
156
156
|
};
|
|
157
|
-
const
|
|
157
|
+
const isConditionallyEnabled = ({ enabledOnUrls = true }) => {
|
|
158
|
+
return enabledOnUrls !== true;
|
|
159
|
+
};
|
|
158
160
|
const onTerminateSession = (socket, bot) => async ({ sessionId, // passed if the user wants to restart the chat
|
|
159
161
|
}) => {
|
|
160
162
|
const session = await bot.createSession(sessionId);
|
package/dist/types.d.ts
CHANGED
|
@@ -115,18 +115,17 @@ export interface WebClientProps {
|
|
|
115
115
|
speech?: SpeechToTextProps | undefined;
|
|
116
116
|
expandChatWindowAtStart?: Devices;
|
|
117
117
|
/**
|
|
118
|
-
* Controls
|
|
118
|
+
* Controls on which pages the chatbot is enabled.
|
|
119
119
|
*
|
|
120
|
-
* - If set to `true
|
|
121
|
-
* - If set to `false`, the
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
* The FAB is always visible on the base URL pages and bookmarklet.
|
|
120
|
+
* - If set to `true` (default), the chatbot is enabled everywhere.
|
|
121
|
+
* - If set to `false`, the chatbot bundle is not served to external pages.
|
|
122
|
+
* It remains accessible via bookmarklet and the server's own embed page.
|
|
123
|
+
* - If set to an array of URL strings, the chatbot bundle is only served
|
|
124
|
+
* when the embedding page's URL starts with one of the given strings.
|
|
126
125
|
*
|
|
127
126
|
* @default true
|
|
128
127
|
*/
|
|
129
|
-
|
|
128
|
+
enabledOnUrls?: boolean | string[];
|
|
130
129
|
/**
|
|
131
130
|
* SAML authentication configuration for the web client.
|
|
132
131
|
* If set, users must authenticate via SAML before accessing the chat.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botfabrik/engine-webclient",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.123.0",
|
|
4
4
|
"description": "Webclient for Botfabriks Bot Engine",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
"dev:embed": "tsx --watch ./run-embed-local.ts"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@botfabrik/engine-domain": "^4.
|
|
35
|
-
"@botfabrik/engine-transcript-export": "^4.
|
|
36
|
-
"@botfabrik/engine-utils": "^4.
|
|
34
|
+
"@botfabrik/engine-domain": "^4.122.1",
|
|
35
|
+
"@botfabrik/engine-transcript-export": "^4.122.1",
|
|
36
|
+
"@botfabrik/engine-utils": "^4.122.1",
|
|
37
37
|
"@google-cloud/speech": "^7.3.1",
|
|
38
38
|
"@node-saml/passport-saml": "^5.1.0",
|
|
39
39
|
"@types/cors": "^2.8.19",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"tsx": "^4.22.3",
|
|
56
56
|
"typescript": "6.0.3"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "cfec83549c767f687e065e9c679e8f0712f9050c"
|
|
59
59
|
}
|