bibot 1.0.7 → 1.0.10
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +20 -36
- package/dist/component/bibot.d.ts +6 -5
- package/dist/config/appStateEnums.d.ts +3 -3
- package/dist/config/endpointEnums.d.ts +18 -18
- package/dist/config/index.d.ts +3 -3
- package/dist/config/statusCode.d.ts +42 -42
- package/dist/context/AppContext.d.ts +9 -8
- package/dist/context/index.d.ts +1 -1
- package/dist/hooks/index.d.ts +3 -3
- package/dist/hooks/mobileView.d.ts +1 -1
- package/dist/hooks/useBiBotChatBot.d.ts +29 -29
- package/dist/hooks/usePluginFactory.d.ts +1 -1
- package/dist/index.css +139 -35
- package/dist/index.d.ts +6 -2
- package/dist/index.js +649 -9
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +646 -0
- package/dist/index.modern.js.map +1 -0
- package/dist/index.test.d.ts +1 -0
- package/dist/reducers/appReducer.d.ts +2 -2
- package/dist/reducers/index.d.ts +1 -1
- package/dist/services/index.d.ts +1 -1
- package/dist/services/plugin-api.d.ts +23 -26
- package/dist/types/coreInterfaces.d.ts +51 -51
- package/dist/types/index.d.ts +1 -1
- package/dist/utils/index.d.ts +2 -2
- package/dist/utils/sessionManager.d.ts +2 -2
- package/dist/utils/trimWhitespace.d.ts +2 -2
- package/package.json +62 -37
- package/.babelrc +0 -7
- package/.vscode/settings.json +0 -5
- package/dist/bibot.d.ts +0 -5
- package/dist/bibot.js +0 -175
- package/dist/bibot.js.map +0 -1
- package/dist/component/bibot.js +0 -170
- package/dist/component/bibot.js.map +0 -1
- package/dist/config/appStateEnums.js +0 -10
- package/dist/config/appStateEnums.js.map +0 -1
- package/dist/config/endpointEnums.js +0 -31
- package/dist/config/endpointEnums.js.map +0 -1
- package/dist/config/index.js +0 -38
- package/dist/config/index.js.map +0 -1
- package/dist/config/statusCode.js +0 -49
- package/dist/config/statusCode.js.map +0 -1
- package/dist/context/AppContext.js +0 -75
- package/dist/context/AppContext.js.map +0 -1
- package/dist/context/index.js +0 -16
- package/dist/context/index.js.map +0 -1
- package/dist/hooks/index.js +0 -38
- package/dist/hooks/index.js.map +0 -1
- package/dist/hooks/mobileView.js +0 -33
- package/dist/hooks/mobileView.js.map +0 -1
- package/dist/hooks/useBiBotChatBot.js +0 -206
- package/dist/hooks/useBiBotChatBot.js.map +0 -1
- package/dist/hooks/usePluginFactory.js +0 -62
- package/dist/hooks/usePluginFactory.js.map +0 -1
- package/dist/reducers/appReducer.js +0 -24
- package/dist/reducers/appReducer.js.map +0 -1
- package/dist/reducers/index.js +0 -16
- package/dist/reducers/index.js.map +0 -1
- package/dist/services/index.js +0 -16
- package/dist/services/index.js.map +0 -1
- package/dist/services/plugin-api.js +0 -185
- package/dist/services/plugin-api.js.map +0 -1
- package/dist/styles/RegisterPageStyle.css +0 -63
- package/dist/styles/adminPortal.css +0 -26
- package/dist/styles/appConfig.css +0 -90
- package/dist/styles/buttonStyle.css +0 -27
- package/dist/styles/chatStyle.css +0 -140
- package/dist/styles/index.css +0 -82
- package/dist/styles/predefinedStyle.css +0 -35
- package/dist/styles/themeStyle.css +0 -42
- package/dist/styles/training.css +0 -86
- package/dist/types/coreInterfaces.js +0 -5
- package/dist/types/coreInterfaces.js.map +0 -1
- package/dist/types/index.js +0 -16
- package/dist/types/index.js.map +0 -1
- package/dist/utils/index.js +0 -27
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/sessionManager.js +0 -17
- package/dist/utils/sessionManager.js.map +0 -1
- package/dist/utils/trimWhitespace.js +0 -15
- package/dist/utils/trimWhitespace.js.map +0 -1
- package/src/component/bibot.tsx +0 -103
- package/src/config/appStateEnums.ts +0 -3
- package/src/config/endpointEnums.ts +0 -28
- package/src/config/index.ts +0 -5
- package/src/config/statusCode.ts +0 -49
- package/src/context/AppContext.tsx +0 -66
- package/src/context/index.ts +0 -3
- package/src/hooks/index.ts +0 -5
- package/src/hooks/mobileView.tsx +0 -17
- package/src/hooks/useBiBotChatBot.tsx +0 -107
- package/src/hooks/usePluginFactory.tsx +0 -38
- package/src/index.css +0 -36
- package/src/index.tsx +0 -3
- package/src/reducers/appReducer.ts +0 -16
- package/src/reducers/index.ts +0 -4
- package/src/services/index.ts +0 -2
- package/src/services/plugin-api.tsx +0 -120
- package/src/styles/RegisterPageStyle.css +0 -63
- package/src/styles/adminPortal.css +0 -26
- package/src/styles/appConfig.css +0 -90
- package/src/styles/buttonStyle.css +0 -27
- package/src/styles/chatStyle.css +0 -140
- package/src/styles/index.css +0 -82
- package/src/styles/predefinedStyle.css +0 -35
- package/src/styles/themeStyle.css +0 -42
- package/src/styles/training.css +0 -86
- package/src/types/coreInterfaces.ts +0 -69
- package/src/types/index.ts +0 -4
- package/src/utils/index.ts +0 -2
- package/src/utils/sessionManager.tsx +0 -15
- package/src/utils/trimWhitespace.ts +0 -11
- package/tsconfig.json +0 -25
- package/webpack.config.js +0 -19
package/dist/index.js
CHANGED
@@ -1,9 +1,649 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
var
|
8
|
-
|
9
|
-
var
|
1
|
+
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
2
|
+
|
3
|
+
var React = require('react');
|
4
|
+
var React__default = _interopDefault(React);
|
5
|
+
var core = require('@mantine/core');
|
6
|
+
var iconsMaterial = require('@mui/icons-material');
|
7
|
+
var ChatIcon = _interopDefault(require('@mui/icons-material/Chat'));
|
8
|
+
var antd = require('antd');
|
9
|
+
var axios = _interopDefault(require('axios'));
|
10
|
+
|
11
|
+
function _extends() {
|
12
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
13
|
+
for (var i = 1; i < arguments.length; i++) {
|
14
|
+
var source = arguments[i];
|
15
|
+
for (var key in source) {
|
16
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
17
|
+
target[key] = source[key];
|
18
|
+
}
|
19
|
+
}
|
20
|
+
}
|
21
|
+
return target;
|
22
|
+
};
|
23
|
+
return _extends.apply(this, arguments);
|
24
|
+
}
|
25
|
+
|
26
|
+
var baseUrls = {
|
27
|
+
inference: 'https://inference.dev.bibot.thespuka.com/v0'
|
28
|
+
};
|
29
|
+
var endpoints = {
|
30
|
+
get inference() {
|
31
|
+
return baseUrls.inference;
|
32
|
+
}
|
33
|
+
};
|
34
|
+
var domain;
|
35
|
+
(function (domain) {
|
36
|
+
domain["app"] = "/app";
|
37
|
+
domain["bibot"] = "/bibot";
|
38
|
+
domain["inference"] = "/inference";
|
39
|
+
})(domain || (domain = {}));
|
40
|
+
var resources;
|
41
|
+
(function (resources) {
|
42
|
+
resources["chatBubble"] = "/chat-bubble-config";
|
43
|
+
resources["predefinedQ"] = "/predefined-q";
|
44
|
+
resources["localQ"] = "/local-q";
|
45
|
+
resources["timedOutLocalQ"] = "/t-local-q";
|
46
|
+
resources["q"] = "/q";
|
47
|
+
})(resources || (resources = {}));
|
48
|
+
|
49
|
+
var inferenceBaseURL = endpoints.inference;
|
50
|
+
var createPluginAxiosInstance = function createPluginAxiosInstance(params, headers) {
|
51
|
+
if (params === void 0) {
|
52
|
+
params = {};
|
53
|
+
}
|
54
|
+
if (headers === void 0) {
|
55
|
+
headers = {};
|
56
|
+
}
|
57
|
+
var instance = axios.create(_extends({
|
58
|
+
baseURL: inferenceBaseURL,
|
59
|
+
timeout: 60000,
|
60
|
+
headers: _extends({
|
61
|
+
'Content-Type': 'application/json'
|
62
|
+
}, headers)
|
63
|
+
}, params));
|
64
|
+
instance.interceptors.response.use(function (response) {
|
65
|
+
return response;
|
66
|
+
}, function (error) {
|
67
|
+
try {
|
68
|
+
var errMsg = 'An unknown error occurred';
|
69
|
+
if (error.response) {
|
70
|
+
errMsg = error.response.data.message;
|
71
|
+
} else if (error.request) {
|
72
|
+
errMsg = 'No response received from the server.';
|
73
|
+
} else {
|
74
|
+
errMsg = "Error setting up the request: " + error.message;
|
75
|
+
}
|
76
|
+
return Promise.resolve(Promise.reject(new Error(errMsg)));
|
77
|
+
} catch (e) {
|
78
|
+
return Promise.reject(e);
|
79
|
+
}
|
80
|
+
});
|
81
|
+
return instance;
|
82
|
+
};
|
83
|
+
|
84
|
+
// A type of promise-like that resolves synchronously and supports only one observer
|
85
|
+
|
86
|
+
const _iteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.iterator || (Symbol.iterator = Symbol("Symbol.iterator"))) : "@@iterator";
|
87
|
+
|
88
|
+
const _asyncIteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.asyncIterator || (Symbol.asyncIterator = Symbol("Symbol.asyncIterator"))) : "@@asyncIterator";
|
89
|
+
|
90
|
+
// Asynchronously call a function and send errors to recovery continuation
|
91
|
+
function _catch(body, recover) {
|
92
|
+
try {
|
93
|
+
var result = body();
|
94
|
+
} catch(e) {
|
95
|
+
return recover(e);
|
96
|
+
}
|
97
|
+
if (result && result.then) {
|
98
|
+
return result.then(void 0, recover);
|
99
|
+
}
|
100
|
+
return result;
|
101
|
+
}
|
102
|
+
|
103
|
+
// Asynchronously await a promise and pass the result to a finally continuation
|
104
|
+
function _finallyRethrows(body, finalizer) {
|
105
|
+
try {
|
106
|
+
var result = body();
|
107
|
+
} catch (e) {
|
108
|
+
return finalizer(true, e);
|
109
|
+
}
|
110
|
+
if (result && result.then) {
|
111
|
+
return result.then(finalizer.bind(null, false), finalizer.bind(null, true));
|
112
|
+
}
|
113
|
+
return finalizer(false, result);
|
114
|
+
}
|
115
|
+
|
116
|
+
var appStateEnums;
|
117
|
+
(function (appStateEnums) {
|
118
|
+
appStateEnums["BIBOT"] = "BIBOT";
|
119
|
+
})(appStateEnums || (appStateEnums = {}));
|
120
|
+
|
121
|
+
var appReducer = function appReducer(state, action) {
|
122
|
+
console.log('This is the appReducer state', state, action);
|
123
|
+
switch (action.type) {
|
124
|
+
case appStateEnums.BIBOT:
|
125
|
+
return _extends({}, state, {
|
126
|
+
chatIsOpen: action.chatIsOpen
|
127
|
+
});
|
128
|
+
default:
|
129
|
+
return state;
|
130
|
+
}
|
131
|
+
};
|
132
|
+
|
133
|
+
// Unique ID creation requires a high quality random # generator. In the browser we therefore
|
134
|
+
// require the crypto API and do not support built-in fallback to lower quality random number
|
135
|
+
// generators (like Math.random()).
|
136
|
+
let getRandomValues;
|
137
|
+
const rnds8 = new Uint8Array(16);
|
138
|
+
function rng() {
|
139
|
+
// lazy load so that environments that need to polyfill have a chance to do so
|
140
|
+
if (!getRandomValues) {
|
141
|
+
// getRandomValues needs to be invoked in a context where "this" is a Crypto implementation.
|
142
|
+
getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);
|
143
|
+
|
144
|
+
if (!getRandomValues) {
|
145
|
+
throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
|
146
|
+
}
|
147
|
+
}
|
148
|
+
|
149
|
+
return getRandomValues(rnds8);
|
150
|
+
}
|
151
|
+
|
152
|
+
/**
|
153
|
+
* Convert array of 16 byte values to UUID string format of the form:
|
154
|
+
* XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
|
155
|
+
*/
|
156
|
+
|
157
|
+
const byteToHex = [];
|
158
|
+
|
159
|
+
for (let i = 0; i < 256; ++i) {
|
160
|
+
byteToHex.push((i + 0x100).toString(16).slice(1));
|
161
|
+
}
|
162
|
+
|
163
|
+
function unsafeStringify(arr, offset = 0) {
|
164
|
+
// Note: Be careful editing this code! It's been tuned for performance
|
165
|
+
// and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
|
166
|
+
return byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]];
|
167
|
+
}
|
168
|
+
|
169
|
+
const randomUUID = typeof crypto !== 'undefined' && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
170
|
+
var native = {
|
171
|
+
randomUUID
|
172
|
+
};
|
173
|
+
|
174
|
+
function v4(options, buf, offset) {
|
175
|
+
if (native.randomUUID && !buf && !options) {
|
176
|
+
return native.randomUUID();
|
177
|
+
}
|
178
|
+
|
179
|
+
options = options || {};
|
180
|
+
const rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
|
181
|
+
|
182
|
+
rnds[6] = rnds[6] & 0x0f | 0x40;
|
183
|
+
rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
|
184
|
+
|
185
|
+
if (buf) {
|
186
|
+
offset = offset || 0;
|
187
|
+
|
188
|
+
for (let i = 0; i < 16; ++i) {
|
189
|
+
buf[offset + i] = rnds[i];
|
190
|
+
}
|
191
|
+
|
192
|
+
return buf;
|
193
|
+
}
|
194
|
+
|
195
|
+
return unsafeStringify(rnds);
|
196
|
+
}
|
197
|
+
|
198
|
+
var SESSION_KEY = 'bibotUserSessionId';
|
199
|
+
var getSessionId = function getSessionId() {
|
200
|
+
var sessionId = localStorage.getItem(SESSION_KEY);
|
201
|
+
if (sessionId === null) {
|
202
|
+
var newSessionId = v4();
|
203
|
+
localStorage.setItem(SESSION_KEY, newSessionId);
|
204
|
+
return newSessionId;
|
205
|
+
}
|
206
|
+
return sessionId;
|
207
|
+
};
|
208
|
+
|
209
|
+
var dummyDispatch = function dummyDispatch() {};
|
210
|
+
var defaultContextValue = {
|
211
|
+
state: {
|
212
|
+
chatIsOpen: false,
|
213
|
+
sessionId: getSessionId()
|
214
|
+
},
|
215
|
+
dispatch: dummyDispatch
|
216
|
+
};
|
217
|
+
var AppContext = React.createContext(defaultContextValue);
|
218
|
+
var AppProvider = function AppProvider(_ref) {
|
219
|
+
var children = _ref.children;
|
220
|
+
var APP_STATE_KEY = 'app_states';
|
221
|
+
var initialState = {
|
222
|
+
chatIsOpen: false,
|
223
|
+
sessionId: getSessionId()
|
224
|
+
};
|
225
|
+
var _useReducer = React.useReducer(appReducer, initialState),
|
226
|
+
state = _useReducer[0],
|
227
|
+
dispatch = _useReducer[1];
|
228
|
+
React.useEffect(function () {
|
229
|
+
var storedStates = localStorage.getItem(APP_STATE_KEY);
|
230
|
+
if (storedStates) {
|
231
|
+
try {
|
232
|
+
var parsedStates = JSON.parse(storedStates);
|
233
|
+
var updatedStates = _extends({}, initialState, parsedStates);
|
234
|
+
console.log(initialState, parsedStates, updatedStates);
|
235
|
+
dispatch(_extends({
|
236
|
+
type: appStateEnums.BIBOT
|
237
|
+
}, updatedStates));
|
238
|
+
} catch (error) {
|
239
|
+
console.error('Failed to parse app states from local storage:', error);
|
240
|
+
}
|
241
|
+
}
|
242
|
+
}, []);
|
243
|
+
React.useEffect(function () {
|
244
|
+
console.log('Changes in state: ', state);
|
245
|
+
localStorage.setItem(APP_STATE_KEY, JSON.stringify(state));
|
246
|
+
}, [state]);
|
247
|
+
return React__default.createElement(AppContext.Provider, {
|
248
|
+
value: {
|
249
|
+
state: state,
|
250
|
+
dispatch: dispatch
|
251
|
+
}
|
252
|
+
}, children);
|
253
|
+
};
|
254
|
+
|
255
|
+
var getRemoteClientChatPredefinedQuestions = function getRemoteClientChatPredefinedQuestions(params) {
|
256
|
+
return Promise.resolve(_catch(function () {
|
257
|
+
var path = "" + domain.inference + resources.predefinedQ;
|
258
|
+
return Promise.resolve(pluginAxiosInstance.get(path, {
|
259
|
+
params: params
|
260
|
+
})).then(function (response) {
|
261
|
+
return response.data.predefined_messages;
|
262
|
+
});
|
263
|
+
}, function () {
|
264
|
+
return ['These are placeholders', 'They will be removed in production', 'This will be empty if there are no predefined questions', 'So hide if there are no predefined questions'];
|
265
|
+
}));
|
266
|
+
};
|
267
|
+
var getRemoteClientChatBubbleConfig = function getRemoteClientChatBubbleConfig(params) {
|
268
|
+
try {
|
269
|
+
return Promise.resolve(_catch(function () {
|
270
|
+
var path = "" + domain.inference + resources.chatBubble;
|
271
|
+
return Promise.resolve(pluginAxiosInstance.get(path, {
|
272
|
+
params: params
|
273
|
+
})).then(function (response) {
|
274
|
+
return response.data;
|
275
|
+
});
|
276
|
+
}, function () {
|
277
|
+
return {
|
278
|
+
bgColor: 'white',
|
279
|
+
chatColor: 'blue',
|
280
|
+
title: 'ChatBot',
|
281
|
+
userImage: 'string'
|
282
|
+
};
|
283
|
+
}));
|
284
|
+
} catch (e) {
|
285
|
+
return Promise.reject(e);
|
286
|
+
}
|
287
|
+
};
|
288
|
+
var askBiBot = function askBiBot(data) {
|
289
|
+
try {
|
290
|
+
return Promise.resolve(_catch(function () {
|
291
|
+
var path = "" + domain.inference + resources.q;
|
292
|
+
return Promise.resolve(pluginAxiosInstance.post(path, data)).then(function (response) {
|
293
|
+
console.log(response);
|
294
|
+
return response.data.message;
|
295
|
+
});
|
296
|
+
}, function (error1) {
|
297
|
+
console.log(error1.message);
|
298
|
+
if (error1.code === 'ECONNABORTED' || error1.message.includes('Endpoint request timed out')) {
|
299
|
+
return _catch(function () {
|
300
|
+
return Promise.resolve(askTimedOutBiBot(_extends({}, data, {
|
301
|
+
tries: 2
|
302
|
+
})));
|
303
|
+
}, function (error2) {
|
304
|
+
if (error2.code === 'ECONNABORTED' || error2.message.includes('Endpoint request timed out')) {
|
305
|
+
return _catch(function () {
|
306
|
+
return Promise.resolve(askTimedOutBiBot(_extends({}, data, {
|
307
|
+
tries: 3
|
308
|
+
})));
|
309
|
+
}, function (error3) {
|
310
|
+
return error3.message;
|
311
|
+
});
|
312
|
+
} else {
|
313
|
+
return error2.message;
|
314
|
+
}
|
315
|
+
});
|
316
|
+
} else {
|
317
|
+
return error1.message;
|
318
|
+
}
|
319
|
+
}));
|
320
|
+
} catch (e) {
|
321
|
+
return Promise.reject(e);
|
322
|
+
}
|
323
|
+
};
|
324
|
+
var askTimedOutBiBot = function askTimedOutBiBot(data) {
|
325
|
+
try {
|
326
|
+
return Promise.resolve(_catch(function () {
|
327
|
+
var path = "" + domain.bibot + resources.timedOutLocalQ;
|
328
|
+
return Promise.resolve(pluginAxiosInstance.post(path, data)).then(function (response) {
|
329
|
+
console.log(response);
|
330
|
+
return response.data.message;
|
331
|
+
});
|
332
|
+
}, function (error) {
|
333
|
+
console.log(error.message);
|
334
|
+
return error.message;
|
335
|
+
}));
|
336
|
+
} catch (e) {
|
337
|
+
return Promise.reject(e);
|
338
|
+
}
|
339
|
+
};
|
340
|
+
var pluginAxiosInstance = createPluginAxiosInstance();
|
341
|
+
|
342
|
+
var useBiBotChatBot = function useBiBotChatBot(_ref) {
|
343
|
+
var sendInputInquiry = function sendInputInquiry() {
|
344
|
+
try {
|
345
|
+
setIsLoading(true);
|
346
|
+
setUserInput('');
|
347
|
+
return Promise.resolve(_finallyRethrows(function () {
|
348
|
+
return _catch(function () {
|
349
|
+
var _temp2 = function () {
|
350
|
+
if (userInput.trim()) {
|
351
|
+
setMessages(function (messages) {
|
352
|
+
return [].concat(messages, [{
|
353
|
+
sender: 'user',
|
354
|
+
text: userInput
|
355
|
+
}]);
|
356
|
+
});
|
357
|
+
return Promise.resolve(askBiBot({
|
358
|
+
client_id: clientId,
|
359
|
+
q: userInput.trim(),
|
360
|
+
session_id: state.sessionId,
|
361
|
+
chat_id: v4()
|
362
|
+
})).then(function (response) {
|
363
|
+
setMessages(function (messages) {
|
364
|
+
return [].concat(messages, [{
|
365
|
+
sender: 'bot',
|
366
|
+
text: response
|
367
|
+
}]);
|
368
|
+
});
|
369
|
+
});
|
370
|
+
}
|
371
|
+
}();
|
372
|
+
if (_temp2 && _temp2.then) return _temp2.then(function () {});
|
373
|
+
}, function (error) {
|
374
|
+
var _error$message;
|
375
|
+
void antd.message.error((_error$message = error === null || error === void 0 ? void 0 : error.message) != null ? _error$message : 'Failed to get response from server');
|
376
|
+
});
|
377
|
+
}, function (_wasThrown, _result) {
|
378
|
+
setIsLoading(false);
|
379
|
+
if (_wasThrown) throw _result;
|
380
|
+
return _result;
|
381
|
+
}));
|
382
|
+
} catch (e) {
|
383
|
+
return Promise.reject(e);
|
384
|
+
}
|
385
|
+
};
|
386
|
+
var clientId = _ref.clientId;
|
387
|
+
var _useState = React.useState([]),
|
388
|
+
predefinedQuestions = _useState[0],
|
389
|
+
setPredefinedQuestions = _useState[1];
|
390
|
+
var _useState2 = React.useState(true),
|
391
|
+
showPredefinedQuestions = _useState2[0],
|
392
|
+
setShowPredefinedQuestions = _useState2[1];
|
393
|
+
var _useContext = React.useContext(AppContext),
|
394
|
+
state = _useContext.state;
|
395
|
+
var _useState3 = React.useState(false),
|
396
|
+
chatIsOpen = _useState3[0],
|
397
|
+
setChatIsOpen = _useState3[1];
|
398
|
+
var _useState4 = React.useState([]),
|
399
|
+
messages = _useState4[0],
|
400
|
+
setMessages = _useState4[1];
|
401
|
+
var _useState5 = React.useState(''),
|
402
|
+
userInput = _useState5[0],
|
403
|
+
setUserInput = _useState5[1];
|
404
|
+
var _useState6 = React.useState(false),
|
405
|
+
isLoading = _useState6[0],
|
406
|
+
setIsLoading = _useState6[1];
|
407
|
+
var messageEndRef = React.useRef(null);
|
408
|
+
var _useState7 = React.useState(),
|
409
|
+
chatBubbleConfig = _useState7[0],
|
410
|
+
setChatBubbleConfig = _useState7[1];
|
411
|
+
var handlePredefinedQuestionSelect = function handlePredefinedQuestionSelect(question) {
|
412
|
+
setUserInput(question);
|
413
|
+
sendInputInquiry();
|
414
|
+
setShowPredefinedQuestions(false);
|
415
|
+
};
|
416
|
+
var getChatBubbleConfig = React.useCallback(function () {
|
417
|
+
try {
|
418
|
+
return Promise.resolve(getRemoteClientChatPredefinedQuestions({
|
419
|
+
client_id: clientId
|
420
|
+
})).then(function (remotePredefinedQuestions) {
|
421
|
+
if (remotePredefinedQuestions) {
|
422
|
+
setPredefinedQuestions(remotePredefinedQuestions);
|
423
|
+
}
|
424
|
+
return Promise.resolve(getRemoteClientChatBubbleConfig({
|
425
|
+
client_id: clientId
|
426
|
+
})).then(function (remoteChatBubbleConfig) {
|
427
|
+
if (remoteChatBubbleConfig) {
|
428
|
+
setChatBubbleConfig(remoteChatBubbleConfig);
|
429
|
+
}
|
430
|
+
});
|
431
|
+
});
|
432
|
+
} catch (e) {
|
433
|
+
return Promise.reject(e);
|
434
|
+
}
|
435
|
+
}, [clientId]);
|
436
|
+
React.useEffect(function () {
|
437
|
+
void getChatBubbleConfig();
|
438
|
+
}, [getChatBubbleConfig]);
|
439
|
+
React.useEffect(function () {
|
440
|
+
if (messageEndRef !== null && messageEndRef !== void 0 && messageEndRef.current) {
|
441
|
+
messageEndRef.current.scrollIntoView({
|
442
|
+
behavior: 'smooth'
|
443
|
+
});
|
444
|
+
}
|
445
|
+
}, [messages]);
|
446
|
+
var toggleChat = function toggleChat() {
|
447
|
+
console.log('This is it', chatIsOpen);
|
448
|
+
setChatIsOpen(!chatIsOpen);
|
449
|
+
};
|
450
|
+
var handleUserInput = function handleUserInput(e) {
|
451
|
+
setUserInput(e.target.value);
|
452
|
+
};
|
453
|
+
var handleKeyPress = function handleKeyPress(e) {
|
454
|
+
try {
|
455
|
+
var _temp = function () {
|
456
|
+
if (e.key === 'Enter' && !isLoading) {
|
457
|
+
return Promise.resolve(sendInputInquiry()).then(function () {});
|
458
|
+
}
|
459
|
+
}();
|
460
|
+
return Promise.resolve(_temp && _temp.then ? _temp.then(function () {}) : void 0);
|
461
|
+
} catch (e) {
|
462
|
+
return Promise.reject(e);
|
463
|
+
}
|
464
|
+
};
|
465
|
+
return {
|
466
|
+
chatIsOpen: chatIsOpen,
|
467
|
+
messages: messages,
|
468
|
+
isLoading: isLoading,
|
469
|
+
messageEndRef: messageEndRef,
|
470
|
+
userInput: userInput,
|
471
|
+
handleUserInput: handleUserInput,
|
472
|
+
handleKeyPress: handleKeyPress,
|
473
|
+
toggleChat: toggleChat,
|
474
|
+
sendInputInquiry: sendInputInquiry,
|
475
|
+
chatBubbleConfig: chatBubbleConfig,
|
476
|
+
showPredefinedQuestions: showPredefinedQuestions,
|
477
|
+
predefinedQuestions: predefinedQuestions,
|
478
|
+
handlePredefinedQuestionSelect: handlePredefinedQuestionSelect
|
479
|
+
};
|
480
|
+
};
|
481
|
+
|
482
|
+
var styles = {"chat-bubble":"_2jyN5","chat-toggle":"_tXNYe","chat-window":"_1P2y-","chat-header":"_2UNL5","message-list":"_2v5bZ","message":"_2RbY_","user":"_1efWC","bot":"_2idRy","loader":"_3qqrl","l5":"_3cq86","input-area":"_34vFI","loading-bubbles":"_1kl6z","bubble":"_3cleF","bounce":"_UNzJX"};
|
483
|
+
|
484
|
+
var PredefinedQuestions = function PredefinedQuestions(_ref) {
|
485
|
+
var questions = _ref.questions,
|
486
|
+
onSelect = _ref.onSelect;
|
487
|
+
return React.createElement("div", {
|
488
|
+
className: styles['predefined-questions']
|
489
|
+
}, questions.map(function (question, index) {
|
490
|
+
return React.createElement("div", {
|
491
|
+
key: index,
|
492
|
+
className: styles['predefined-questions'],
|
493
|
+
onClick: function onClick() {
|
494
|
+
return onSelect(question);
|
495
|
+
}
|
496
|
+
}, question);
|
497
|
+
}));
|
498
|
+
};
|
499
|
+
var ChatBubbleBiBot = function ChatBubbleBiBot(_ref2) {
|
500
|
+
var _chatBubbleConfig$col, _chatBubbleConfig$col2;
|
501
|
+
var clientId = _ref2.clientId;
|
502
|
+
var _useBiBotChatBot = useBiBotChatBot({
|
503
|
+
clientId: clientId
|
504
|
+
}),
|
505
|
+
chatIsOpen = _useBiBotChatBot.chatIsOpen,
|
506
|
+
messages = _useBiBotChatBot.messages,
|
507
|
+
isLoading = _useBiBotChatBot.isLoading,
|
508
|
+
messageEndRef = _useBiBotChatBot.messageEndRef,
|
509
|
+
userInput = _useBiBotChatBot.userInput,
|
510
|
+
handleUserInput = _useBiBotChatBot.handleUserInput,
|
511
|
+
handleKeyPress = _useBiBotChatBot.handleKeyPress,
|
512
|
+
sendInputInquiry = _useBiBotChatBot.sendInputInquiry,
|
513
|
+
toggleChat = _useBiBotChatBot.toggleChat,
|
514
|
+
chatBubbleConfig = _useBiBotChatBot.chatBubbleConfig,
|
515
|
+
showPredefinedQuestions = _useBiBotChatBot.showPredefinedQuestions,
|
516
|
+
predefinedQuestions = _useBiBotChatBot.predefinedQuestions,
|
517
|
+
handlePredefinedQuestionSelect = _useBiBotChatBot.handlePredefinedQuestionSelect;
|
518
|
+
return React.createElement("div", {
|
519
|
+
className: "chat-bubble " + (chatIsOpen ? 'open' : '')
|
520
|
+
}, chatIsOpen && React.createElement("div", {
|
521
|
+
className: styles["chat-window"],
|
522
|
+
style: {
|
523
|
+
backgroundColor: chatBubbleConfig === null || chatBubbleConfig === void 0 ? void 0 : chatBubbleConfig.bgColor
|
524
|
+
}
|
525
|
+
}, React.createElement("div", {
|
526
|
+
className: styles["chat-header"],
|
527
|
+
style: {
|
528
|
+
backgroundColor: (_chatBubbleConfig$col = chatBubbleConfig === null || chatBubbleConfig === void 0 ? void 0 : chatBubbleConfig.color) != null ? _chatBubbleConfig$col : '#dedede'
|
529
|
+
}
|
530
|
+
}, React.createElement("div", {
|
531
|
+
style: {
|
532
|
+
alignItems: 'center',
|
533
|
+
display: 'flex',
|
534
|
+
color: '#fff',
|
535
|
+
fontWeight: 'bold'
|
536
|
+
}
|
537
|
+
}, React.createElement(core.Indicator, {
|
538
|
+
inline: true,
|
539
|
+
size: 12,
|
540
|
+
offset: 7,
|
541
|
+
position: "bottom-end",
|
542
|
+
color: 'green'
|
543
|
+
}, React.createElement(core.Avatar, {
|
544
|
+
color: "white",
|
545
|
+
src: chatBubbleConfig === null || chatBubbleConfig === void 0 ? void 0 : chatBubbleConfig.logo_url,
|
546
|
+
alt: "profile"
|
547
|
+
}))), React.createElement("div", {
|
548
|
+
style: {
|
549
|
+
display: 'flex',
|
550
|
+
flexDirection: 'column',
|
551
|
+
textAlign: 'left',
|
552
|
+
paddingLeft: '10px',
|
553
|
+
justifyContent: 'flex-start',
|
554
|
+
color: '#fff'
|
555
|
+
}
|
556
|
+
}, React.createElement("span", {
|
557
|
+
style: {
|
558
|
+
fontWeight: 'bold'
|
559
|
+
}
|
560
|
+
}, chatBubbleConfig === null || chatBubbleConfig === void 0 ? void 0 : chatBubbleConfig.title), isLoading ? React.createElement("span", {
|
561
|
+
style: {
|
562
|
+
fontSize: '12px',
|
563
|
+
lineHeight: '0.5'
|
564
|
+
}
|
565
|
+
}, "Typing...") : React.createElement("span", {
|
566
|
+
style: {
|
567
|
+
fontSize: '12px',
|
568
|
+
lineHeight: '0.5'
|
569
|
+
}
|
570
|
+
}, 'Online'))), React.createElement("div", {
|
571
|
+
className: styles["message-list"]
|
572
|
+
}, messages.map(function (message, index) {
|
573
|
+
return message.sender === 'user' ? React.createElement("div", {
|
574
|
+
key: index,
|
575
|
+
className: "message " + message.sender
|
576
|
+
}, message.text) : React.createElement("div", {
|
577
|
+
key: index,
|
578
|
+
style: {
|
579
|
+
display: 'flex'
|
580
|
+
}
|
581
|
+
}, React.createElement(core.Avatar, {
|
582
|
+
color: "white",
|
583
|
+
src: chatBubbleConfig === null || chatBubbleConfig === void 0 ? void 0 : chatBubbleConfig.logo_url,
|
584
|
+
size: 25,
|
585
|
+
alt: "profile"
|
586
|
+
}), React.createElement("div", {
|
587
|
+
className: "message " + message.sender
|
588
|
+
}, message.text));
|
589
|
+
}), showPredefinedQuestions && predefinedQuestions && predefinedQuestions.length > 0 && React.createElement(PredefinedQuestions, {
|
590
|
+
questions: predefinedQuestions,
|
591
|
+
onSelect: handlePredefinedQuestionSelect
|
592
|
+
}), isLoading && React.createElement("div", {
|
593
|
+
style: {
|
594
|
+
marginLeft: '20px'
|
595
|
+
},
|
596
|
+
className: 'message'
|
597
|
+
}, " ", React.createElement("div", {
|
598
|
+
className: "loader"
|
599
|
+
}), " "), React.createElement("div", {
|
600
|
+
ref: messageEndRef
|
601
|
+
})), React.createElement("div", {
|
602
|
+
className: styles["input-area"]
|
603
|
+
}, React.createElement("input", {
|
604
|
+
autoFocus: true,
|
605
|
+
type: "text",
|
606
|
+
value: userInput,
|
607
|
+
onChange: handleUserInput,
|
608
|
+
onKeyDown: handleKeyPress,
|
609
|
+
placeholder: "Ask a question"
|
610
|
+
}), React.createElement(antd.Button, {
|
611
|
+
disabled: isLoading != null ? isLoading : true,
|
612
|
+
style: {
|
613
|
+
backgroundColor: 'transparent',
|
614
|
+
color: isLoading ? '#dedede' : chatBubbleConfig === null || chatBubbleConfig === void 0 ? void 0 : chatBubbleConfig.color
|
615
|
+
},
|
616
|
+
size: 'middle',
|
617
|
+
icon: React.createElement(iconsMaterial.SendRounded, null),
|
618
|
+
onClick: sendInputInquiry
|
619
|
+
}))), React.createElement(antd.Button, {
|
620
|
+
type: 'link',
|
621
|
+
onClick: toggleChat,
|
622
|
+
className: styles["chat-toggle"],
|
623
|
+
style: {
|
624
|
+
backgroundColor: (_chatBubbleConfig$col2 = chatBubbleConfig === null || chatBubbleConfig === void 0 ? void 0 : chatBubbleConfig.color) != null ? _chatBubbleConfig$col2 : '#dedede'
|
625
|
+
}
|
626
|
+
}, chatIsOpen ? React.createElement(iconsMaterial.Close, {
|
627
|
+
style: {
|
628
|
+
width: 30,
|
629
|
+
height: 30,
|
630
|
+
color: '#fff'
|
631
|
+
}
|
632
|
+
}) : React.createElement(ChatIcon, {
|
633
|
+
style: {
|
634
|
+
width: 30,
|
635
|
+
height: 30,
|
636
|
+
color: '#fff'
|
637
|
+
}
|
638
|
+
})));
|
639
|
+
};
|
640
|
+
|
641
|
+
var BiBot = function BiBot(_ref) {
|
642
|
+
var clientId = _ref.clientId;
|
643
|
+
return React.createElement(AppProvider, null, React.createElement(core.MantineProvider, null, React.createElement(ChatBubbleBiBot, {
|
644
|
+
clientId: clientId
|
645
|
+
})));
|
646
|
+
};
|
647
|
+
|
648
|
+
exports.BiBot = BiBot;
|
649
|
+
//# sourceMappingURL=index.js.map
|