@botfabrik/engine-webclient 4.65.2 → 4.66.1
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 +8 -0
- package/dist/client/assets/index-Bv7hr1lr.css +1 -0
- package/dist/client/assets/index-DalAsBxv.js +111 -0
- package/dist/client/assets/index-DalAsBxv.js.map +1 -0
- package/dist/client/custom.css +21 -0
- package/dist/client/fab.svg +1 -1
- package/dist/client/index.html +3 -3
- package/dist/client/manifest.json +1 -1
- package/dist/createSessionInfo.d.ts +1 -1
- package/dist/createSessionInfo.js +3 -4
- package/dist/createSessionInfo.test.js +6 -9
- package/dist/embed/bundle.js +11 -11
- package/dist/index.d.ts +5 -1
- package/dist/index.js +96 -86
- package/dist/requestSessionData.d.ts +1 -1
- package/dist/requestSessionData.js +10 -7
- package/dist/requestSessionData.test.js +12 -7
- package/package.json +5 -5
- package/dist/client/assets/index-CtRHUofL.js +0 -111
- package/dist/client/assets/index-CtRHUofL.js.map +0 -1
- package/dist/client/assets/index-vVZBi9_F.css +0 -1
package/dist/client/custom.css
CHANGED
|
@@ -2,3 +2,24 @@
|
|
|
2
2
|
* Das Aussehen des Webclients kann für jedes Projekt übersteuert werden.
|
|
3
3
|
* Dazu kann eine eigene CSS Datei namens 'custom.css' im Verzeichnis 'public/${name-meines-webclients}/' abgelegt werden.
|
|
4
4
|
*/
|
|
5
|
+
|
|
6
|
+
@import url(//fonts.googleapis.com/css?family=Roboto:400,300,700,500,100,200);
|
|
7
|
+
|
|
8
|
+
.bubble-chat {
|
|
9
|
+
/* common */
|
|
10
|
+
--brand-primary-color: rgb(6, 48, 98);
|
|
11
|
+
--brand-secondary-color: white;
|
|
12
|
+
--danger-color: #cd2147;
|
|
13
|
+
|
|
14
|
+
/* chat window */
|
|
15
|
+
--header-background-color: var(--brand-primary-color);
|
|
16
|
+
|
|
17
|
+
/* chat body */
|
|
18
|
+
--body-background-color: rgb(234, 238, 243);
|
|
19
|
+
--bot-bubble-border-width: 0;
|
|
20
|
+
--bot-avatar-background-color: white;
|
|
21
|
+
--guest-bubble-border-width: 0;
|
|
22
|
+
--agent-avatar-background-color: white;
|
|
23
|
+
|
|
24
|
+
font-family: 'Roboto', sans-serif;
|
|
25
|
+
}
|
package/dist/client/fab.svg
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
</g>
|
|
7
7
|
<g>
|
|
8
8
|
<g transform="matrix(0.968573,0,0,0.968573,50.1659,47.2531)">
|
|
9
|
-
<path d="M1531.31,5.511C2393.48,5.511 3108.27,705.64 3126.5,1568C3144.73,2430.38 2459.57,3130.51 1597.4,3130.51C735.231,3130.51 20.46,2430.38 2.21,1568C-16.022,705.638 669.138,5.511 1531.31,5.511Z" style="fill:#
|
|
9
|
+
<path d="M1531.31,5.511C2393.48,5.511 3108.27,705.64 3126.5,1568C3144.73,2430.38 2459.57,3130.51 1597.4,3130.51C735.231,3130.51 20.46,2430.38 2.21,1568C-16.022,705.638 669.138,5.511 1531.31,5.511Z" style="fill:#042f61;stroke:white;stroke-width:61.95px;"/>
|
|
10
10
|
</g>
|
|
11
11
|
<g transform="matrix(0.968573,0,0,0.968573,50.1659,47.2531)">
|
|
12
12
|
<path d="M1179.34,2536.02C1114.36,2559.92 1082.25,2566.64 1035.19,2566.64C977.681,2566.64 941.083,2526.31 940.336,2458.34C940.336,2382.91 976.187,2346.31 1041.91,2346.31C1076.27,2346.31 1109.13,2353.03 1167.39,2367.97L1208.47,2262.66C1152.45,2235.03 1093.45,2221.58 1035.94,2221.58C888.054,2221.58 799.175,2306.73 799.175,2458.34C799.175,2607.72 888.054,2691.37 1028.47,2691.37C1097.18,2691.37 1153.2,2676.43 1224.15,2639.84L1179.34,2536.02Z" style="fill:white;fill-rule:nonzero;"/>
|
package/dist/client/index.html
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<!doctype html>
|
|
2
|
-
<html lang="en" translate="no" class="notranslate">
|
|
2
|
+
<html lang="en" translate="no" class="notranslate bubble-chat">
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="utf-8" />
|
|
5
5
|
<link rel="icon" href="./favicon.ico" />
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
<meta name="theme-color" content="#000000" />
|
|
8
8
|
<meta name="google" content="notranslate" />
|
|
9
9
|
<title>Bubble Chat Client</title>
|
|
10
|
-
<script type="module" crossorigin src="./assets/index-
|
|
11
|
-
<link rel="stylesheet" crossorigin href="./assets/index-
|
|
10
|
+
<script type="module" crossorigin src="./assets/index-DalAsBxv.js"></script>
|
|
11
|
+
<link rel="stylesheet" crossorigin href="./assets/index-Bv7hr1lr.css">
|
|
12
12
|
</head>
|
|
13
13
|
|
|
14
14
|
<body>
|
|
@@ -3,5 +3,5 @@ import type { Environment } from '@botfabrik/engine-domain';
|
|
|
3
3
|
import type { Socket } from 'socket.io';
|
|
4
4
|
import { WebClientProps } from './index';
|
|
5
5
|
import type { SessionInfoClientPayload, SessionInfoUserPayload } from './types';
|
|
6
|
-
declare const createSessionInfo: (socket: Socket, clientName: string, environment: Environment, sessionInfo: SessionInfo<SessionInfoClientPayload, SessionInfoUserPayload>, locale: string | undefined, props: WebClientProps) => () => Promise<SessionInfo<SessionInfoClientPayload, SessionInfoUserPayload>>;
|
|
6
|
+
declare const createSessionInfo: (socket: Socket, clientName: string, environment: Environment, sessionInfo: SessionInfo<SessionInfoClientPayload, SessionInfoUserPayload>, userId: string, locale: string | undefined, props: WebClientProps) => () => Promise<SessionInfo<SessionInfoClientPayload, SessionInfoUserPayload>>;
|
|
7
7
|
export default createSessionInfo;
|
|
@@ -6,8 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const buildUserAgentInfos_1 = __importDefault(require("./buildUserAgentInfos"));
|
|
7
7
|
const extractIP_1 = __importDefault(require("./extractIP"));
|
|
8
8
|
const index_1 = require("./index");
|
|
9
|
-
const createSessionInfoBase = async (querystrings, headers, ip, clientName, environment, sessionInfo, locale, props) => {
|
|
10
|
-
const userId = querystrings.userId;
|
|
9
|
+
const createSessionInfoBase = async (userId, querystrings, headers, ip, clientName, environment, sessionInfo, locale, props) => {
|
|
11
10
|
const userAgent = (0, buildUserAgentInfos_1.default)(headers['user-agent'], querystrings);
|
|
12
11
|
const client = {
|
|
13
12
|
...sessionInfo.client,
|
|
@@ -43,10 +42,10 @@ const createSessionInfoBase = async (querystrings, headers, ip, clientName, envi
|
|
|
43
42
|
}
|
|
44
43
|
return { client, user, contexts, environment };
|
|
45
44
|
};
|
|
46
|
-
const createSessionInfo = (socket, clientName, environment, sessionInfo, locale, props) => async () => {
|
|
45
|
+
const createSessionInfo = (socket, clientName, environment, sessionInfo, userId, locale, props) => async () => {
|
|
47
46
|
const request = socket.request;
|
|
48
47
|
const querystrings = socket.handshake.query;
|
|
49
48
|
const ip = (0, extractIP_1.default)(request);
|
|
50
|
-
return await createSessionInfoBase(querystrings, request.headers, ip, clientName, environment, sessionInfo, locale, props);
|
|
49
|
+
return await createSessionInfoBase(userId, querystrings, request.headers, ip, clientName, environment, sessionInfo, locale, props);
|
|
51
50
|
};
|
|
52
51
|
exports.default = createSessionInfo;
|
|
@@ -6,10 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const globals_1 = require("@jest/globals");
|
|
7
7
|
const createSessionInfo_1 = __importDefault(require("./createSessionInfo"));
|
|
8
8
|
(0, globals_1.describe)('create session info', () => {
|
|
9
|
-
const querystrings = {
|
|
10
|
-
sessionId: 'session-id',
|
|
11
|
-
userId: 'user-id',
|
|
12
|
-
};
|
|
9
|
+
const querystrings = {};
|
|
13
10
|
const headers = {
|
|
14
11
|
host: 'fluance-chatbot.scapp.io',
|
|
15
12
|
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36',
|
|
@@ -58,7 +55,7 @@ const createSessionInfo_1 = __importDefault(require("./createSessionInfo"));
|
|
|
58
55
|
environment: 'PROD',
|
|
59
56
|
};
|
|
60
57
|
(0, globals_1.it)('without user payload', async () => {
|
|
61
|
-
const sessionInfo = await (0, createSessionInfo_1.default)(socket, 'my-client', 'TEST', defaultSessionInfo, 'de_DE', {})();
|
|
58
|
+
const sessionInfo = await (0, createSessionInfo_1.default)(socket, 'my-client', 'TEST', defaultSessionInfo, 'my-user-id', 'de_DE', {})();
|
|
62
59
|
// client
|
|
63
60
|
(0, globals_1.expect)(sessionInfo.client.name).toBe('my-client');
|
|
64
61
|
(0, globals_1.expect)(sessionInfo.client.type).toBe('webclient');
|
|
@@ -69,7 +66,7 @@ const createSessionInfo_1 = __importDefault(require("./createSessionInfo"));
|
|
|
69
66
|
(0, globals_1.expect)(sessionInfo.client.payload.querystrings).toEqual(querystrings);
|
|
70
67
|
(0, globals_1.expect)(sessionInfo.client.payload.ip).toBe('151.248.213.117');
|
|
71
68
|
// user
|
|
72
|
-
(0, globals_1.expect)(sessionInfo.user.id).toBe('user-id');
|
|
69
|
+
(0, globals_1.expect)(sessionInfo.user.id).toBe('my-user-id');
|
|
73
70
|
(0, globals_1.expect)(sessionInfo.user.displayName).toBe('Webseiten Besucher');
|
|
74
71
|
(0, globals_1.expect)(sessionInfo.user.locale).toBe('de_DE');
|
|
75
72
|
(0, globals_1.expect)(sessionInfo.user.payload).toStrictEqual({});
|
|
@@ -91,7 +88,7 @@ const createSessionInfo_1 = __importDefault(require("./createSessionInfo"));
|
|
|
91
88
|
const props = {
|
|
92
89
|
requestUserInfos,
|
|
93
90
|
};
|
|
94
|
-
const sessionInfo = await (0, createSessionInfo_1.default)(socket, 'my-client', 'TEST', defaultSessionInfo, 'de_DE', props)();
|
|
91
|
+
const sessionInfo = await (0, createSessionInfo_1.default)(socket, 'my-client', 'TEST', defaultSessionInfo, 'my-user-id', 'de_DE', props)();
|
|
95
92
|
(0, globals_1.expect)(sessionInfo.user.id).toBe('hans.muster@PRIMARY');
|
|
96
93
|
(0, globals_1.expect)(sessionInfo.user.displayName).toBe('Hans Muster');
|
|
97
94
|
(0, globals_1.expect)(sessionInfo.user.payload.username).toBe('hans.muster');
|
|
@@ -105,8 +102,8 @@ const createSessionInfo_1 = __importDefault(require("./createSessionInfo"));
|
|
|
105
102
|
const props = {
|
|
106
103
|
requestUserInfos,
|
|
107
104
|
};
|
|
108
|
-
const sessionInfo = await (0, createSessionInfo_1.default)(socket, 'my-client', 'TEST', defaultSessionInfo, 'de_DE', props)();
|
|
109
|
-
(0, globals_1.expect)(sessionInfo.user.id).toBe('user-id');
|
|
105
|
+
const sessionInfo = await (0, createSessionInfo_1.default)(socket, 'my-client', 'TEST', defaultSessionInfo, 'my-user-id', 'de_DE', props)();
|
|
106
|
+
(0, globals_1.expect)(sessionInfo.user.id).toBe('my-user-id');
|
|
110
107
|
(0, globals_1.expect)(sessionInfo.user.displayName).toBe('Webseiten Besucher');
|
|
111
108
|
(0, globals_1.expect)(sessionInfo.user.locale).toBe('de_DE');
|
|
112
109
|
(0, globals_1.expect)(sessionInfo.user.payload).toStrictEqual({});
|
package/dist/embed/bundle.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
var at=Object.defineProperty;var lt=(h,
|
|
1
|
+
var at=Object.defineProperty;var lt=(h,p,j)=>p in h?at(h,p,{enumerable:!0,configurable:!0,writable:!0,value:j}):h[p]=j;var Z=(h,p,j)=>lt(h,typeof p!="symbol"?p+"":p,j);(function(){"use strict";function h(){}function p(e){return e()}function j(){return Object.create(null)}function k(e){e.forEach(p)}function A(e){return typeof e=="function"}function P(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}let L;function x(e,t){return e===t?!0:(L||(L=document.createElement("a")),L.href=t,e===L.href)}function we(e){return Object.keys(e).length===0}const _e=typeof window<"u"?window:typeof globalThis<"u"?globalThis:global;function v(e,t){e.appendChild(t)}function z(e,t,n){const r=ye(e);if(!r.getElementById(t)){const o=m("style");o.id=t,o.textContent=n,je(r,o)}}function ye(e){if(!e)return document;const t=e.getRootNode?e.getRootNode():e.ownerDocument;return t&&t.host?t:e.ownerDocument}function je(e,t){return v(e.head||e,t),t.sheet}function y(e,t,n){e.insertBefore(t,n||null)}function b(e){e.parentNode&&e.parentNode.removeChild(e)}function m(e){return document.createElement(e)}function ee(e){return document.createTextNode(e)}function E(){return ee(" ")}function ke(){return ee("")}function W(e,t,n,r){return e.addEventListener(t,n,r),()=>e.removeEventListener(t,n,r)}function d(e,t,n){n==null?e.removeAttribute(t):e.getAttribute(t)!==n&&e.setAttribute(t,n)}function xe(e){return Array.from(e.childNodes)}function te(e,t,n){e.classList.toggle(t,!!n)}let N;function U(e){N=e}const C=[],ne=[];let O=[];const re=[],Ce=Promise.resolve();let H=!1;function Oe(){H||(H=!0,Ce.then(oe))}function q(e){O.push(e)}const M=new Set;let T=0;function oe(){if(T!==0)return;const e=N;do{try{for(;T<C.length;){const t=C[T];T++,U(t),Te(t.$$)}}catch(t){throw C.length=0,T=0,t}for(U(null),C.length=0,T=0;ne.length;)ne.pop()();for(let t=0;t<O.length;t+=1){const n=O[t];M.has(n)||(M.add(n),n())}O.length=0}while(C.length);for(;re.length;)re.pop()();H=!1,M.clear(),U(e)}function Te(e){if(e.fragment!==null){e.update(),k(e.before_update);const t=e.dirty;e.dirty=[-1],e.fragment&&e.fragment.p(e.ctx,t),e.after_update.forEach(q)}}function Ee(e){const t=[],n=[];O.forEach(r=>e.indexOf(r)===-1?t.push(r):n.push(r)),n.forEach(r=>r()),O=t}const I=new Set;let Ue;function B(e,t){e&&e.i&&(I.delete(e),e.i(t))}function ie(e,t,n,r){if(e&&e.o){if(I.has(e))return;I.add(e),Ue.c.push(()=>{I.delete(e),r&&(n&&e.d(1),r())}),e.o(t)}else r&&r()}function se(e){e&&e.c()}function $(e,t,n){const{fragment:r,after_update:o}=e.$$;r&&r.m(t,n),q(()=>{const s=e.$$.on_mount.map(p).filter(A);e.$$.on_destroy?e.$$.on_destroy.push(...s):k(s),e.$$.on_mount=[]}),o.forEach(q)}function G(e,t){const n=e.$$;n.fragment!==null&&(Ee(n.after_update),k(n.on_destroy),n.fragment&&n.fragment.d(t),n.on_destroy=n.fragment=null,n.ctx=[])}function Se(e,t){e.$$.dirty[0]===-1&&(C.push(e),Oe(),e.$$.dirty.fill(0)),e.$$.dirty[t/31|0]|=1<<t%31}function F(e,t,n,r,o,s,a=null,f=[-1]){const l=N;U(e);const i=e.$$={fragment:null,ctx:[],props:s,update:h,not_equal:o,bound:j(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:j(),dirty:f,skip_bound:!1,root:t.target||l.$$.root};a&&a(i.root);let c=!1;if(i.ctx=n?n(e,t.props||{},(u,g,...w)=>{const _=w.length?w[0]:g;return i.ctx&&o(i.ctx[u],i.ctx[u]=_)&&(!i.skip_bound&&i.bound[u]&&i.bound[u](_),c&&Se(e,u)),g}):[],i.update(),c=!0,k(i.before_update),i.fragment=r?r(i.ctx):!1,t.target){if(t.hydrate){const u=xe(t.target);i.fragment&&i.fragment.l(u),u.forEach(b)}else i.fragment&&i.fragment.c();t.intro&&B(e.$$.fragment),$(e,t.target,t.anchor),oe()}U(l)}class Y{constructor(){Z(this,"$$");Z(this,"$$set")}$destroy(){G(this,1),this.$destroy=h}$on(t,n){if(!A(n))return h;const r=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return r.push(n),()=>{const o=r.indexOf(n);o!==-1&&r.splice(o,1)}}$set(t){this.$$set&&!we(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const Ae="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(Ae);function Le(e){z(e,"svelte-f0h0jd",`.svelte-f0h0jd.svelte-f0h0jd,.svelte-f0h0jd.svelte-f0h0jd:before,.svelte-f0h0jd.svelte-f0h0jd:after{box-sizing:border-box}.bot-border.svelte-f0h0jd.svelte-f0h0jd{position:fixed;display:flex;flex-direction:column;top:0;bottom:env(safe-area-inset-bottom);height:100%;max-height:100vh;width:100%;border-width:0;border-radius:var(--window-border-radius, 8px);box-shadow:rgba(0, 0, 0, 0.24) 0px 16px 40px;background:transparent;opacity:1;transition:transform 200ms,
|
|
2
2
|
opacity 100ms 100ms,
|
|
3
|
-
all 150ms;z-index:2147483647}.bot-border.closed.svelte-
|
|
3
|
+
all 150ms;z-index:2147483647}.bot-border.closed.svelte-f0h0jd.svelte-f0h0jd{transform:translateY(100vh);opacity:0}.header.svelte-f0h0jd.svelte-f0h0jd{display:flex;justify-content:space-between;width:100%;height:var(--header-height, 4em);background-color:var(
|
|
4
4
|
--header-background-color,
|
|
5
|
-
var(--brand-primary-color,
|
|
6
|
-
)}.bot.svelte-
|
|
7
|
-
'data-server' with the full qualified URL to the chatbot-server.`,n=
|
|
5
|
+
var(--brand-primary-color, white)
|
|
6
|
+
)}.bot.svelte-f0h0jd.svelte-f0h0jd{display:block;width:100%;flex:1 0 auto;margin:0}@media screen and (min-width: 768px){#chat-frame.svelte-f0h0jd.svelte-f0h0jd{border-bottom-left-radius:var(--window-border-radius, 8px);border-bottom-right-radius:var(--window-border-radius, 8px)}.header.svelte-f0h0jd.svelte-f0h0jd{border-top-left-radius:var(--window-border-radius, 8px);border-top-right-radius:var(--window-border-radius, 8px)}.bot-border.svelte-f0h0jd.svelte-f0h0jd{height:var(--window-height, 40em);max-height:calc(100vh - 2em);width:var(--window-width, 23em);top:auto;right:1em;bottom:1em;left:auto;border-radius:var(--window-border-radius, 8px)}.bot-border.closed.svelte-f0h0jd.svelte-f0h0jd{transform:translateY(var(--window-height, 40em));opacity:0}}.bot-border-close-icon.svelte-f0h0jd.svelte-f0h0jd{height:100%;padding:var(--close-icon-padding, 1em)}img.svelte-f0h0jd.svelte-f0h0jd{display:block;height:100%;padding:var(--logo-padding, 1em)}svg.svelte-f0h0jd.svelte-f0h0jd{height:100%;padding:0.4em;cursor:pointer}svg.svelte-f0h0jd path.svelte-f0h0jd{transition:stroke-width 100ms;stroke:white;stroke-width:2px}svg.svelte-f0h0jd:hover path.svelte-f0h0jd{stroke-width:3px}p.svelte-f0h0jd.svelte-f0h0jd,pre.svelte-f0h0jd.svelte-f0h0jd{max-width:300px}pre.svelte-f0h0jd.svelte-f0h0jd{font-size:0.6em;line-height:0.5}`)}function We(e){let t,n,r;return{c(){t=m("p"),t.textContent=`Please make sure that the script tag has 'id="chatbot"' and the attribute
|
|
7
|
+
'data-server' with the full qualified URL to the chatbot-server.`,n=E(),r=m("pre"),r.innerHTML=` <code class="svelte-f0h0jd">
|
|
8
8
|
<script
|
|
9
|
-
<br class="svelte-
|
|
9
|
+
<br class="svelte-f0h0jd"/>
|
|
10
10
|
id="chatbot"
|
|
11
|
-
<br class="svelte-
|
|
11
|
+
<br class="svelte-f0h0jd"/>
|
|
12
12
|
data-server="https://server.com/webclient"
|
|
13
|
-
<br class="svelte-
|
|
13
|
+
<br class="svelte-f0h0jd"/>
|
|
14
14
|
defer
|
|
15
|
-
<br class="svelte-
|
|
15
|
+
<br class="svelte-f0h0jd"/>
|
|
16
16
|
src="https://server.com/webclient/embed/bundle.js"> </script>
|
|
17
17
|
</code>
|
|
18
|
-
`,
|
|
19
|
-
box-shadow 100ms}.chat-button.svelte-2hl2mw:hover{box-shadow:16px 16px 16px rgba(0, 0, 0, 0.2);transform:translateY(-2px)}`)}function Ne(e){let t,n,r,o,s,a;return{c(){t=
|
|
18
|
+
`,d(t,"class","svelte-f0h0jd"),d(r,"class","svelte-f0h0jd")},m(o,s){y(o,t,s),y(o,n,s),y(o,r,s)},p:h,d(o){o&&(b(t),b(n),b(r))}}}function Ie(e){let t,n,r,o,s,a,f,l,i,c,u,g;return{c(){t=m("div"),n=m("div"),r=m("img"),s=E(),a=m("div"),a.innerHTML='<svg viewBox="-2 -2 24 24" aria-label="Close window icon" class="svelte-f0h0jd"><path d="M0,0L20,20M20,0L0,20" class="svelte-f0h0jd"></path></svg>',f=E(),l=m("iframe"),x(r.src,o=`${e[3]}/logo.svg`)||d(r,"src",o),d(r,"alt","Logo"),d(r,"class","logo svelte-f0h0jd"),d(a,"aria-label","Close chat window"),d(a,"role","button"),d(a,"class","bot-border-close-icon svelte-f0h0jd"),d(a,"tabindex",0),d(n,"class","header svelte-f0h0jd"),d(l,"id","chat-frame"),d(l,"title","Chat"),d(l,"class","bot svelte-f0h0jd"),x(l.src,i=`${e[0]}${e[0].indexOf("?")===-1?"?":"&"}referrer=${encodeURIComponent(e[1]??"")}&windowHeight=${le()}&windowWidth=${ae()}`)||d(l,"src",i),d(l,"frameborder","0"),d(l,"allow","microphone"),l.allowFullscreen=!0,d(t,"class","bot-border svelte-f0h0jd"),d(t,"aria-hidden",c=e[2]?"false":"true"),te(t,"closed",!e[2])},m(w,_){y(w,t,_),v(t,n),v(n,r),v(n,s),v(n,a),v(t,f),v(t,l),u||(g=[W(a,"click",function(){A(e[4])&&e[4].apply(this,arguments)}),W(a,"keydown",e[5])],u=!0)},p(w,_){e=w,_&8&&!x(r.src,o=`${e[3]}/logo.svg`)&&d(r,"src",o),_&3&&!x(l.src,i=`${e[0]}${e[0].indexOf("?")===-1?"?":"&"}referrer=${encodeURIComponent(e[1]??"")}&windowHeight=${le()}&windowWidth=${ae()}`)&&d(l,"src",i),_&4&&c!==(c=e[2]?"false":"true")&&d(t,"aria-hidden",c),_&4&&te(t,"closed",!e[2])},d(w){w&&b(t),u=!1,k(g)}}}function Re(e){let t;function n(s,a){return s[0]?Ie:We}let r=n(e),o=r(e);return{c(){o.c(),t=ke()},m(s,a){o.m(s,a),y(s,t,a)},p(s,[a]){r===(r=n(s))&&o?o.p(s,a):(o.d(1),o=r(s),o&&(o.c(),o.m(t.parentNode,t)))},i:h,o:h,d(s){s&&b(t),o.d(s)}}}function ae(){try{return window.innerWidth}catch{return-1}}function le(){try{return window.innerHeight}catch{return-1}}function De(e,t,n){let{server:r}=t,{referrer:o}=t,{open:s}=t,{assetsUrl:a}=t,{onToggle:f}=t;function l(i){const c=i.key;(c==="ArrowDown"||c==="ArrowRight"||c==="Enter"||c===" "||c==="Space")&&(i.stopPropagation(),f())}return e.$$set=i=>{"server"in i&&n(0,r=i.server),"referrer"in i&&n(1,o=i.referrer),"open"in i&&n(2,s=i.open),"assetsUrl"in i&&n(3,a=i.assetsUrl),"onToggle"in i&&n(4,f=i.onToggle)},[r,o,s,a,f,l]}class Pe extends Y{constructor(t){super(),F(this,t,De,Re,P,{server:0,referrer:1,open:2,assetsUrl:3,onToggle:4},Le)}}function ze(e){z(e,"svelte-2hl2mw",`.svelte-2hl2mw,.svelte-2hl2mw:before,.svelte-2hl2mw:after{box-sizing:border-box}.chat-button-wrapper.svelte-2hl2mw{position:fixed;top:var(--fab-top-mobile, var(--fab-top, auto));right:var(--fab-right-mobile, var(--fab-right, 1.5em));bottom:var(--fab-bottom-mobile, var(--fab-bottom, 1.5em));left:var(--fab-left-mobile, var(--fab-left, auto));width:var(--fab-size-mobile, var(--fab-size, 5em));height:var(--fab-size-mobile, var(--fab-size, 5em));z-index:999}@media screen and (min-width: 768px){.chat-button-wrapper.svelte-2hl2mw{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-size, 6em);height:var(--fab-size, 6em)}}.chat-button.svelte-2hl2mw{display:block;height:100%;cursor:pointer;border-radius:50%;box-shadow:9px 9px 16px rgba(0, 0, 0, 0.25);transition:transform 100ms,
|
|
19
|
+
box-shadow 100ms}.chat-button.svelte-2hl2mw:hover{box-shadow:16px 16px 16px rgba(0, 0, 0, 0.2);transform:translateY(-2px)}`)}function Ne(e){let t,n,r,o,s,a;return{c(){t=m("div"),n=m("img"),d(n,"class","chat-button svelte-2hl2mw"),d(n,"alt","Open chat window"),x(n.src,r=`${e[0]}/fab.svg`)||d(n,"src",r),d(t,"class","chat-button-wrapper svelte-2hl2mw"),d(t,"tabindex","0"),d(t,"role","button"),d(t,"aria-label","Open chat window"),d(t,"aria-expanded",o=e[2]?"true":"false")},m(f,l){y(f,t,l),v(t,n),s||(a=[W(t,"click",function(){A(e[1])&&e[1].apply(this,arguments)}),W(t,"keydown",e[3])],s=!0)},p(f,[l]){e=f,l&1&&!x(n.src,r=`${e[0]}/fab.svg`)&&d(n,"src",r),l&4&&o!==(o=e[2]?"true":"false")&&d(t,"aria-expanded",o)},i:h,o:h,d(f){f&&b(t),s=!1,k(a)}}}function He(e,t,n){let{assetsUrl:r}=t,{onToggle:o}=t,{open:s}=t;function a(f){const l=f.key;(l==="ArrowDown"||l==="ArrowRight"||l==="Enter"||l===" "||l==="Space")&&(f.stopPropagation(),o())}return e.$$set=f=>{"assetsUrl"in f&&n(0,r=f.assetsUrl),"onToggle"in f&&n(1,o=f.onToggle),"open"in f&&n(2,s=f.open)},[r,o,s,a]}class qe extends Y{constructor(t){super(),F(this,t,He,Ne,P,{assetsUrl:0,onToggle:1,open:2},ze)}}/*! js-cookie v3.0.5 | MIT */function R(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)e[r]=n[r]}return e}var Me={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 K(e,t){function n(o,s,a){if(!(typeof document>"u")){a=R({},t,a),typeof a.expires=="number"&&(a.expires=new Date(Date.now()+a.expires*864e5)),a.expires&&(a.expires=a.expires.toUTCString()),o=encodeURIComponent(o).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var f="";for(var l in a)a[l]&&(f+="; "+l,a[l]!==!0&&(f+="="+a[l].split(";")[0]));return document.cookie=o+"="+e.write(s,o)+f}}function r(o){if(!(typeof document>"u"||arguments.length&&!o)){for(var s=document.cookie?document.cookie.split("; "):[],a={},f=0;f<s.length;f++){var l=s[f].split("="),i=l.slice(1).join("=");try{var c=decodeURIComponent(l[0]);if(a[c]=e.read(i,c),o===c)break}catch{}}return o?a[o]:a}}return Object.create({set:n,get:r,remove:function(o,s){n(o,"",R({},s,{expires:-1}))},withAttributes:function(o){return K(this.converter,R({},this.attributes,o))},withConverter:function(o){return K(R({},this.converter,o),this.attributes)}},{attributes:{value:Object.freeze(t)},converter:{value:Object.freeze(e)}})}var fe=K(Me,{path:"/"});const de="bot-window",ce=()=>{switch(fe.get(de)){case"open":return!0;case"closed":return!1;default:return!1}},ue=e=>{fe.set(de,e)};let he=!1;function Be(e){he=e}function $e(){return he}const V=[];let S=ce();function J(){S=!0,ue("open"),V.forEach(function(e){e.call(window,S)})}function Q(){S=!1,ue("closed"),V.forEach(function(e){e.call(window,S)})}function X(){S?Q():J()}function Ge(e){ge({type:"CHAT_MESSAGE_FROM_GUEST",text:e})}function Fe(e){ge({type:"TRIGGER_STORY",story:e})}function ge(e){var n;const t=document.getElementById("chat-frame");(n=t==null?void 0:t.contentWindow)==null||n.postMessage(e,"*")}function me(e,t){switch(e){case"ON_CHAT_WINDOW_STATE_CHANGE":V.push(t);break;default:throw new Error("Unsupported event "+e)}}const Ye=Object.freeze(Object.defineProperty({__proto__:null,closeChatWindow:Q,enterGuestMessage:Ge,isChatbotLoaded:$e,openChatWindow:J,subscribe:me,toggleChatWindow:X,triggerStory:Fe},Symbol.toStringTag,{value:"Module"}));function Ke(){return navigator.userAgent.match(/(iPad|iPhone|iPod)/g)}const Ve=()=>{Ke()&&document.querySelectorAll("html, body").forEach(e=>{e.classList.add("iOS-device")})},Je=e=>{"gtag"in window&&typeof window.gtag=="function"?window.gtag("event","",e):"dataLayer"in window&&Array.isArray(window.dataLayer)&&window.dataLayer.push(e)},Qe=(e,t)=>{window.addEventListener("message",n=>{const r=n.data;switch(r.type){case"webclient.expand.window":e(r.devices);break;case"webclient.change.url":t(r.url);break;case"google.tag.event":Je(r.payload);break}},!1)},{document:Xe}=_e;function Ze(e){z(e,"svelte-1vmieip",".bubble-chat.svelte-1vmieip{font-size:16px}")}function et(e){let t,n,r,o,s,a,f,l;return s=new qe({props:{assetsUrl:e[2],open:e[3],onToggle:X}}),f=new Pe({props:{server:e[0],referrer:e[1],assetsUrl:e[2],open:e[3],onToggle:X}}),{c(){t=m("link"),r=E(),o=m("div"),se(s.$$.fragment),a=E(),se(f.$$.fragment),d(t,"rel","stylesheet"),d(t,"href",n=`${e[2]}/custom.css`),d(o,"class","bubble-chat svelte-1vmieip")},m(i,c){v(Xe.head,t),y(i,r,c),y(i,o,c),$(s,o,null),v(o,a),$(f,o,null),l=!0},p(i,[c]){(!l||c&4&&n!==(n=`${i[2]}/custom.css`))&&d(t,"href",n);const u={};c&4&&(u.assetsUrl=i[2]),c&8&&(u.open=i[3]),s.$set(u);const g={};c&1&&(g.server=i[0]),c&2&&(g.referrer=i[1]),c&4&&(g.assetsUrl=i[2]),c&8&&(g.open=i[3]),f.$set(g)},i(i){l||(B(s.$$.fragment,i),B(f.$$.fragment,i),l=!0)},o(i){ie(s.$$.fragment,i),ie(f.$$.fragment,i),l=!1},d(i){i&&(b(r),b(o)),b(t),G(s),G(f)}}}function tt(e,t,n){let{server:r}=t,{referrer:o}=t,{assetsUrl:s=r?r.split("?")[0]:void 0}=t;Ve();let a=ce();me("ON_CHAT_WINDOW_STATE_CHANGE",function(c){n(3,a=c)});function f(i){const c=window.innerWidth,u=i==null||i==="all",g=i==="desktop"&&c>=768,w=i==="mobile"&&c<768;(u||g||w)&&J()}function l(i){window.innerWidth<768&&Q(),document.location.href=i}return Qe(f,l),e.$$set=i=>{"server"in i&&n(0,r=i.server),"referrer"in i&&n(1,o=i.referrer),"assetsUrl"in i&&n(2,s=i.assetsUrl)},[r,o,s,a]}class nt extends Y{constructor(t){super(),F(this,t,tt,et,P,{server:0,referrer:1,assetsUrl:2},Ze)}}const rt=e=>e.replace(/\/embed\/bundle\.js/,""),ot=e=>{var t;return(t=e.dataset)==null?void 0:t.server},it=e=>{if(e&&"src"in e&&typeof e.src=="string")return ot(e)||rt(e.src)},st=document.querySelector("script#chatbot"),pe=it(st);window.chatbot=Ye;const ve=()=>{console.log("Chatbot is loading from",pe),new nt({target:document.body,props:{server:pe,referrer:window.location.href}}),Be(!0)},be=(e=0)=>{e>=3||document.readyState==="complete"?setTimeout(ve,1e3):setTimeout(()=>{be(e+1)},1e3)};be();var D=document.getElementById("chatbot");D&&"src"in D&&typeof D.src=="string"&&D.src.indexOf("caller=bookmarklet")>0&&setTimeout(ve,500)})();
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,10 @@ import { Action } from '@botfabrik/engine-domain';
|
|
|
4
4
|
import { SpeechToTextProps } from './speechToText';
|
|
5
5
|
import type { SessionInfoUserPayload, WebclientMiddlewareState } from './types';
|
|
6
6
|
export type RequestUserInfos = (querystrings: any) => Promise<Partial<SessionInfoUser<SessionInfoUserPayload>>>;
|
|
7
|
-
export type RequestSessionRecordQuery = (
|
|
7
|
+
export type RequestSessionRecordQuery = (params: {
|
|
8
|
+
querystrings: any;
|
|
9
|
+
sessionId: string;
|
|
10
|
+
}) => Promise<Record<string, unknown>>;
|
|
8
11
|
export interface WebClientProps {
|
|
9
12
|
getStartedAction?: Action;
|
|
10
13
|
requestUserInfos?: RequestUserInfos;
|
|
@@ -17,6 +20,7 @@ export interface WebClientProps {
|
|
|
17
20
|
problemReportingEnabled?: boolean;
|
|
18
21
|
conversationRatingEnabled?: boolean;
|
|
19
22
|
fabVisible?: boolean;
|
|
23
|
+
useStartScreen?: boolean;
|
|
20
24
|
}
|
|
21
25
|
export declare enum Devices {
|
|
22
26
|
All = "all",
|
package/dist/index.js
CHANGED
|
@@ -90,92 +90,8 @@ exports.default = (clientName, environment, props) => async (bot) => {
|
|
|
90
90
|
const nsp = bot.webserver.socket.of(`/${clientName}/chat`);
|
|
91
91
|
nsp.on('connection', async (socket) => {
|
|
92
92
|
try {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const sessionsCollection = bot.store.db.collection('sessions');
|
|
96
|
-
const { sessionId, sessionInfo: defaultSessionInfo, isNew, } = await (0, requestSessionData_1.default)(querystrings, sessionsCollection, clientName, locale, props);
|
|
97
|
-
// create a channel for each session
|
|
98
|
-
socket.join(sessionId);
|
|
99
|
-
const sessionInfo = await (0, createSessionInfo_1.default)(socket, clientName, environment, defaultSessionInfo, locale, props)();
|
|
100
|
-
const session = await bot.createSession(sessionId, sessionInfo);
|
|
101
|
-
// sending active language and translations to client
|
|
102
|
-
const clientLocale = (0, getSupportedClientLocale_1.default)(session.translator.locale);
|
|
103
|
-
nsp
|
|
104
|
-
.to(sessionId)
|
|
105
|
-
.emit('set-translations', clientLocale, bot.translation.getResourceBundle(clientLocale)[clientName] || {});
|
|
106
|
-
// sending persisted state to client
|
|
107
|
-
const previousConversations = await (0, loadPreviousConversation_1.default)(bot.store, sessionId);
|
|
108
|
-
nsp.to(sessionId).emit('restore-client-state', {
|
|
109
|
-
sessionId,
|
|
110
|
-
messages: previousConversations,
|
|
111
|
-
});
|
|
112
|
-
// enable speech support
|
|
113
|
-
if (props.speech) {
|
|
114
|
-
nsp.to(sessionId).emit('enable-speech-support');
|
|
115
|
-
}
|
|
116
|
-
// enable problem reporting
|
|
117
|
-
if (props.problemReportingEnabled) {
|
|
118
|
-
nsp.to(sessionId).emit('enable-problem-reporting');
|
|
119
|
-
}
|
|
120
|
-
// enable transcript export
|
|
121
|
-
if (props.emailExportEnabled || props.pdfExportEnabled) {
|
|
122
|
-
nsp.to(sessionId).emit('enable-transcript-export', {
|
|
123
|
-
pdf: props.pdfExportEnabled || false,
|
|
124
|
-
email: props.emailExportEnabled || false,
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
// enable display of general conditions
|
|
128
|
-
if (props.showGeneralConditions) {
|
|
129
|
-
nsp.to(sessionId).emit('show-general-conditions');
|
|
130
|
-
}
|
|
131
|
-
// enable conversation rating
|
|
132
|
-
if (props.conversationRatingEnabled) {
|
|
133
|
-
nsp.to(sessionId).emit('enable-conversation-rating', {
|
|
134
|
-
rating: sessionInfo.client.payload.conversationRating,
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
// Notify middlewares about a connected or reconnected guest
|
|
138
|
-
await session.dispatch((0, engine_domain_1.guestConnected)(sessionId));
|
|
139
|
-
if (isNew && props.getStartedAction) {
|
|
140
|
-
await session.dispatch(props.getStartedAction);
|
|
141
|
-
}
|
|
142
|
-
if (isNew &&
|
|
143
|
-
props.expandChatWindowAtStart &&
|
|
144
|
-
props.expandChatWindowAtStart !== Devices.None) {
|
|
145
|
-
nsp
|
|
146
|
-
.to(session.id)
|
|
147
|
-
.emit('expand-window', { devices: props.expandChatWindowAtStart });
|
|
148
|
-
}
|
|
149
|
-
// forward actions from webclient
|
|
150
|
-
socket.on('action', async (action) => {
|
|
151
|
-
await session.dispatch(JSON.parse(action));
|
|
152
|
-
});
|
|
153
|
-
socket.on('disconnect', async () => {
|
|
154
|
-
await session.dispatch((0, engine_domain_1.guestDisconnected)(sessionId));
|
|
155
|
-
});
|
|
156
|
-
socket.on('conversation-rating', async (rating) => {
|
|
157
|
-
sessionsCollection.updateOne({ _id: sessionId }, {
|
|
158
|
-
$set: { 'sessionInfo.client.payload.conversationRating': rating },
|
|
159
|
-
});
|
|
160
|
-
session.dispatch({
|
|
161
|
-
type: engine_domain_1.ActionTypes.CONVERSATION_RATING_FROM_GUEST,
|
|
162
|
-
payload: { rating },
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
socket.on('audio-message', async (buffer) => {
|
|
166
|
-
if (props.speech) {
|
|
167
|
-
try {
|
|
168
|
-
const text = await (0, speechToText_1.default)(props.speech, session.translator.locale, buffer);
|
|
169
|
-
if (text && text.length) {
|
|
170
|
-
nsp.to(sessionId).emit('speech-transcription', text);
|
|
171
|
-
session.dispatch((0, engine_domain_1.receiveTextMessageFromGuest)(text));
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
catch (error) {
|
|
175
|
-
logger.error(error);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
});
|
|
93
|
+
sendConfigurationToClient(socket, props, bot, clientName);
|
|
94
|
+
socket.on('start-chat', onStartChat(socket, props, bot, clientName, environment, logger));
|
|
179
95
|
}
|
|
180
96
|
catch (error) {
|
|
181
97
|
logger.error('Error while connecting webclient with backend.');
|
|
@@ -207,4 +123,98 @@ const serveStaticOptions = {
|
|
|
207
123
|
},
|
|
208
124
|
};
|
|
209
125
|
const isFabVisible = ({ fabVisible = true }) => fabVisible;
|
|
126
|
+
const onStartChat = (socket, props, bot, clientName, environment, logger) => async ({ sessionId: defaultSessionId, userId: defaultUserId, }) => {
|
|
127
|
+
const locale = (0, extractLocale_1.default)(socket.handshake.query, socket.request.headers['accept-language']);
|
|
128
|
+
const sessionsCollection = bot.store.db.collection('sessions');
|
|
129
|
+
const { sessionId, sessionInfo: defaultSessionInfo, isNew, } = await (0, requestSessionData_1.default)(defaultSessionId, socket.handshake.query, sessionsCollection, clientName, locale, props);
|
|
130
|
+
// create a channel for each session
|
|
131
|
+
socket.join(sessionId);
|
|
132
|
+
const sessionInfo = await (0, createSessionInfo_1.default)(socket, clientName, environment, defaultSessionInfo, defaultUserId, locale, props)();
|
|
133
|
+
const session = await bot.createSession(sessionId, sessionInfo);
|
|
134
|
+
// sending persisted state to client
|
|
135
|
+
const previousConversations = await (0, loadPreviousConversation_1.default)(bot.store, sessionId);
|
|
136
|
+
socket.emit('restore-client-state', {
|
|
137
|
+
sessionId,
|
|
138
|
+
messages: previousConversations,
|
|
139
|
+
});
|
|
140
|
+
// enable conversation rating
|
|
141
|
+
if (props.conversationRatingEnabled) {
|
|
142
|
+
socket.emit('enable-conversation-rating', {
|
|
143
|
+
rating: sessionInfo.client.payload.conversationRating,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
// Notify middlewares about a connected or reconnected guest
|
|
147
|
+
await session.dispatch((0, engine_domain_1.guestConnected)(sessionId));
|
|
148
|
+
if (isNew && props.getStartedAction) {
|
|
149
|
+
await session.dispatch(props.getStartedAction);
|
|
150
|
+
}
|
|
151
|
+
if (isNew &&
|
|
152
|
+
props.expandChatWindowAtStart &&
|
|
153
|
+
props.expandChatWindowAtStart !== Devices.None) {
|
|
154
|
+
socket.emit('expand-window', {
|
|
155
|
+
devices: props.expandChatWindowAtStart,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
// forward actions from webclient
|
|
159
|
+
socket.on('action', async (action) => {
|
|
160
|
+
await session.dispatch(JSON.parse(action));
|
|
161
|
+
});
|
|
162
|
+
socket.on('disconnect', async () => {
|
|
163
|
+
await session.dispatch((0, engine_domain_1.guestDisconnected)(sessionId));
|
|
164
|
+
});
|
|
165
|
+
socket.on('conversation-rating', async (rating) => {
|
|
166
|
+
sessionsCollection.updateOne({ _id: sessionId }, {
|
|
167
|
+
$set: {
|
|
168
|
+
'sessionInfo.client.payload.conversationRating': rating,
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
session.dispatch({
|
|
172
|
+
type: engine_domain_1.ActionTypes.CONVERSATION_RATING_FROM_GUEST,
|
|
173
|
+
payload: { rating },
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
socket.on('audio-message', async (buffer) => {
|
|
177
|
+
if (props.speech) {
|
|
178
|
+
try {
|
|
179
|
+
const text = await (0, speechToText_1.default)(props.speech, session.translator.locale, buffer);
|
|
180
|
+
if (text && text.length) {
|
|
181
|
+
socket.emit('speech-transcription', text);
|
|
182
|
+
session.dispatch((0, engine_domain_1.receiveTextMessageFromGuest)(text));
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
logger.error(error);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
};
|
|
191
|
+
const sendConfigurationToClient = (socket, props, bot, clientName) => {
|
|
192
|
+
// sending active language and translations to client
|
|
193
|
+
const locale = (0, extractLocale_1.default)(socket.handshake.query, socket.request.headers['accept-language']);
|
|
194
|
+
const supportedLocale = bot.translation.detectSupportedLocale(locale);
|
|
195
|
+
const clientLocale = (0, getSupportedClientLocale_1.default)(supportedLocale);
|
|
196
|
+
socket.emit('set-translations', clientLocale, bot.translation.getResourceBundle(clientLocale)[clientName] || {});
|
|
197
|
+
// enable speech support
|
|
198
|
+
if (props.speech) {
|
|
199
|
+
socket.emit('enable-speech-support');
|
|
200
|
+
}
|
|
201
|
+
// enable problem reporting
|
|
202
|
+
if (props.problemReportingEnabled) {
|
|
203
|
+
socket.emit('enable-problem-reporting');
|
|
204
|
+
}
|
|
205
|
+
// enable transcript export
|
|
206
|
+
if (props.emailExportEnabled || props.pdfExportEnabled) {
|
|
207
|
+
socket.emit('enable-transcript-export', {
|
|
208
|
+
pdf: !!props.pdfExportEnabled,
|
|
209
|
+
email: !!props.emailExportEnabled,
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
// enable display of general conditions
|
|
213
|
+
if (props.showGeneralConditions) {
|
|
214
|
+
socket.emit('show-general-conditions');
|
|
215
|
+
}
|
|
216
|
+
// inform client whether to use start screen
|
|
217
|
+
// socket.emit('set-use-start-screen', !!props.useStartScreen);
|
|
218
|
+
socket.emit('set-use-start-screen', true);
|
|
219
|
+
};
|
|
210
220
|
exports.CLIENT_TYPE = 'webclient';
|
|
@@ -6,5 +6,5 @@ interface SessionData {
|
|
|
6
6
|
sessionInfo: SessionInfo<SessionInfoClientPayload, SessionInfoUserPayload>;
|
|
7
7
|
isNew: boolean;
|
|
8
8
|
}
|
|
9
|
-
declare const requestSessionData: (querystrings: any, sessionsCollection: any, clientName: string, locale: string | undefined, props: WebClientProps) => Promise<SessionData>;
|
|
9
|
+
declare const requestSessionData: (sessionId: string, querystrings: any, sessionsCollection: any, clientName: string, locale: string | undefined, props: WebClientProps) => Promise<SessionData>;
|
|
10
10
|
export default requestSessionData;
|
|
@@ -2,34 +2,37 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const crypto_1 = require("crypto");
|
|
4
4
|
const index_1 = require("./index");
|
|
5
|
-
const requestSessionData = async (querystrings, sessionsCollection, clientName, locale, props) => {
|
|
5
|
+
const requestSessionData = async (sessionId, querystrings, sessionsCollection, clientName, locale, props) => {
|
|
6
6
|
const baseQuery = {
|
|
7
7
|
'sessionInfo.client.type': index_1.CLIENT_TYPE,
|
|
8
8
|
'sessionInfo.client.name': clientName,
|
|
9
9
|
};
|
|
10
10
|
let findSessionRecordQuery;
|
|
11
11
|
if (props.requestSessionRecordQuery) {
|
|
12
|
-
const customQuery = await props.requestSessionRecordQuery(
|
|
12
|
+
const customQuery = await props.requestSessionRecordQuery({
|
|
13
|
+
sessionId,
|
|
14
|
+
querystrings,
|
|
15
|
+
});
|
|
13
16
|
findSessionRecordQuery = Object.assign({}, baseQuery, customQuery);
|
|
14
17
|
}
|
|
15
18
|
else {
|
|
16
19
|
findSessionRecordQuery = {
|
|
17
|
-
_id:
|
|
20
|
+
_id: sessionId,
|
|
18
21
|
'sessionInfo.user.locale': locale,
|
|
19
22
|
...baseQuery,
|
|
20
23
|
};
|
|
21
24
|
}
|
|
22
25
|
const sessionRecord = await sessionsCollection.findOne(findSessionRecordQuery, { _id: 1, sessionInfo: 1 });
|
|
23
|
-
let
|
|
26
|
+
let sesId;
|
|
24
27
|
let sessionInfo;
|
|
25
28
|
let isNew;
|
|
26
29
|
if (sessionRecord) {
|
|
27
|
-
|
|
30
|
+
sesId = sessionRecord._id;
|
|
28
31
|
sessionInfo = sessionRecord.sessionInfo;
|
|
29
32
|
isNew = false;
|
|
30
33
|
}
|
|
31
34
|
else {
|
|
32
|
-
|
|
35
|
+
sesId = (0, crypto_1.randomUUID)();
|
|
33
36
|
sessionInfo = {
|
|
34
37
|
client: {},
|
|
35
38
|
user: {},
|
|
@@ -38,7 +41,7 @@ const requestSessionData = async (querystrings, sessionsCollection, clientName,
|
|
|
38
41
|
isNew = true;
|
|
39
42
|
}
|
|
40
43
|
return {
|
|
41
|
-
sessionId,
|
|
44
|
+
sessionId: sesId,
|
|
42
45
|
sessionInfo,
|
|
43
46
|
isNew,
|
|
44
47
|
};
|
|
@@ -18,7 +18,6 @@ globals_1.jest.mock('crypto', () => {
|
|
|
18
18
|
globals_1.jest.clearAllMocks();
|
|
19
19
|
});
|
|
20
20
|
const querystrings = {
|
|
21
|
-
sessionId: 'session-id',
|
|
22
21
|
accessToken: 'access-token',
|
|
23
22
|
};
|
|
24
23
|
(0, globals_1.it)('when sessionId has been passed by query param but does not exists in db', async () => {
|
|
@@ -27,7 +26,7 @@ globals_1.jest.mock('crypto', () => {
|
|
|
27
26
|
const sessionsCollection = {
|
|
28
27
|
findOne,
|
|
29
28
|
};
|
|
30
|
-
const { sessionId, isNew } = await (0, requestSessionData_1.default)(querystrings, sessionsCollection, 'test-bot', 'de_DE', {});
|
|
29
|
+
const { sessionId, isNew } = await (0, requestSessionData_1.default)('session-id', querystrings, sessionsCollection, 'test-bot', 'de_DE', {});
|
|
31
30
|
(0, globals_1.expect)(findOne).toHaveBeenCalledTimes(1);
|
|
32
31
|
(0, globals_1.expect)(findOne).toHaveBeenCalledWith({
|
|
33
32
|
_id: 'session-id',
|
|
@@ -44,7 +43,7 @@ globals_1.jest.mock('crypto', () => {
|
|
|
44
43
|
const sessionsCollection = {
|
|
45
44
|
findOne,
|
|
46
45
|
};
|
|
47
|
-
const { sessionId, isNew } = await (0, requestSessionData_1.default)(querystrings, sessionsCollection, 'test-bot', 'de_DE', {});
|
|
46
|
+
const { sessionId, isNew } = await (0, requestSessionData_1.default)('session-id', querystrings, sessionsCollection, 'test-bot', 'de_DE', {});
|
|
48
47
|
(0, globals_1.expect)(findOne).toHaveBeenCalledTimes(1);
|
|
49
48
|
(0, globals_1.expect)(findOne).toHaveBeenCalledWith({
|
|
50
49
|
_id: 'session-id',
|
|
@@ -66,9 +65,12 @@ globals_1.jest.mock('crypto', () => {
|
|
|
66
65
|
requestSessionRecordQuery,
|
|
67
66
|
};
|
|
68
67
|
requestSessionRecordQuery.mockReturnValueOnce(Promise.resolve({ 'sessionInfo.user.id': 'hans@apptiva.ch' }));
|
|
69
|
-
const { sessionId, isNew } = await (0, requestSessionData_1.default)(querystrings, sessionsCollection, 'test-bot', 'de_DE', props);
|
|
68
|
+
const { sessionId, isNew } = await (0, requestSessionData_1.default)('session-id', querystrings, sessionsCollection, 'test-bot', 'de_DE', props);
|
|
70
69
|
(0, globals_1.expect)(requestSessionRecordQuery).toHaveBeenCalledTimes(1);
|
|
71
|
-
(0, globals_1.expect)(requestSessionRecordQuery).toHaveBeenCalledWith(
|
|
70
|
+
(0, globals_1.expect)(requestSessionRecordQuery).toHaveBeenCalledWith({
|
|
71
|
+
querystrings,
|
|
72
|
+
sessionId: 'session-id',
|
|
73
|
+
});
|
|
72
74
|
(0, globals_1.expect)(findOne).toHaveBeenCalledTimes(1);
|
|
73
75
|
(0, globals_1.expect)(findOne).toHaveBeenCalledWith({
|
|
74
76
|
'sessionInfo.client.name': 'test-bot',
|
|
@@ -89,9 +91,12 @@ globals_1.jest.mock('crypto', () => {
|
|
|
89
91
|
requestSessionRecordQuery,
|
|
90
92
|
};
|
|
91
93
|
requestSessionRecordQuery.mockReturnValueOnce(Promise.resolve({ 'sessionInfo.user.id': 'hans@apptiva.ch' }));
|
|
92
|
-
const { sessionId, isNew } = await (0, requestSessionData_1.default)(querystrings, sessionsCollection, 'test-bot', 'de_DE', props);
|
|
94
|
+
const { sessionId, isNew } = await (0, requestSessionData_1.default)('session-id', querystrings, sessionsCollection, 'test-bot', 'de_DE', props);
|
|
93
95
|
(0, globals_1.expect)(requestSessionRecordQuery).toHaveBeenCalledTimes(1);
|
|
94
|
-
(0, globals_1.expect)(requestSessionRecordQuery).toHaveBeenCalledWith(
|
|
96
|
+
(0, globals_1.expect)(requestSessionRecordQuery).toHaveBeenCalledWith({
|
|
97
|
+
querystrings,
|
|
98
|
+
sessionId: 'session-id',
|
|
99
|
+
});
|
|
95
100
|
(0, globals_1.expect)(findOne).toHaveBeenCalledTimes(1);
|
|
96
101
|
(0, globals_1.expect)(findOne).toHaveBeenCalledWith({
|
|
97
102
|
'sessionInfo.client.name': 'test-bot',
|