@livechat/customer-sdk 3.1.1 → 3.1.2
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 +6 -0
- package/dist/customer-sdk.cjs.js +186 -636
- package/dist/customer-sdk.cjs.native.js +186 -635
- package/dist/customer-sdk.esm.js +187 -637
- package/dist/customer-sdk.js +264 -863
- package/dist/customer-sdk.min.js +1 -1
- package/package.json +6 -5
- package/types/actions.d.ts +331 -0
- package/types/chatHistory.d.ts +19 -0
- package/types/clientDataParsers.d.ts +55 -0
- package/types/completionValues.d.ts +4 -0
- package/types/constants/clientErrorCodes.d.ts +11 -0
- package/types/constants/connectionStatuses.d.ts +6 -0
- package/types/constants/eventTypes.d.ts +8 -0
- package/types/constants/reduxActions.d.ts +23 -0
- package/types/constants/serverDisconnectionReasons.d.ts +15 -0
- package/types/constants/serverErrorCodes.d.ts +23 -0
- package/types/constants/serverPushActions.d.ts +26 -0
- package/types/constants/serverRequestActions.d.ts +30 -0
- package/types/constants/sortOrders.d.ts +3 -0
- package/types/constants/userTypes.d.ts +3 -0
- package/types/createError.d.ts +9 -0
- package/types/createStore.d.ts +12 -0
- package/types/debug.d.ts +3 -0
- package/types/graylog/index.d.ts +14 -0
- package/types/graylog/makeGrayLogRequest.d.ts +2 -0
- package/types/graylog/makeGrayLogRequest.native.d.ts +6 -0
- package/types/index.d.ts +239 -0
- package/types/reducer.d.ts +546 -0
- package/types/sendRequestAction.d.ts +4 -0
- package/types/sendTicketForm.d.ts +14 -0
- package/types/serverDataParser.d.ts +34 -0
- package/types/serverEventParser.d.ts +12 -0
- package/types/serverFrameParser.d.ts +385 -0
- package/types/sideEffects/checkGoals.d.ts +5 -0
- package/types/sideEffects/index.d.ts +12 -0
- package/types/sideStorage.d.ts +5 -0
- package/types/socketClient.d.ts +11 -0
- package/types/socketListener.d.ts +9 -0
- package/types/thunks.d.ts +4 -0
- package/types/types/actions.d.ts +157 -0
- package/types/types/clientEntities.d.ts +374 -0
- package/types/types/frames.d.ts +635 -0
- package/types/types/serverEntities.d.ts +408 -0
- package/types/types/state.d.ts +56 -0
- package/types/uploadFile.d.ts +19 -0
- package/types/validateFile/index.d.ts +3 -0
package/dist/customer-sdk.esm.js
CHANGED
|
@@ -8,7 +8,7 @@ import promiseTry from '@livechat/promise-try';
|
|
|
8
8
|
import createBackoff from '@livechat/backoff';
|
|
9
9
|
import storage from '@livechat/isomorphic-storage';
|
|
10
10
|
import unfetch from 'unfetch';
|
|
11
|
-
import { buildQueryString } from '@livechat/url-utils';
|
|
11
|
+
import { buildQueryString, removeProtocol } from '@livechat/url-utils';
|
|
12
12
|
import createPlatformClient from '@livechat/platform-client';
|
|
13
13
|
import rawUploadFile from '@livechat/file-upload';
|
|
14
14
|
|
|
@@ -16,50 +16,40 @@ function _extends() {
|
|
|
16
16
|
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
17
17
|
for (var i = 1; i < arguments.length; i++) {
|
|
18
18
|
var source = arguments[i];
|
|
19
|
-
|
|
20
19
|
for (var key in source) {
|
|
21
20
|
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
22
21
|
target[key] = source[key];
|
|
23
22
|
}
|
|
24
23
|
}
|
|
25
24
|
}
|
|
26
|
-
|
|
27
25
|
return target;
|
|
28
26
|
};
|
|
29
27
|
return _extends.apply(this, arguments);
|
|
30
28
|
}
|
|
31
|
-
|
|
32
29
|
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
33
30
|
if (source == null) return {};
|
|
34
31
|
var target = {};
|
|
35
32
|
var sourceKeys = Object.keys(source);
|
|
36
33
|
var key, i;
|
|
37
|
-
|
|
38
34
|
for (i = 0; i < sourceKeys.length; i++) {
|
|
39
35
|
key = sourceKeys[i];
|
|
40
36
|
if (excluded.indexOf(key) >= 0) continue;
|
|
41
37
|
target[key] = source[key];
|
|
42
38
|
}
|
|
43
|
-
|
|
44
39
|
return target;
|
|
45
40
|
}
|
|
46
|
-
|
|
47
41
|
function _toPrimitive(input, hint) {
|
|
48
42
|
if (typeof input !== "object" || input === null) return input;
|
|
49
43
|
var prim = input[Symbol.toPrimitive];
|
|
50
|
-
|
|
51
44
|
if (prim !== undefined) {
|
|
52
45
|
var res = prim.call(input, hint || "default");
|
|
53
46
|
if (typeof res !== "object") return res;
|
|
54
47
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
55
48
|
}
|
|
56
|
-
|
|
57
49
|
return (hint === "string" ? String : Number)(input);
|
|
58
50
|
}
|
|
59
|
-
|
|
60
51
|
function _toPropertyKey(arg) {
|
|
61
52
|
var key = _toPrimitive(arg, "string");
|
|
62
|
-
|
|
63
53
|
return typeof key === "symbol" ? key : String(key);
|
|
64
54
|
}
|
|
65
55
|
|
|
@@ -130,19 +120,16 @@ var createReducer = function createReducer(initialState, reducersMap) {
|
|
|
130
120
|
// eslint-disable-next-line no-console
|
|
131
121
|
console.warn(["Reducer contains an 'undefined' action type.", 'Have you misspelled a constant?'].join('\n'));
|
|
132
122
|
}
|
|
133
|
-
|
|
134
123
|
return function reducer(state, action) {
|
|
135
124
|
if (state === void 0) {
|
|
136
125
|
state = initialState;
|
|
137
126
|
}
|
|
138
|
-
|
|
139
127
|
if (hasOwn(action.type, reducersMap)) {
|
|
140
128
|
return reducersMap[action.type](state, action.payload);
|
|
141
129
|
}
|
|
142
|
-
|
|
143
130
|
return state;
|
|
144
131
|
};
|
|
145
|
-
};
|
|
132
|
+
};
|
|
146
133
|
|
|
147
134
|
var CONNECTED = 'connected';
|
|
148
135
|
var DESTROYED = 'destroyed';
|
|
@@ -175,22 +162,17 @@ var isConnected = function isConnected(state) {
|
|
|
175
162
|
var isDestroyed = function isDestroyed(state) {
|
|
176
163
|
return getConnectionStatus(state) === DESTROYED;
|
|
177
164
|
};
|
|
178
|
-
|
|
179
165
|
var getEnvPart = function getEnvPart(_ref) {
|
|
180
166
|
var licenseId = _ref.licenseId,
|
|
181
|
-
|
|
182
|
-
|
|
167
|
+
env = _ref.env;
|
|
183
168
|
if (licenseId === 1520) {
|
|
184
169
|
return '.staging';
|
|
185
170
|
}
|
|
186
|
-
|
|
187
171
|
if (env === 'production') {
|
|
188
172
|
return '';
|
|
189
173
|
}
|
|
190
|
-
|
|
191
174
|
return "." + env;
|
|
192
175
|
};
|
|
193
|
-
|
|
194
176
|
var getApiOrigin = function getApiOrigin(state) {
|
|
195
177
|
var region = state.region;
|
|
196
178
|
var regionPart = region ? "-" + region : '';
|
|
@@ -201,25 +183,25 @@ var getServerUrl = function getServerUrl(state) {
|
|
|
201
183
|
};
|
|
202
184
|
var createInitialState = function createInitialState(initialStateData) {
|
|
203
185
|
var _initialStateData$app = initialStateData.application,
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
186
|
+
application = _initialStateData$app === void 0 ? {} : _initialStateData$app,
|
|
187
|
+
licenseId = initialStateData.licenseId,
|
|
188
|
+
_initialStateData$gro = initialStateData.groupId,
|
|
189
|
+
groupId = _initialStateData$gro === void 0 ? null : _initialStateData$gro,
|
|
190
|
+
env = initialStateData.env,
|
|
191
|
+
_initialStateData$pag = initialStateData.page,
|
|
192
|
+
page = _initialStateData$pag === void 0 ? null : _initialStateData$pag,
|
|
193
|
+
_initialStateData$reg = initialStateData.region,
|
|
194
|
+
region = _initialStateData$reg === void 0 ? null : _initialStateData$reg,
|
|
195
|
+
_initialStateData$ref = initialStateData.referrer,
|
|
196
|
+
referrer = _initialStateData$ref === void 0 ? null : _initialStateData$ref,
|
|
197
|
+
_initialStateData$uni = initialStateData.uniqueGroups,
|
|
198
|
+
uniqueGroups = _initialStateData$uni === void 0 ? false : _initialStateData$uni,
|
|
199
|
+
_initialStateData$mob = initialStateData.mobile,
|
|
200
|
+
mobile = _initialStateData$mob === void 0 ? false : _initialStateData$mob;
|
|
219
201
|
return {
|
|
220
202
|
application: _extends({}, application, {
|
|
221
203
|
name: "customer_sdk",
|
|
222
|
-
version: "3.1.
|
|
204
|
+
version: "3.1.2"
|
|
223
205
|
}),
|
|
224
206
|
licenseId: licenseId,
|
|
225
207
|
env: env,
|
|
@@ -243,18 +225,14 @@ var createInitialState = function createInitialState(initialStateData) {
|
|
|
243
225
|
mobile: mobile
|
|
244
226
|
};
|
|
245
227
|
};
|
|
246
|
-
|
|
247
228
|
var removeStoredRequest = function removeStoredRequest(state, _ref2) {
|
|
248
229
|
var id = _ref2.id;
|
|
249
|
-
|
|
250
230
|
var _state$requests = state.requests,
|
|
251
|
-
|
|
252
|
-
|
|
231
|
+
requests = _objectWithoutPropertiesLoose(_state$requests, [id].map(_toPropertyKey));
|
|
253
232
|
return _extends({}, state, {
|
|
254
233
|
requests: requests
|
|
255
234
|
});
|
|
256
235
|
};
|
|
257
|
-
|
|
258
236
|
var setConnectionStatus = function setConnectionStatus(status, state) {
|
|
259
237
|
return _extends({}, state, {
|
|
260
238
|
connection: _extends({}, state.connection, {
|
|
@@ -262,10 +240,8 @@ var setConnectionStatus = function setConnectionStatus(status, state) {
|
|
|
262
240
|
})
|
|
263
241
|
});
|
|
264
242
|
};
|
|
265
|
-
|
|
266
243
|
var createReducer$1 = (function (state) {
|
|
267
244
|
var _createReducer;
|
|
268
|
-
|
|
269
245
|
return createReducer(state, (_createReducer = {}, _createReducer[CHANGE_REGION] = function (state, _ref3) {
|
|
270
246
|
var region = _ref3.region;
|
|
271
247
|
return _extends({}, state, {
|
|
@@ -279,12 +255,11 @@ var createReducer$1 = (function (state) {
|
|
|
279
255
|
return setConnectionStatus(PAUSED, state);
|
|
280
256
|
}, _createReducer[REQUEST_FAILED] = removeStoredRequest, _createReducer[RESPONSE_RECEIVED] = removeStoredRequest, _createReducer[PUSH_RESPONSE_RECEIVED] = removeStoredRequest, _createReducer[SEND_REQUEST] = function (state, _ref4) {
|
|
281
257
|
var _extends2;
|
|
282
|
-
|
|
283
258
|
var promise = _ref4.promise,
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
259
|
+
resolve = _ref4.resolve,
|
|
260
|
+
reject = _ref4.reject,
|
|
261
|
+
id = _ref4.id,
|
|
262
|
+
request = _ref4.request;
|
|
288
263
|
return _extends({}, state, {
|
|
289
264
|
requests: _extends({}, state.requests, (_extends2 = {}, _extends2[id] = {
|
|
290
265
|
id: id,
|
|
@@ -296,9 +271,8 @@ var createReducer$1 = (function (state) {
|
|
|
296
271
|
});
|
|
297
272
|
}, _createReducer[SET_CHAT_ACTIVE] = function (state, _ref5) {
|
|
298
273
|
var _extends3;
|
|
299
|
-
|
|
300
274
|
var id = _ref5.id,
|
|
301
|
-
|
|
275
|
+
active = _ref5.active;
|
|
302
276
|
return _extends({}, state, {
|
|
303
277
|
chats: _extends({}, state.chats, (_extends3 = {}, _extends3[id] = _extends({}, state.chats[id], {
|
|
304
278
|
active: active
|
|
@@ -314,11 +288,9 @@ var createReducer$1 = (function (state) {
|
|
|
314
288
|
});
|
|
315
289
|
}, _createReducer[SOCKET_DISCONNECTED] = function (state) {
|
|
316
290
|
var previousStatus = getConnectionStatus(state);
|
|
317
|
-
|
|
318
291
|
if (process.env.NODE_ENV !== 'production' && (previousStatus === PAUSED || previousStatus === DESTROYED)) {
|
|
319
292
|
throw new Error("Got 'socket_disconnected' action when in " + previousStatus + " state. This should be an impossible state.");
|
|
320
293
|
}
|
|
321
|
-
|
|
322
294
|
var state1 = setConnectionStatus(previousStatus === DISCONNECTED ? DISCONNECTED : RECONNECTING, state);
|
|
323
295
|
return _extends({}, state1, {
|
|
324
296
|
requests: {}
|
|
@@ -342,27 +314,27 @@ function finalCreateStore(initialStateData) {
|
|
|
342
314
|
|
|
343
315
|
function createError(_ref) {
|
|
344
316
|
var message = _ref.message,
|
|
345
|
-
|
|
317
|
+
code = _ref.code;
|
|
346
318
|
var error = new Error(message);
|
|
347
319
|
error.code = code;
|
|
348
320
|
return error;
|
|
349
321
|
}
|
|
350
322
|
|
|
351
323
|
var ACCESS_TOKEN_EXPIRED = 'access_token_expired';
|
|
352
|
-
var CUSTOMER_BANNED = 'customer_banned';
|
|
353
|
-
|
|
324
|
+
var CUSTOMER_BANNED = 'customer_banned';
|
|
325
|
+
// customer tried reconnecting too many times after they received too_many_connections error
|
|
354
326
|
var CUSTOMER_TEMPORARILY_BLOCKED = 'customer_temporarily_blocked';
|
|
355
327
|
var LICENSE_EXPIRED = 'license_expired';
|
|
356
328
|
var LICENSE_NOT_FOUND = 'license_not_found';
|
|
357
329
|
var MISDIRECTED_CONNECTION$1 = 'misdirected_connection';
|
|
358
|
-
var PRODUCT_VERSION_CHANGED = 'product_version_changed';
|
|
330
|
+
var PRODUCT_VERSION_CHANGED = 'product_version_changed';
|
|
331
|
+
// the limit of connections per user host has been exceeded
|
|
359
332
|
// or rate limit for new connections has been hit
|
|
360
333
|
// (in 3.2 only the latter case, the first one is using `too_many_connections` to avoid breaking changes)
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
334
|
+
var SERVICE_TEMPORARILY_UNAVAILABLE$1 = 'service_temporarily_unavailable';
|
|
335
|
+
// the limit of those connections is per user
|
|
336
|
+
var TOO_MANY_CONNECTIONS = 'too_many_connections';
|
|
337
|
+
// the limit of unauthorized connections is per IP
|
|
366
338
|
var TOO_MANY_UNAUTHORIZED_CONNECTIONS = 'too_many_unauthorized_connections';
|
|
367
339
|
var UNSUPPORTED_VERSION = 'unsupported_version';
|
|
368
340
|
|
|
@@ -431,20 +403,17 @@ var CUSTOM = 'custom';
|
|
|
431
403
|
|
|
432
404
|
var createEventBase = function createEventBase(event) {
|
|
433
405
|
var base = {};
|
|
434
|
-
|
|
435
406
|
if (typeof event.customId === 'string') {
|
|
436
407
|
base.custom_id = event.customId;
|
|
437
408
|
}
|
|
438
|
-
|
|
439
409
|
if (isObject(event.properties)) {
|
|
440
410
|
base.properties = event.properties;
|
|
441
411
|
}
|
|
442
|
-
|
|
443
412
|
return base;
|
|
444
|
-
};
|
|
445
|
-
// but should we? maybe only in DEV mode?
|
|
446
|
-
|
|
413
|
+
};
|
|
447
414
|
|
|
415
|
+
// TODO: we could validate and throw here
|
|
416
|
+
// but should we? maybe only in DEV mode?
|
|
448
417
|
var parseEvent = function parseEvent(event) {
|
|
449
418
|
switch (event.type) {
|
|
450
419
|
case MESSAGE:
|
|
@@ -453,7 +422,6 @@ var parseEvent = function parseEvent(event) {
|
|
|
453
422
|
type: event.type,
|
|
454
423
|
text: event.text
|
|
455
424
|
});
|
|
456
|
-
|
|
457
425
|
if (event.postback) {
|
|
458
426
|
message.postback = {
|
|
459
427
|
id: event.postback.id,
|
|
@@ -463,10 +431,8 @@ var parseEvent = function parseEvent(event) {
|
|
|
463
431
|
value: event.postback.value
|
|
464
432
|
};
|
|
465
433
|
}
|
|
466
|
-
|
|
467
434
|
return message;
|
|
468
435
|
}
|
|
469
|
-
|
|
470
436
|
case FILE:
|
|
471
437
|
{
|
|
472
438
|
var file = _extends({}, createEventBase(event), {
|
|
@@ -474,10 +440,8 @@ var parseEvent = function parseEvent(event) {
|
|
|
474
440
|
url: event.url,
|
|
475
441
|
alternative_text: event.alternativeText
|
|
476
442
|
});
|
|
477
|
-
|
|
478
443
|
return file;
|
|
479
444
|
}
|
|
480
|
-
|
|
481
445
|
case FILLED_FORM:
|
|
482
446
|
{
|
|
483
447
|
var filledForm = _extends({}, createEventBase(event), {
|
|
@@ -490,27 +454,22 @@ var parseEvent = function parseEvent(event) {
|
|
|
490
454
|
if (!field.answer) {
|
|
491
455
|
return field;
|
|
492
456
|
}
|
|
493
|
-
|
|
494
457
|
var _field$answer = field.answer,
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
458
|
+
groupId = _field$answer.groupId,
|
|
459
|
+
answer = _objectWithoutPropertiesLoose(_field$answer, ["groupId"]);
|
|
498
460
|
return _extends({}, field, {
|
|
499
461
|
answer: _extends({}, answer, {
|
|
500
462
|
group_id: groupId
|
|
501
463
|
})
|
|
502
464
|
});
|
|
503
465
|
}
|
|
504
|
-
|
|
505
466
|
default:
|
|
506
467
|
return field;
|
|
507
468
|
}
|
|
508
469
|
})
|
|
509
470
|
});
|
|
510
|
-
|
|
511
471
|
return filledForm;
|
|
512
472
|
}
|
|
513
|
-
|
|
514
473
|
case SYSTEM_MESSAGE:
|
|
515
474
|
{
|
|
516
475
|
var systemMessage = _extends({}, createEventBase(event), {
|
|
@@ -518,81 +477,64 @@ var parseEvent = function parseEvent(event) {
|
|
|
518
477
|
text: event.text,
|
|
519
478
|
system_message_type: event.systemMessageType
|
|
520
479
|
});
|
|
521
|
-
|
|
522
480
|
if (event.recipients) {
|
|
523
481
|
systemMessage.recipients = event.recipients;
|
|
524
482
|
}
|
|
525
|
-
|
|
526
483
|
return systemMessage;
|
|
527
484
|
}
|
|
528
|
-
|
|
529
485
|
case CUSTOM:
|
|
530
486
|
{
|
|
531
487
|
var customEvent = _extends({}, createEventBase(event), {
|
|
532
488
|
type: event.type
|
|
533
489
|
});
|
|
534
|
-
|
|
535
490
|
if (event.content) {
|
|
536
491
|
customEvent.content = event.content;
|
|
537
492
|
}
|
|
538
|
-
|
|
539
493
|
return customEvent;
|
|
540
494
|
}
|
|
541
495
|
}
|
|
542
496
|
};
|
|
543
|
-
|
|
544
497
|
var parseThreadData = function parseThreadData(thread) {
|
|
545
498
|
var data = {};
|
|
546
499
|
var events = thread.events,
|
|
547
|
-
|
|
548
|
-
|
|
500
|
+
properties = thread.properties;
|
|
549
501
|
if (events) {
|
|
550
502
|
data.events = events.map(parseEvent);
|
|
551
503
|
}
|
|
552
|
-
|
|
553
504
|
if (properties) {
|
|
554
505
|
data.properties = properties;
|
|
555
506
|
}
|
|
556
|
-
|
|
557
507
|
return data;
|
|
558
508
|
};
|
|
559
|
-
|
|
560
509
|
var parseStartChatData = function parseStartChatData(_ref) {
|
|
561
510
|
var _ref$active = _ref.active,
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
511
|
+
active = _ref$active === void 0 ? true : _ref$active,
|
|
512
|
+
chat = _ref.chat,
|
|
513
|
+
continuous = _ref.continuous;
|
|
565
514
|
var data = {
|
|
566
515
|
active: active,
|
|
567
516
|
chat: {}
|
|
568
517
|
};
|
|
569
|
-
|
|
570
518
|
if (typeof continuous === 'boolean') {
|
|
571
519
|
data.continuous = continuous;
|
|
572
520
|
}
|
|
573
|
-
|
|
574
521
|
if (!chat) {
|
|
575
522
|
return data;
|
|
576
523
|
}
|
|
577
|
-
|
|
578
524
|
var access = chat.access,
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
525
|
+
thread = chat.thread,
|
|
526
|
+
properties = chat.properties;
|
|
582
527
|
if (access && access.groupIds) {
|
|
583
528
|
data.chat.access = {
|
|
584
529
|
group_ids: access.groupIds
|
|
585
530
|
};
|
|
586
531
|
}
|
|
587
|
-
|
|
588
532
|
if (properties) {
|
|
589
533
|
data.chat.properties = properties;
|
|
590
534
|
}
|
|
591
|
-
|
|
592
535
|
if (thread) {
|
|
593
536
|
data.chat.thread = parseThreadData(thread);
|
|
594
537
|
}
|
|
595
|
-
|
|
596
538
|
return data;
|
|
597
539
|
};
|
|
598
540
|
var parseResumeChatData = function parseResumeChatData(requestData) {
|
|
@@ -606,19 +548,16 @@ var parseResumeChatData = function parseResumeChatData(requestData) {
|
|
|
606
548
|
var parseCustomerSessionFields = function parseCustomerSessionFields(sessionFields) {
|
|
607
549
|
return toPairs(sessionFields).map(function (_ref2) {
|
|
608
550
|
var _ref3;
|
|
609
|
-
|
|
610
551
|
var key = _ref2[0],
|
|
611
|
-
|
|
552
|
+
value = _ref2[1];
|
|
612
553
|
return _ref3 = {}, _ref3[key] = value, _ref3;
|
|
613
554
|
});
|
|
614
555
|
};
|
|
615
556
|
var parseCustomerUpdate = function parseCustomerUpdate(update) {
|
|
616
557
|
var result = pickOwn(['avatar', 'name', 'email'], update);
|
|
617
|
-
|
|
618
558
|
if (update.sessionFields) {
|
|
619
559
|
result.session_fields = parseCustomerSessionFields(update.sessionFields);
|
|
620
560
|
}
|
|
621
|
-
|
|
622
561
|
return result;
|
|
623
562
|
};
|
|
624
563
|
|
|
@@ -648,7 +587,6 @@ var prefetchToken = function prefetchToken(fresh) {
|
|
|
648
587
|
if (fresh === void 0) {
|
|
649
588
|
fresh = false;
|
|
650
589
|
}
|
|
651
|
-
|
|
652
590
|
return {
|
|
653
591
|
type: PREFETCH_TOKEN,
|
|
654
592
|
payload: {
|
|
@@ -663,9 +601,10 @@ var reconnect = function reconnect(delay) {
|
|
|
663
601
|
delay: delay
|
|
664
602
|
}
|
|
665
603
|
};
|
|
666
|
-
};
|
|
667
|
-
// we should explore providing stricter types for this in the future
|
|
604
|
+
};
|
|
668
605
|
|
|
606
|
+
// TODO: this one was currently pretty hard to type in full
|
|
607
|
+
// we should explore providing stricter types for this in the future
|
|
669
608
|
var sendRequest = function sendRequest(action, payload, source) {
|
|
670
609
|
return {
|
|
671
610
|
type: SEND_REQUEST,
|
|
@@ -681,17 +620,15 @@ var sendRequest = function sendRequest(action, payload, source) {
|
|
|
681
620
|
};
|
|
682
621
|
var sendEvent = function sendEvent(_ref) {
|
|
683
622
|
var chatId = _ref.chatId,
|
|
684
|
-
|
|
685
|
-
|
|
623
|
+
event = _ref.event,
|
|
624
|
+
attachToLastThread = _ref.attachToLastThread;
|
|
686
625
|
var payload = {
|
|
687
626
|
chat_id: chatId,
|
|
688
627
|
event: parseEvent(event)
|
|
689
628
|
};
|
|
690
|
-
|
|
691
629
|
if (attachToLastThread) {
|
|
692
630
|
payload.attach_to_last_thread = true;
|
|
693
631
|
}
|
|
694
|
-
|
|
695
632
|
return sendRequest(SEND_EVENT, payload);
|
|
696
633
|
};
|
|
697
634
|
var setChatActive = function setChatActive(id, active) {
|
|
@@ -720,12 +657,10 @@ var socketDisconnected = function socketDisconnected() {
|
|
|
720
657
|
// TODO: this thing is not really well typed and should be improved
|
|
721
658
|
var sendRequestAction = function sendRequestAction(store, action) {
|
|
722
659
|
action.payload.id = generateUniqueId(store.getState().requests);
|
|
723
|
-
|
|
724
660
|
var _deferred = deferred(),
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
661
|
+
resolve = _deferred.resolve,
|
|
662
|
+
reject = _deferred.reject,
|
|
663
|
+
promise = _deferred.promise;
|
|
729
664
|
action.payload.promise = promise;
|
|
730
665
|
action.payload.resolve = resolve;
|
|
731
666
|
action.payload.reject = reject;
|
|
@@ -740,17 +675,16 @@ var WRONG_PRODUCT_VERSION = 'WRONG_PRODUCT_VERSION';
|
|
|
740
675
|
|
|
741
676
|
var getSideStorageKey = function getSideStorageKey(store) {
|
|
742
677
|
var _store$getState = store.getState(),
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
678
|
+
licenseId = _store$getState.licenseId,
|
|
679
|
+
groupId = _store$getState.groupId,
|
|
680
|
+
uniqueGroups = _store$getState.uniqueGroups;
|
|
747
681
|
return "side_storage_" + licenseId + (uniqueGroups ? ":" + groupId : '');
|
|
748
682
|
};
|
|
749
|
-
|
|
750
683
|
var getSideStorage = function getSideStorage(store) {
|
|
751
684
|
return storage.getItem(getSideStorageKey(store))["catch"](noop).then(function (sideStorage) {
|
|
752
685
|
return JSON.parse(sideStorage || '{}');
|
|
753
|
-
})
|
|
686
|
+
})
|
|
687
|
+
// shouldnt get triggered, just a defensive measure against malformed storage entries
|
|
754
688
|
["catch"](function () {
|
|
755
689
|
return {};
|
|
756
690
|
});
|
|
@@ -761,9 +695,7 @@ var saveSideStorage = function saveSideStorage(store, sideStorage) {
|
|
|
761
695
|
|
|
762
696
|
var taskChain = function taskChain(_ref, onSuccess, onError) {
|
|
763
697
|
var steps = _ref.slice(0);
|
|
764
|
-
|
|
765
698
|
var cancelled = false;
|
|
766
|
-
|
|
767
699
|
var next = function next(intermediateResult) {
|
|
768
700
|
var step = steps.shift();
|
|
769
701
|
promiseTry(function () {
|
|
@@ -772,22 +704,18 @@ var taskChain = function taskChain(_ref, onSuccess, onError) {
|
|
|
772
704
|
if (cancelled) {
|
|
773
705
|
return;
|
|
774
706
|
}
|
|
775
|
-
|
|
776
707
|
if (steps.length) {
|
|
777
708
|
next(result);
|
|
778
709
|
return;
|
|
779
710
|
}
|
|
780
|
-
|
|
781
711
|
onSuccess(result);
|
|
782
712
|
}, function (error) {
|
|
783
713
|
if (cancelled) {
|
|
784
714
|
return;
|
|
785
715
|
}
|
|
786
|
-
|
|
787
716
|
onError(error);
|
|
788
717
|
});
|
|
789
718
|
};
|
|
790
|
-
|
|
791
719
|
next();
|
|
792
720
|
return {
|
|
793
721
|
cancel: function cancel() {
|
|
@@ -795,17 +723,14 @@ var taskChain = function taskChain(_ref, onSuccess, onError) {
|
|
|
795
723
|
}
|
|
796
724
|
};
|
|
797
725
|
};
|
|
798
|
-
|
|
799
726
|
var sendLoginFlowRequest = function sendLoginFlowRequest(store, type, payload) {
|
|
800
727
|
return sendRequestAction(store, sendRequest(type, payload, 'login'));
|
|
801
728
|
};
|
|
802
|
-
|
|
803
729
|
var delay = function delay(ms) {
|
|
804
730
|
return new Promise(function (resolve) {
|
|
805
731
|
setTimeout(resolve, ms);
|
|
806
732
|
});
|
|
807
733
|
};
|
|
808
|
-
|
|
809
734
|
function createLoginTask(auth, customerDataProvider) {
|
|
810
735
|
var store;
|
|
811
736
|
var sentPage = null;
|
|
@@ -820,24 +745,19 @@ function createLoginTask(auth, customerDataProvider) {
|
|
|
820
745
|
min: 1000
|
|
821
746
|
}));
|
|
822
747
|
var currentBackoffStrategy = defaultBackoffStrategy;
|
|
823
|
-
|
|
824
748
|
var destroy$1 = function destroy$1(reason) {
|
|
825
749
|
return store.dispatch(destroy(reason));
|
|
826
750
|
};
|
|
827
|
-
|
|
828
751
|
var reconnect$1 = function reconnect$1() {
|
|
829
752
|
return store.dispatch(reconnect(currentBackoffStrategy.duration()));
|
|
830
753
|
};
|
|
831
|
-
|
|
832
754
|
var getTokenAndSideStorage = function getTokenAndSideStorage() {
|
|
833
755
|
return Promise.all([auth.getToken(), getSideStorage(store)]);
|
|
834
756
|
};
|
|
835
|
-
|
|
836
757
|
var dispatchSelfId = function dispatchSelfId(_ref2) {
|
|
837
758
|
var token = _ref2[0],
|
|
838
|
-
|
|
759
|
+
sideStorage = _ref2[1];
|
|
839
760
|
var selfId = getSelfId(store.getState());
|
|
840
|
-
|
|
841
761
|
if (selfId === null) {
|
|
842
762
|
store.dispatch(setSelfId(token.entityId));
|
|
843
763
|
} else if (selfId !== token.entityId) {
|
|
@@ -845,19 +765,17 @@ function createLoginTask(auth, customerDataProvider) {
|
|
|
845
765
|
err.code = IDENTITY_MISMATCH;
|
|
846
766
|
throw err;
|
|
847
767
|
}
|
|
848
|
-
|
|
849
768
|
return [token, sideStorage];
|
|
850
769
|
};
|
|
851
|
-
|
|
852
770
|
var _sendLogin = function sendLogin(_ref3) {
|
|
853
771
|
var token = _ref3[0],
|
|
854
|
-
|
|
772
|
+
sideStorage = _ref3[1];
|
|
855
773
|
var state = store.getState();
|
|
856
774
|
var application = state.application,
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
775
|
+
groupId = state.groupId,
|
|
776
|
+
page = state.page,
|
|
777
|
+
referrer = state.referrer,
|
|
778
|
+
mobile = state.mobile;
|
|
861
779
|
var payload = {
|
|
862
780
|
token: token.tokenType + " " + token.accessToken,
|
|
863
781
|
customer: typeof customerDataProvider === 'function' ? parseCustomerUpdate(customerDataProvider()) : {},
|
|
@@ -865,24 +783,19 @@ function createLoginTask(auth, customerDataProvider) {
|
|
|
865
783
|
is_mobile: mobile,
|
|
866
784
|
application: pick(['name', 'version'], application)
|
|
867
785
|
};
|
|
868
|
-
|
|
869
786
|
if (typeof groupId === 'number') {
|
|
870
787
|
payload.group_id = groupId;
|
|
871
788
|
}
|
|
872
|
-
|
|
873
789
|
if (application.channelType) {
|
|
874
790
|
payload.application.channel_type = application.channelType;
|
|
875
791
|
}
|
|
876
|
-
|
|
877
792
|
if (page !== null) {
|
|
878
793
|
sentPage = page;
|
|
879
794
|
payload.customer_page = page;
|
|
880
795
|
}
|
|
881
|
-
|
|
882
796
|
if (referrer !== null) {
|
|
883
797
|
payload.referrer = referrer;
|
|
884
798
|
}
|
|
885
|
-
|
|
886
799
|
return Promise.race([sendLoginFlowRequest(store, LOGIN, payload), delay(15 * 1000).then(function () {
|
|
887
800
|
return Promise.reject(createError({
|
|
888
801
|
message: 'Request timed out.',
|
|
@@ -890,22 +803,17 @@ function createLoginTask(auth, customerDataProvider) {
|
|
|
890
803
|
}));
|
|
891
804
|
})]);
|
|
892
805
|
};
|
|
893
|
-
|
|
894
806
|
var updateCustomerPageIfNeeded = function updateCustomerPageIfNeeded() {
|
|
895
807
|
var _store$getState = store.getState(),
|
|
896
|
-
|
|
897
|
-
|
|
808
|
+
page = _store$getState.page;
|
|
898
809
|
if (sentPage !== page) {
|
|
899
810
|
sendLoginFlowRequest(store, UPDATE_CUSTOMER_PAGE$1, page)["catch"](noop);
|
|
900
811
|
}
|
|
901
|
-
|
|
902
812
|
sentPage = null;
|
|
903
813
|
};
|
|
904
|
-
|
|
905
814
|
return {
|
|
906
815
|
sendLogin: function sendLogin(_store) {
|
|
907
816
|
var _task;
|
|
908
|
-
|
|
909
817
|
// after switching to callbags, we should be able to use smth similar to redux-observable
|
|
910
818
|
// and thus just use store given to epic
|
|
911
819
|
store = _store;
|
|
@@ -914,62 +822,52 @@ function createLoginTask(auth, customerDataProvider) {
|
|
|
914
822
|
task = null;
|
|
915
823
|
defaultBackoffStrategy.reset();
|
|
916
824
|
slowerBackoffStrategy.reset();
|
|
917
|
-
currentBackoffStrategy = defaultBackoffStrategy;
|
|
825
|
+
currentBackoffStrategy = defaultBackoffStrategy;
|
|
918
826
|
|
|
827
|
+
// TODO: rethink if this should be handled by SDK consumer
|
|
919
828
|
updateCustomerPageIfNeeded();
|
|
920
829
|
store.dispatch(loginSuccess(loginResponse));
|
|
921
830
|
}, function (error) {
|
|
922
831
|
task = null;
|
|
923
|
-
|
|
924
832
|
if (process.env.NODE_ENV !== 'production') {
|
|
925
833
|
console.error('[Customer SDK] Login flow has thrown code', error.code, 'with', error);
|
|
926
834
|
}
|
|
927
|
-
|
|
928
835
|
switch (error.code) {
|
|
929
836
|
case AUTHENTICATION:
|
|
930
837
|
auth.getFreshToken();
|
|
931
838
|
reconnect$1();
|
|
932
839
|
return;
|
|
933
|
-
|
|
934
840
|
case CONNECTION_LOST:
|
|
935
841
|
// this is connectivity problem, not a server error
|
|
936
842
|
// and is taken care of in socket module
|
|
937
843
|
// as it has its own backoff implementation
|
|
938
844
|
return;
|
|
939
|
-
|
|
940
845
|
case MISDIRECTED_CONNECTION:
|
|
941
846
|
// socket gets reinitialized on this anyway, so just ignore it here
|
|
942
847
|
return;
|
|
943
|
-
|
|
944
848
|
case SDK_DESTROYED:
|
|
945
849
|
return;
|
|
946
850
|
// those are auth errors, we should maybe export those constants from the auth package
|
|
947
|
-
|
|
948
851
|
case 'SSO_IDENTITY_EXCEPTION':
|
|
949
852
|
case 'SSO_OAUTH_EXCEPTION':
|
|
950
853
|
if (error.message === 'server_error' || error.message === 'temporarily_unavailable') {
|
|
951
854
|
reconnect$1();
|
|
952
855
|
return;
|
|
953
856
|
}
|
|
954
|
-
|
|
955
857
|
destroy$1(error.message);
|
|
956
858
|
return;
|
|
957
|
-
|
|
958
859
|
case USERS_LIMIT_REACHED:
|
|
959
860
|
store.dispatch(pauseConnection(error.code.toLowerCase()));
|
|
960
861
|
return;
|
|
961
|
-
|
|
962
862
|
case IDENTITY_MISMATCH:
|
|
963
863
|
case CUSTOMER_BANNED$1:
|
|
964
864
|
case WRONG_PRODUCT_VERSION:
|
|
965
865
|
destroy$1(error.code.toLowerCase());
|
|
966
866
|
return;
|
|
967
|
-
|
|
968
867
|
case SERVICE_TEMPORARILY_UNAVAILABLE:
|
|
969
868
|
currentBackoffStrategy = slowerBackoffStrategy;
|
|
970
869
|
reconnect$1();
|
|
971
870
|
return;
|
|
972
|
-
|
|
973
871
|
default:
|
|
974
872
|
reconnect$1();
|
|
975
873
|
return;
|
|
@@ -978,7 +876,6 @@ function createLoginTask(auth, customerDataProvider) {
|
|
|
978
876
|
},
|
|
979
877
|
cancel: function cancel() {
|
|
980
878
|
var _task2;
|
|
981
|
-
|
|
982
879
|
(_task2 = task) == null ? void 0 : _task2.cancel();
|
|
983
880
|
}
|
|
984
881
|
};
|
|
@@ -987,17 +884,13 @@ function createLoginTask(auth, customerDataProvider) {
|
|
|
987
884
|
var checkGoals = function checkGoals(store, auth, sessionFields) {
|
|
988
885
|
return auth.getToken().then(function (token) {
|
|
989
886
|
var state = store.getState();
|
|
990
|
-
|
|
991
887
|
if (getSelfId(state) === null) {
|
|
992
888
|
store.dispatch(setSelfId(token.entityId));
|
|
993
889
|
}
|
|
994
|
-
|
|
995
890
|
var page = state.page;
|
|
996
|
-
|
|
997
891
|
if (!page || !page.url) {
|
|
998
892
|
return;
|
|
999
893
|
}
|
|
1000
|
-
|
|
1001
894
|
var query = buildQueryString({
|
|
1002
895
|
license_id: state.licenseId
|
|
1003
896
|
});
|
|
@@ -1022,7 +915,7 @@ var checkGoals = function checkGoals(store, auth, sessionFields) {
|
|
|
1022
915
|
|
|
1023
916
|
var failAllRequests = function failAllRequests(_ref, reason) {
|
|
1024
917
|
var getState = _ref.getState,
|
|
1025
|
-
|
|
918
|
+
dispatch = _ref.dispatch;
|
|
1026
919
|
var state = getState();
|
|
1027
920
|
var requests = getAllRequests(state);
|
|
1028
921
|
dispatch({
|
|
@@ -1037,7 +930,7 @@ var failAllRequests = function failAllRequests(_ref, reason) {
|
|
|
1037
930
|
};
|
|
1038
931
|
var failRequest = function failRequest(_ref2, requestAction, error) {
|
|
1039
932
|
var getState = _ref2.getState,
|
|
1040
|
-
|
|
933
|
+
dispatch = _ref2.dispatch;
|
|
1041
934
|
var requestId = requestAction.payload.id;
|
|
1042
935
|
dispatch({
|
|
1043
936
|
type: REQUEST_FAILED,
|
|
@@ -1061,22 +954,17 @@ var parseCommonEventProps = function parseCommonEventProps(threadId, event) {
|
|
|
1061
954
|
threadId: threadId,
|
|
1062
955
|
properties: event.properties || {}
|
|
1063
956
|
};
|
|
1064
|
-
|
|
1065
957
|
if (event.custom_id !== undefined) {
|
|
1066
958
|
parsed.customId = event.custom_id;
|
|
1067
959
|
}
|
|
1068
|
-
|
|
1069
960
|
return parsed;
|
|
1070
961
|
};
|
|
1071
|
-
|
|
1072
962
|
var downsizeWithRatio = function downsizeWithRatio(max, dimensions) {
|
|
1073
963
|
var _ref;
|
|
1074
|
-
|
|
1075
964
|
var biggerProp;
|
|
1076
965
|
var smallerProp;
|
|
1077
966
|
var bigger;
|
|
1078
967
|
var smaller;
|
|
1079
|
-
|
|
1080
968
|
if (dimensions.height > dimensions.width) {
|
|
1081
969
|
biggerProp = 'height';
|
|
1082
970
|
smallerProp = 'width';
|
|
@@ -1088,11 +976,9 @@ var downsizeWithRatio = function downsizeWithRatio(max, dimensions) {
|
|
|
1088
976
|
bigger = dimensions.width;
|
|
1089
977
|
smaller = dimensions.height;
|
|
1090
978
|
}
|
|
1091
|
-
|
|
1092
979
|
var ratio = max / bigger;
|
|
1093
980
|
return _ref = {}, _ref[biggerProp] = Math.ceil(Math.min(bigger, max)), _ref[smallerProp] = Math.ceil(Math.min(ratio * smaller, smaller)), _ref;
|
|
1094
981
|
};
|
|
1095
|
-
|
|
1096
982
|
var parseImage = function parseImage(thread, image) {
|
|
1097
983
|
return _extends({}, parseCommonEventProps(thread, image), {
|
|
1098
984
|
type: FILE,
|
|
@@ -1113,12 +999,10 @@ var parseImage = function parseImage(thread, image) {
|
|
|
1113
999
|
alternativeText: image.alternative_text
|
|
1114
1000
|
});
|
|
1115
1001
|
};
|
|
1116
|
-
|
|
1117
1002
|
var parseFile = function parseFile(thread, file) {
|
|
1118
1003
|
if (file.width !== undefined && file.height !== undefined) {
|
|
1119
1004
|
return parseImage(thread, file);
|
|
1120
1005
|
}
|
|
1121
|
-
|
|
1122
1006
|
return _extends({}, parseCommonEventProps(thread, file), {
|
|
1123
1007
|
type: FILE,
|
|
1124
1008
|
contentType: file.content_type,
|
|
@@ -1145,18 +1029,15 @@ var parseFilledForm = function parseFilledForm(thread, filledForm) {
|
|
|
1145
1029
|
if (!field.answer) {
|
|
1146
1030
|
return field;
|
|
1147
1031
|
}
|
|
1148
|
-
|
|
1149
1032
|
var _field$answer = field.answer,
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1033
|
+
groupId = _field$answer.group_id,
|
|
1034
|
+
answer = _objectWithoutPropertiesLoose(_field$answer, ["group_id"]);
|
|
1153
1035
|
return _extends({}, field, {
|
|
1154
1036
|
answer: _extends({}, answer, {
|
|
1155
1037
|
groupId: groupId
|
|
1156
1038
|
})
|
|
1157
1039
|
});
|
|
1158
1040
|
}
|
|
1159
|
-
|
|
1160
1041
|
default:
|
|
1161
1042
|
return field;
|
|
1162
1043
|
}
|
|
@@ -1176,18 +1057,14 @@ var parseCustomEvent = function parseCustomEvent(thread, event) {
|
|
|
1176
1057
|
content: event.content
|
|
1177
1058
|
});
|
|
1178
1059
|
};
|
|
1179
|
-
|
|
1180
1060
|
var parseRichMessageElement = function parseRichMessageElement(element) {
|
|
1181
1061
|
var parsed = {};
|
|
1182
|
-
|
|
1183
1062
|
if (typeof element.title === 'string') {
|
|
1184
1063
|
parsed.title = element.title;
|
|
1185
1064
|
}
|
|
1186
|
-
|
|
1187
1065
|
if (typeof element.subtitle === 'string') {
|
|
1188
1066
|
parsed.subtitle = element.subtitle;
|
|
1189
1067
|
}
|
|
1190
|
-
|
|
1191
1068
|
if (element.image) {
|
|
1192
1069
|
// TODO: we should reuse parseImage here
|
|
1193
1070
|
var image = element.image;
|
|
@@ -1198,7 +1075,6 @@ var parseRichMessageElement = function parseRichMessageElement(element) {
|
|
|
1198
1075
|
alternativeText: image.alternative_text
|
|
1199
1076
|
});
|
|
1200
1077
|
}
|
|
1201
|
-
|
|
1202
1078
|
if (element.buttons) {
|
|
1203
1079
|
parsed.buttons = element.buttons.map(function (serverButton) {
|
|
1204
1080
|
switch (serverButton.type) {
|
|
@@ -1214,7 +1090,6 @@ var parseRichMessageElement = function parseRichMessageElement(element) {
|
|
|
1214
1090
|
role: serverButton.role || 'default'
|
|
1215
1091
|
};
|
|
1216
1092
|
}
|
|
1217
|
-
|
|
1218
1093
|
case 'cancel':
|
|
1219
1094
|
{
|
|
1220
1095
|
return {
|
|
@@ -1225,7 +1100,6 @@ var parseRichMessageElement = function parseRichMessageElement(element) {
|
|
|
1225
1100
|
role: serverButton.role || 'default'
|
|
1226
1101
|
};
|
|
1227
1102
|
}
|
|
1228
|
-
|
|
1229
1103
|
case 'url':
|
|
1230
1104
|
{
|
|
1231
1105
|
var button = {
|
|
@@ -1236,14 +1110,11 @@ var parseRichMessageElement = function parseRichMessageElement(element) {
|
|
|
1236
1110
|
value: serverButton.value,
|
|
1237
1111
|
role: serverButton.role || 'default'
|
|
1238
1112
|
};
|
|
1239
|
-
|
|
1240
1113
|
if (serverButton.target) {
|
|
1241
1114
|
button.target = serverButton.target;
|
|
1242
1115
|
}
|
|
1243
|
-
|
|
1244
1116
|
return button;
|
|
1245
1117
|
}
|
|
1246
|
-
|
|
1247
1118
|
case 'webview':
|
|
1248
1119
|
{
|
|
1249
1120
|
var _button = {
|
|
@@ -1254,14 +1125,11 @@ var parseRichMessageElement = function parseRichMessageElement(element) {
|
|
|
1254
1125
|
value: serverButton.value,
|
|
1255
1126
|
role: serverButton.role || 'default'
|
|
1256
1127
|
};
|
|
1257
|
-
|
|
1258
1128
|
if (typeof serverButton.webview_height === 'string') {
|
|
1259
1129
|
_button.webviewHeight = serverButton.webview_height;
|
|
1260
1130
|
}
|
|
1261
|
-
|
|
1262
1131
|
return _button;
|
|
1263
1132
|
}
|
|
1264
|
-
|
|
1265
1133
|
default:
|
|
1266
1134
|
{
|
|
1267
1135
|
return {
|
|
@@ -1274,10 +1142,8 @@ var parseRichMessageElement = function parseRichMessageElement(element) {
|
|
|
1274
1142
|
}
|
|
1275
1143
|
});
|
|
1276
1144
|
}
|
|
1277
|
-
|
|
1278
1145
|
return parsed;
|
|
1279
1146
|
};
|
|
1280
|
-
|
|
1281
1147
|
var parseRichMessage = function parseRichMessage(thread, richMessage) {
|
|
1282
1148
|
switch (richMessage.template_id) {
|
|
1283
1149
|
case 'cards':
|
|
@@ -1288,7 +1154,6 @@ var parseRichMessage = function parseRichMessage(thread, richMessage) {
|
|
|
1288
1154
|
template: richMessage.template_id,
|
|
1289
1155
|
elements: richMessage.elements.map(parseRichMessageElement)
|
|
1290
1156
|
});
|
|
1291
|
-
|
|
1292
1157
|
default:
|
|
1293
1158
|
return null;
|
|
1294
1159
|
}
|
|
@@ -1301,36 +1166,27 @@ var parseSystemMessage = function parseSystemMessage(thread, systemMessage) {
|
|
|
1301
1166
|
text: systemMessage.text,
|
|
1302
1167
|
systemMessageType: systemMessage.system_message_type
|
|
1303
1168
|
});
|
|
1304
|
-
|
|
1305
1169
|
if (systemMessage.text_vars) {
|
|
1306
1170
|
parsed.textVars = systemMessage.text_vars;
|
|
1307
1171
|
}
|
|
1308
|
-
|
|
1309
1172
|
return parsed;
|
|
1310
1173
|
};
|
|
1311
1174
|
var parseEvent$1 = function parseEvent(thread, event) {
|
|
1312
1175
|
switch (event.type) {
|
|
1313
1176
|
case FILE:
|
|
1314
1177
|
return parseFile(thread, event);
|
|
1315
|
-
|
|
1316
1178
|
case FORM:
|
|
1317
1179
|
return parseForm(thread, event);
|
|
1318
|
-
|
|
1319
1180
|
case FILLED_FORM:
|
|
1320
1181
|
return parseFilledForm(thread, event);
|
|
1321
|
-
|
|
1322
1182
|
case MESSAGE:
|
|
1323
1183
|
return parseMessage(thread, event);
|
|
1324
|
-
|
|
1325
1184
|
case RICH_MESSAGE:
|
|
1326
1185
|
return parseRichMessage(thread, event);
|
|
1327
|
-
|
|
1328
1186
|
case SYSTEM_MESSAGE:
|
|
1329
1187
|
return parseSystemMessage(thread, event);
|
|
1330
|
-
|
|
1331
1188
|
case CUSTOM:
|
|
1332
1189
|
return parseCustomEvent(thread, event);
|
|
1333
|
-
|
|
1334
1190
|
default:
|
|
1335
1191
|
return null;
|
|
1336
1192
|
}
|
|
@@ -1355,23 +1211,20 @@ var parseGreeting = function parseGreeting(greeting) {
|
|
|
1355
1211
|
};
|
|
1356
1212
|
};
|
|
1357
1213
|
|
|
1214
|
+
// we could use `mergeAll` for this, but we need to preserve insertion order here
|
|
1358
1215
|
// so it's better to rely on a custom implementation
|
|
1359
|
-
|
|
1360
1216
|
var parseCustomerSessionFields$1 = function parseCustomerSessionFields(sessionFields) {
|
|
1361
1217
|
return sessionFields.reduce(function (acc, field) {
|
|
1362
1218
|
var _Object$keys = Object.keys(field),
|
|
1363
|
-
|
|
1364
|
-
|
|
1219
|
+
key = _Object$keys[0];
|
|
1365
1220
|
acc[key] = field[key];
|
|
1366
1221
|
return acc;
|
|
1367
1222
|
}, {});
|
|
1368
1223
|
};
|
|
1369
|
-
|
|
1370
1224
|
var parseAccess = function parseAccess(access) {
|
|
1371
1225
|
if (access === void 0) {
|
|
1372
1226
|
access = {};
|
|
1373
1227
|
}
|
|
1374
|
-
|
|
1375
1228
|
return access.group_ids ? {
|
|
1376
1229
|
groupIds: access.group_ids
|
|
1377
1230
|
} : {};
|
|
@@ -1423,14 +1276,11 @@ var parseChatAgent = function parseChatAgent(agent) {
|
|
|
1423
1276
|
};
|
|
1424
1277
|
var parseCustomerOptionalProps = function parseCustomerOptionalProps(customerProps) {
|
|
1425
1278
|
var optionalProps = pickOwn(['avatar', 'email', 'name'], customerProps);
|
|
1426
|
-
|
|
1427
1279
|
if (customerProps.session_fields) {
|
|
1428
1280
|
optionalProps.sessionFields = parseCustomerSessionFields$1(customerProps.session_fields);
|
|
1429
1281
|
}
|
|
1430
|
-
|
|
1431
1282
|
return optionalProps;
|
|
1432
1283
|
};
|
|
1433
|
-
|
|
1434
1284
|
var parseCustomerCommonProps = function parseCustomerCommonProps(customer) {
|
|
1435
1285
|
var optionalProps = parseCustomerOptionalProps(customer);
|
|
1436
1286
|
return _extends({
|
|
@@ -1440,7 +1290,6 @@ var parseCustomerCommonProps = function parseCustomerCommonProps(customer) {
|
|
|
1440
1290
|
sessionFields: optionalProps.sessionFields || {}
|
|
1441
1291
|
});
|
|
1442
1292
|
};
|
|
1443
|
-
|
|
1444
1293
|
var parseChatCustomer = function parseChatCustomer(customer) {
|
|
1445
1294
|
return _extends({}, parseCustomerCommonProps(customer), {
|
|
1446
1295
|
present: customer.present
|
|
@@ -1461,7 +1310,7 @@ var parseCustomer = function parseCustomer(customer) {
|
|
|
1461
1310
|
};
|
|
1462
1311
|
var parsePredictedAgent = function parsePredictedAgent(payload) {
|
|
1463
1312
|
var agent = payload.agent,
|
|
1464
|
-
|
|
1313
|
+
queue = payload.queue;
|
|
1465
1314
|
return {
|
|
1466
1315
|
agent: {
|
|
1467
1316
|
id: agent.id,
|
|
@@ -1494,12 +1343,11 @@ var parseGroupStatus = function parseGroupStatus(status) {
|
|
|
1494
1343
|
|
|
1495
1344
|
var _FAIL_ALL_REQUESTS_ME;
|
|
1496
1345
|
|
|
1346
|
+
// TODO: rethink how we handle reconnects
|
|
1497
1347
|
var SMALL_RECONNECT_DELAY = 100;
|
|
1498
1348
|
var FAIL_ALL_REQUESTS_MESSAGES = (_FAIL_ALL_REQUESTS_ME = {}, _FAIL_ALL_REQUESTS_ME[CONNECTION_LOST] = 'Connection lost.', _FAIL_ALL_REQUESTS_ME[MISDIRECTED_CONNECTION] = 'Connected to wrong region.', _FAIL_ALL_REQUESTS_ME);
|
|
1499
|
-
|
|
1500
1349
|
var updateStateIfNeeded = function updateStateIfNeeded(store, action) {
|
|
1501
1350
|
var state = store.getState();
|
|
1502
|
-
|
|
1503
1351
|
switch (action.type) {
|
|
1504
1352
|
case PUSH_RESPONSE_RECEIVED:
|
|
1505
1353
|
case PUSH_RECEIVED:
|
|
@@ -1507,45 +1355,37 @@ var updateStateIfNeeded = function updateStateIfNeeded(store, action) {
|
|
|
1507
1355
|
case CHAT_DEACTIVATED:
|
|
1508
1356
|
store.dispatch(setChatActive(action.payload.payload.chatId, false));
|
|
1509
1357
|
return;
|
|
1510
|
-
|
|
1511
1358
|
case INCOMING_CHAT:
|
|
1512
1359
|
store.dispatch(setChatActive(action.payload.payload.chat.id, true));
|
|
1513
1360
|
return;
|
|
1514
|
-
|
|
1515
1361
|
default:
|
|
1516
1362
|
return;
|
|
1517
1363
|
}
|
|
1518
|
-
|
|
1519
1364
|
case RESPONSE_RECEIVED:
|
|
1520
1365
|
switch (action.payload.action) {
|
|
1521
1366
|
case LIST_CHATS:
|
|
1522
1367
|
action.payload.payload.chatsSummary.filter(function (_ref) {
|
|
1523
1368
|
var id = _ref.id,
|
|
1524
|
-
|
|
1369
|
+
active = _ref.active;
|
|
1525
1370
|
return isChatActive(state, id) !== active;
|
|
1526
1371
|
}).forEach(function (_ref2) {
|
|
1527
1372
|
var id = _ref2.id,
|
|
1528
|
-
|
|
1373
|
+
active = _ref2.active;
|
|
1529
1374
|
store.dispatch(setChatActive(id, active));
|
|
1530
1375
|
});
|
|
1531
1376
|
return;
|
|
1532
|
-
|
|
1533
1377
|
default:
|
|
1534
1378
|
return;
|
|
1535
1379
|
}
|
|
1536
|
-
|
|
1537
1380
|
}
|
|
1538
1381
|
};
|
|
1539
|
-
|
|
1540
1382
|
var sendRequest$1 = function sendRequest(socket, _ref3) {
|
|
1541
1383
|
var _ref3$payload = _ref3.payload,
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1384
|
+
id = _ref3$payload.id,
|
|
1385
|
+
request = _ref3$payload.request;
|
|
1545
1386
|
var frame = _extends({
|
|
1546
1387
|
request_id: id
|
|
1547
1388
|
}, request);
|
|
1548
|
-
|
|
1549
1389
|
switch (frame.action) {
|
|
1550
1390
|
case LOGIN:
|
|
1551
1391
|
{
|
|
@@ -1556,7 +1396,8 @@ var sendRequest$1 = function sendRequest(socket, _ref3) {
|
|
|
1556
1396
|
pushes: {
|
|
1557
1397
|
// '3.4': upgradedPushes,
|
|
1558
1398
|
'3.3': values(serverPushActions).filter(function (pushAction) {
|
|
1559
|
-
return (
|
|
1399
|
+
return (
|
|
1400
|
+
// `customer_disconnected` can be sent immediately after opening the connection, before it even received login request
|
|
1560
1401
|
// therefore it's not possible to subscribe for a particular version of this push - the "connection version" is always used
|
|
1561
1402
|
pushAction !== CUSTOMER_DISCONNECTED && !includes(pushAction, upgradedPushes)
|
|
1562
1403
|
);
|
|
@@ -1566,56 +1407,45 @@ var sendRequest$1 = function sendRequest(socket, _ref3) {
|
|
|
1566
1407
|
}));
|
|
1567
1408
|
return;
|
|
1568
1409
|
}
|
|
1569
|
-
|
|
1570
1410
|
default:
|
|
1571
1411
|
socket.emit(frame);
|
|
1572
1412
|
return;
|
|
1573
1413
|
}
|
|
1574
1414
|
};
|
|
1575
|
-
|
|
1576
1415
|
var emitUsers = function emitUsers(emit, users) {
|
|
1577
1416
|
users.forEach(function (user) {
|
|
1578
1417
|
if ('present' in user) {
|
|
1579
1418
|
var rest = _objectWithoutPropertiesLoose(user, ["present"]);
|
|
1580
|
-
|
|
1581
1419
|
emit('user_data', rest);
|
|
1582
1420
|
return;
|
|
1583
1421
|
}
|
|
1584
|
-
|
|
1585
1422
|
if (user.type === CUSTOMER) {
|
|
1586
1423
|
var _rest = _objectWithoutPropertiesLoose(user, ["statistics"]);
|
|
1587
|
-
|
|
1588
1424
|
emit('user_data', _rest);
|
|
1589
1425
|
return;
|
|
1590
1426
|
}
|
|
1591
|
-
|
|
1592
1427
|
emit('user_data', user);
|
|
1593
1428
|
});
|
|
1594
1429
|
};
|
|
1595
|
-
|
|
1596
1430
|
var handleMulticast = function handleMulticast(emit, _ref4) {
|
|
1597
1431
|
var type = _ref4.type,
|
|
1598
|
-
|
|
1599
|
-
|
|
1432
|
+
content = _ref4.content;
|
|
1600
1433
|
if (type !== 'lc2') {
|
|
1601
1434
|
return;
|
|
1602
1435
|
}
|
|
1603
|
-
|
|
1604
1436
|
if (content.name === 'groups_update' && 'groups' in content && !isEmpty(content.groups)) {
|
|
1605
1437
|
var _content$groups = content.groups,
|
|
1606
|
-
|
|
1438
|
+
group = _content$groups[0];
|
|
1607
1439
|
var availability = parseGroupStatus(group.status);
|
|
1608
1440
|
emit('availability_updated', {
|
|
1609
1441
|
availability: availability
|
|
1610
1442
|
});
|
|
1611
1443
|
}
|
|
1612
1444
|
};
|
|
1613
|
-
|
|
1614
1445
|
var handlePush = function handlePush(_ref5, _ref6) {
|
|
1615
1446
|
var emit = _ref5.emit,
|
|
1616
|
-
|
|
1447
|
+
store = _ref5.store;
|
|
1617
1448
|
var payload = _ref6.payload;
|
|
1618
|
-
|
|
1619
1449
|
switch (payload.action) {
|
|
1620
1450
|
case THREAD_PROPERTIES_UPDATED:
|
|
1621
1451
|
if (payload.payload.properties.lc2 && 'queue_pos' in payload.payload.properties.lc2) {
|
|
@@ -1628,14 +1458,11 @@ var handlePush = function handlePush(_ref5, _ref6) {
|
|
|
1628
1458
|
}
|
|
1629
1459
|
});
|
|
1630
1460
|
}
|
|
1631
|
-
|
|
1632
1461
|
emit('thread_properties_updated', payload.payload);
|
|
1633
1462
|
return;
|
|
1634
|
-
|
|
1635
1463
|
case CUSTOMER_SIDE_STORAGE_UPDATED:
|
|
1636
1464
|
saveSideStorage(store, payload.payload.customer_side_storage);
|
|
1637
1465
|
return;
|
|
1638
|
-
|
|
1639
1466
|
case CUSTOMER_DISCONNECTED:
|
|
1640
1467
|
// each of those should currently lead to either reconnect or destroy call
|
|
1641
1468
|
// after receiving this push server closes the connection with us
|
|
@@ -1652,7 +1479,6 @@ var handlePush = function handlePush(_ref5, _ref6) {
|
|
|
1652
1479
|
store.dispatch(reconnect(SMALL_RECONNECT_DELAY));
|
|
1653
1480
|
emit('disconnected', payload.payload);
|
|
1654
1481
|
break;
|
|
1655
|
-
|
|
1656
1482
|
case CUSTOMER_BANNED:
|
|
1657
1483
|
case CUSTOMER_TEMPORARILY_BLOCKED:
|
|
1658
1484
|
case LICENSE_NOT_FOUND:
|
|
@@ -1662,7 +1488,6 @@ var handlePush = function handlePush(_ref5, _ref6) {
|
|
|
1662
1488
|
// this also emits `disconnected` event - but it's handled in response to this action by destroy handler
|
|
1663
1489
|
store.dispatch(destroy(payload.payload.reason));
|
|
1664
1490
|
break;
|
|
1665
|
-
|
|
1666
1491
|
case MISDIRECTED_CONNECTION$1:
|
|
1667
1492
|
failAllRequests(store, MISDIRECTED_CONNECTION);
|
|
1668
1493
|
store.dispatch({
|
|
@@ -1670,119 +1495,98 @@ var handlePush = function handlePush(_ref5, _ref6) {
|
|
|
1670
1495
|
payload: payload.payload.data
|
|
1671
1496
|
});
|
|
1672
1497
|
break;
|
|
1673
|
-
|
|
1674
1498
|
case SERVICE_TEMPORARILY_UNAVAILABLE$1:
|
|
1675
1499
|
case TOO_MANY_UNAUTHORIZED_CONNECTIONS:
|
|
1676
1500
|
// this should only really fail a `login` request - as it's the only one sent before authorization
|
|
1677
1501
|
// and login should reconnect on its own right now
|
|
1678
1502
|
failAllRequests(store, payload.payload.reason.toUpperCase());
|
|
1679
1503
|
break;
|
|
1680
|
-
|
|
1681
1504
|
default:
|
|
1682
1505
|
store.dispatch(reconnect(SMALL_RECONNECT_DELAY));
|
|
1683
1506
|
emit('disconnected', payload.payload);
|
|
1684
1507
|
break;
|
|
1685
1508
|
}
|
|
1686
|
-
|
|
1687
1509
|
return;
|
|
1688
|
-
|
|
1689
1510
|
case INCOMING_CHAT:
|
|
1690
1511
|
emitUsers(emit, payload.payload.chat.users);
|
|
1691
1512
|
emit(payload.action, payload.payload);
|
|
1692
1513
|
return;
|
|
1693
|
-
|
|
1694
1514
|
case INCOMING_EVENT:
|
|
1695
1515
|
if (payload.payload.event === null) {
|
|
1696
1516
|
return;
|
|
1697
1517
|
}
|
|
1698
|
-
|
|
1699
1518
|
emit(payload.action, payload.payload);
|
|
1700
1519
|
return;
|
|
1701
|
-
|
|
1702
1520
|
case INCOMING_TYPING_INDICATOR:
|
|
1703
1521
|
emit(payload.action, payload.payload);
|
|
1704
1522
|
return;
|
|
1705
|
-
|
|
1706
1523
|
case INCOMING_MULTICAST:
|
|
1707
|
-
handleMulticast(emit, payload.payload);
|
|
1708
|
-
|
|
1524
|
+
handleMulticast(emit, payload.payload);
|
|
1525
|
+
// we passthrough this action even if it was already handled above
|
|
1709
1526
|
emit(payload.action, payload.payload);
|
|
1710
1527
|
return;
|
|
1711
|
-
|
|
1712
1528
|
case USER_ADDED_TO_CHAT:
|
|
1713
1529
|
emitUsers(emit, [payload.payload.user]);
|
|
1714
1530
|
emit(payload.action, payload.payload);
|
|
1715
1531
|
return;
|
|
1716
|
-
|
|
1717
1532
|
default:
|
|
1718
1533
|
emit(payload.action, payload.payload);
|
|
1719
1534
|
return;
|
|
1720
1535
|
}
|
|
1721
1536
|
};
|
|
1722
|
-
|
|
1723
1537
|
var handleResponse = function handleResponse(_ref7, _ref8) {
|
|
1724
1538
|
var emit = _ref7.emit;
|
|
1725
1539
|
var payload = _ref8.payload;
|
|
1726
|
-
|
|
1727
1540
|
switch (payload.action) {
|
|
1728
1541
|
case CHAT_DEACTIVATED:
|
|
1729
1542
|
payload.resolve(SUCCESS);
|
|
1730
1543
|
return;
|
|
1731
|
-
|
|
1732
1544
|
case GET_CHAT:
|
|
1733
1545
|
emitUsers(emit, payload.payload.users);
|
|
1734
1546
|
payload.resolve(payload.payload);
|
|
1735
1547
|
return;
|
|
1736
|
-
|
|
1737
1548
|
case INCOMING_CHAT:
|
|
1738
1549
|
emitUsers(emit, payload.payload.chat.users);
|
|
1739
1550
|
payload.resolve(payload.payload);
|
|
1740
1551
|
return;
|
|
1741
|
-
|
|
1742
1552
|
case INCOMING_EVENT:
|
|
1743
1553
|
payload.resolve(payload.payload.event);
|
|
1744
1554
|
return;
|
|
1745
|
-
|
|
1746
1555
|
case LIST_CHATS:
|
|
1747
1556
|
emitUsers(emit, payload.payload.users);
|
|
1748
1557
|
payload.resolve(payload.payload);
|
|
1749
1558
|
return;
|
|
1750
|
-
|
|
1751
1559
|
default:
|
|
1752
1560
|
payload.resolve(payload.payload);
|
|
1753
1561
|
return;
|
|
1754
1562
|
}
|
|
1755
1563
|
};
|
|
1756
|
-
|
|
1757
1564
|
var createSideEffectsHandler = (function (_ref9) {
|
|
1758
1565
|
var auth = _ref9.auth,
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1566
|
+
customerDataProvider = _ref9.customerDataProvider,
|
|
1567
|
+
emitter = _ref9.emitter,
|
|
1568
|
+
socket = _ref9.socket;
|
|
1762
1569
|
var emit = emitter.emit;
|
|
1763
|
-
var loginTask = createLoginTask(auth, customerDataProvider);
|
|
1570
|
+
var loginTask = createLoginTask(auth, customerDataProvider);
|
|
1764
1571
|
|
|
1572
|
+
// TODO: using Store type here is a lie, middleware only provides MiddlewareAPI here
|
|
1765
1573
|
return function (action, store) {
|
|
1766
1574
|
switch (action.type) {
|
|
1767
1575
|
case CHANGE_REGION:
|
|
1768
1576
|
socket.reinitialize();
|
|
1769
1577
|
return;
|
|
1770
|
-
|
|
1771
1578
|
case CHECK_GOALS:
|
|
1772
1579
|
checkGoals(store, auth, action.payload.sessionFields)["catch"](noop);
|
|
1773
1580
|
return;
|
|
1774
|
-
|
|
1775
1581
|
case DESTROY:
|
|
1776
1582
|
{
|
|
1777
1583
|
var payload = action.payload;
|
|
1778
1584
|
loginTask.cancel();
|
|
1779
1585
|
socket.destroy();
|
|
1780
|
-
|
|
1781
1586
|
switch (payload.reason) {
|
|
1782
1587
|
case 'manual':
|
|
1783
1588
|
failAllRequests(store, SDK_DESTROYED);
|
|
1784
1589
|
break;
|
|
1785
|
-
|
|
1786
1590
|
case CUSTOMER_BANNED:
|
|
1787
1591
|
case LICENSE_EXPIRED:
|
|
1788
1592
|
case PRODUCT_VERSION_CHANGED:
|
|
@@ -1790,7 +1594,6 @@ var createSideEffectsHandler = (function (_ref9) {
|
|
|
1790
1594
|
failAllRequests(store, CONNECTION_LOST);
|
|
1791
1595
|
emit('disconnected', payload);
|
|
1792
1596
|
break;
|
|
1793
|
-
|
|
1794
1597
|
default:
|
|
1795
1598
|
// in general those deestroys should only come either from login errors
|
|
1796
1599
|
// or from customer_disconnected pushes that are sent immediately after connection
|
|
@@ -1799,16 +1602,14 @@ var createSideEffectsHandler = (function (_ref9) {
|
|
|
1799
1602
|
emit('disconnected', payload);
|
|
1800
1603
|
break;
|
|
1801
1604
|
}
|
|
1802
|
-
|
|
1803
1605
|
emitter.off();
|
|
1804
1606
|
return;
|
|
1805
1607
|
}
|
|
1806
|
-
|
|
1807
1608
|
case FAIL_ALL_REQUESTS:
|
|
1808
1609
|
{
|
|
1809
1610
|
var _action$payload = action.payload,
|
|
1810
|
-
|
|
1811
|
-
|
|
1611
|
+
reason = _action$payload.reason,
|
|
1612
|
+
rejects = _action$payload.rejects;
|
|
1812
1613
|
var error = {
|
|
1813
1614
|
message: FAIL_ALL_REQUESTS_MESSAGES[reason],
|
|
1814
1615
|
code: reason
|
|
@@ -1818,23 +1619,20 @@ var createSideEffectsHandler = (function (_ref9) {
|
|
|
1818
1619
|
});
|
|
1819
1620
|
return;
|
|
1820
1621
|
}
|
|
1821
|
-
|
|
1822
1622
|
case LOGIN_SUCCESS:
|
|
1823
1623
|
{
|
|
1824
1624
|
var _action$payload2 = action.payload,
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1625
|
+
dynamicConfig = _action$payload2.dynamicConfig,
|
|
1626
|
+
customer = _action$payload2.customer,
|
|
1627
|
+
chats = _action$payload2.chats,
|
|
1628
|
+
greeting = _action$payload2.greeting,
|
|
1629
|
+
availability = _action$payload2.availability;
|
|
1831
1630
|
var eventData = _extends({
|
|
1832
1631
|
customer: customer,
|
|
1833
1632
|
availability: availability
|
|
1834
1633
|
}, greeting && {
|
|
1835
1634
|
greeting: greeting
|
|
1836
1635
|
});
|
|
1837
|
-
|
|
1838
1636
|
Object.defineProperty(eventData, '__unsafeDynamicConfig', {
|
|
1839
1637
|
value: dynamicConfig
|
|
1840
1638
|
});
|
|
@@ -1844,45 +1642,37 @@ var createSideEffectsHandler = (function (_ref9) {
|
|
|
1844
1642
|
emit('connected', eventData);
|
|
1845
1643
|
return;
|
|
1846
1644
|
}
|
|
1847
|
-
|
|
1848
1645
|
case PAUSE_CONNECTION:
|
|
1849
1646
|
{
|
|
1850
1647
|
var _payload = action.payload;
|
|
1851
1648
|
socket.disconnect();
|
|
1852
|
-
|
|
1853
1649
|
if (_payload.reason !== 'manual') {
|
|
1854
1650
|
emit('disconnected', _payload);
|
|
1855
1651
|
}
|
|
1856
|
-
|
|
1857
1652
|
return;
|
|
1858
1653
|
}
|
|
1859
|
-
|
|
1860
1654
|
case PREFETCH_TOKEN:
|
|
1861
1655
|
if (action.payload.fresh) {
|
|
1862
1656
|
auth.getFreshToken()["catch"](noop);
|
|
1863
1657
|
return;
|
|
1864
1658
|
}
|
|
1865
|
-
|
|
1866
1659
|
auth.hasToken().then(function (hasToken) {
|
|
1867
1660
|
if (!hasToken) {
|
|
1868
1661
|
return auth.getToken();
|
|
1869
1662
|
}
|
|
1870
|
-
|
|
1871
1663
|
return auth.getToken().then(function (_ref10) {
|
|
1872
1664
|
var creationDate = _ref10.creationDate,
|
|
1873
|
-
|
|
1874
|
-
var ONE_HOUR = 60 * 60 * 1000;
|
|
1665
|
+
expiresIn = _ref10.expiresIn;
|
|
1666
|
+
var ONE_HOUR = 60 * 60 * 1000;
|
|
1667
|
+
// check if the token is worth reusing
|
|
1875
1668
|
// we don't want to get disconnected in a moment because of expired token
|
|
1876
|
-
|
|
1877
1669
|
if (creationDate + expiresIn - Date.now() > ONE_HOUR) {
|
|
1878
1670
|
return;
|
|
1879
1671
|
}
|
|
1880
|
-
|
|
1881
1672
|
return auth.invalidate().then(auth.getFreshToken);
|
|
1882
1673
|
});
|
|
1883
1674
|
})["catch"](noop);
|
|
1884
1675
|
return;
|
|
1885
|
-
|
|
1886
1676
|
case PUSH_RECEIVED:
|
|
1887
1677
|
// TODO: this if doesn't seem to make much sense
|
|
1888
1678
|
// I'm too afraid to remove it right now though
|
|
@@ -1893,46 +1683,39 @@ var createSideEffectsHandler = (function (_ref9) {
|
|
|
1893
1683
|
}, action);
|
|
1894
1684
|
return;
|
|
1895
1685
|
}
|
|
1896
|
-
|
|
1897
1686
|
updateStateIfNeeded(store, action);
|
|
1898
1687
|
handlePush({
|
|
1899
1688
|
emit: emit,
|
|
1900
1689
|
store: store
|
|
1901
1690
|
}, action);
|
|
1902
1691
|
return;
|
|
1903
|
-
|
|
1904
1692
|
case PUSH_RESPONSE_RECEIVED:
|
|
1905
1693
|
updateStateIfNeeded(store, action);
|
|
1906
1694
|
handleResponse({
|
|
1907
1695
|
emit: emit
|
|
1908
1696
|
}, action);
|
|
1909
1697
|
return;
|
|
1910
|
-
|
|
1911
1698
|
case RECONNECT:
|
|
1912
1699
|
failAllRequests(store, CONNECTION_LOST);
|
|
1913
1700
|
socket.reconnect(action.payload.delay);
|
|
1914
1701
|
return;
|
|
1915
|
-
|
|
1916
1702
|
case REQUEST_FAILED:
|
|
1917
1703
|
{
|
|
1918
1704
|
var _action$payload3 = action.payload,
|
|
1919
|
-
|
|
1920
|
-
|
|
1705
|
+
reject = _action$payload3.reject,
|
|
1706
|
+
_error = _action$payload3.error;
|
|
1921
1707
|
reject(createError(_error));
|
|
1922
1708
|
return;
|
|
1923
1709
|
}
|
|
1924
|
-
|
|
1925
1710
|
case RESPONSE_RECEIVED:
|
|
1926
1711
|
updateStateIfNeeded(store, action);
|
|
1927
1712
|
handleResponse({
|
|
1928
1713
|
emit: emit
|
|
1929
1714
|
}, action);
|
|
1930
1715
|
return;
|
|
1931
|
-
|
|
1932
1716
|
case SEND_REQUEST:
|
|
1933
1717
|
{
|
|
1934
1718
|
var state = store.getState();
|
|
1935
|
-
|
|
1936
1719
|
if (isDestroyed(state)) {
|
|
1937
1720
|
failRequest(store, action, {
|
|
1938
1721
|
code: SDK_DESTROYED,
|
|
@@ -1940,7 +1723,6 @@ var createSideEffectsHandler = (function (_ref9) {
|
|
|
1940
1723
|
});
|
|
1941
1724
|
return;
|
|
1942
1725
|
}
|
|
1943
|
-
|
|
1944
1726
|
if (!isConnected(state) && action.payload.source !== 'login') {
|
|
1945
1727
|
failRequest(store, action, {
|
|
1946
1728
|
code: NO_CONNECTION,
|
|
@@ -1948,56 +1730,44 @@ var createSideEffectsHandler = (function (_ref9) {
|
|
|
1948
1730
|
});
|
|
1949
1731
|
return;
|
|
1950
1732
|
}
|
|
1951
|
-
|
|
1952
1733
|
sendRequest$1(socket, action);
|
|
1953
1734
|
}
|
|
1954
1735
|
return;
|
|
1955
|
-
|
|
1956
1736
|
case SET_SELF_ID:
|
|
1957
1737
|
emit('customer_id', action.payload.id);
|
|
1958
1738
|
return;
|
|
1959
|
-
|
|
1960
1739
|
case SOCKET_DISCONNECTED:
|
|
1961
1740
|
emit('disconnected', {
|
|
1962
1741
|
reason: 'connection_lost'
|
|
1963
1742
|
});
|
|
1964
1743
|
return;
|
|
1965
|
-
|
|
1966
1744
|
case SOCKET_CONNECTED:
|
|
1967
1745
|
loginTask.sendLogin(store);
|
|
1968
1746
|
return;
|
|
1969
|
-
|
|
1970
1747
|
case SOCKET_RECOVERED:
|
|
1971
1748
|
// don't emit if from consumer's perspective we haven't been connected
|
|
1972
1749
|
if (!isConnected(store.getState())) {
|
|
1973
1750
|
return;
|
|
1974
1751
|
}
|
|
1975
|
-
|
|
1976
1752
|
emit('connection_recovered');
|
|
1977
1753
|
return;
|
|
1978
|
-
|
|
1979
1754
|
case SOCKET_UNSTABLE:
|
|
1980
1755
|
// don't emit if from consumer's perspective we haven't been connected
|
|
1981
1756
|
if (!isConnected(store.getState())) {
|
|
1982
1757
|
return;
|
|
1983
1758
|
}
|
|
1984
|
-
|
|
1985
1759
|
emit('connection_unstable');
|
|
1986
1760
|
return;
|
|
1987
|
-
|
|
1988
1761
|
case START_CONNECTION:
|
|
1989
1762
|
socket.connect();
|
|
1990
1763
|
store.dispatch(prefetchToken());
|
|
1991
1764
|
return;
|
|
1992
|
-
|
|
1993
1765
|
case UPDATE_CUSTOMER_PAGE:
|
|
1994
1766
|
if (!isConnected(store.getState())) {
|
|
1995
1767
|
return;
|
|
1996
1768
|
}
|
|
1997
|
-
|
|
1998
1769
|
sendRequestAction(store, sendRequest(UPDATE_CUSTOMER_PAGE$1, action.payload))["catch"](noop);
|
|
1999
1770
|
return;
|
|
2000
|
-
|
|
2001
1771
|
default:
|
|
2002
1772
|
return;
|
|
2003
1773
|
}
|
|
@@ -2005,7 +1775,6 @@ var createSideEffectsHandler = (function (_ref9) {
|
|
|
2005
1775
|
});
|
|
2006
1776
|
|
|
2007
1777
|
var HISTORY_EVENT_COUNT_TARGET = 25;
|
|
2008
|
-
|
|
2009
1778
|
var createState = function createState() {
|
|
2010
1779
|
return {
|
|
2011
1780
|
status: 'idle',
|
|
@@ -2013,10 +1782,8 @@ var createState = function createState() {
|
|
|
2013
1782
|
nextPageId: null
|
|
2014
1783
|
};
|
|
2015
1784
|
};
|
|
2016
|
-
|
|
2017
1785
|
var createChatHistoryIterator = function createChatHistoryIterator(sdk, chatId) {
|
|
2018
1786
|
var historyState = createState();
|
|
2019
|
-
|
|
2020
1787
|
var next = function next(resolve, reject) {
|
|
2021
1788
|
switch (historyState.status) {
|
|
2022
1789
|
case 'idle':
|
|
@@ -2029,9 +1796,8 @@ var createChatHistoryIterator = function createChatHistoryIterator(sdk, chatId)
|
|
|
2029
1796
|
minEventsCount: HISTORY_EVENT_COUNT_TARGET
|
|
2030
1797
|
}).then(function (_ref) {
|
|
2031
1798
|
var threads = _ref.threads,
|
|
2032
|
-
|
|
1799
|
+
nextPageId = _ref.nextPageId;
|
|
2033
1800
|
historyState.nextPageId = nextPageId;
|
|
2034
|
-
|
|
2035
1801
|
if (!historyState.nextPageId) {
|
|
2036
1802
|
historyState.status = 'done';
|
|
2037
1803
|
resolve({
|
|
@@ -2049,13 +1815,10 @@ var createChatHistoryIterator = function createChatHistoryIterator(sdk, chatId)
|
|
|
2049
1815
|
done: false
|
|
2050
1816
|
});
|
|
2051
1817
|
}
|
|
2052
|
-
|
|
2053
1818
|
var queuedTask = historyState.queuedTasks.shift();
|
|
2054
|
-
|
|
2055
1819
|
if (!queuedTask) {
|
|
2056
1820
|
return;
|
|
2057
1821
|
}
|
|
2058
|
-
|
|
2059
1822
|
next(queuedTask.resolve, queuedTask.reject);
|
|
2060
1823
|
}, function (err) {
|
|
2061
1824
|
var queuedTasks = historyState.queuedTasks;
|
|
@@ -2067,14 +1830,12 @@ var createChatHistoryIterator = function createChatHistoryIterator(sdk, chatId)
|
|
|
2067
1830
|
});
|
|
2068
1831
|
});
|
|
2069
1832
|
return;
|
|
2070
|
-
|
|
2071
1833
|
case 'fetching':
|
|
2072
1834
|
historyState.queuedTasks.push({
|
|
2073
1835
|
resolve: resolve,
|
|
2074
1836
|
reject: reject
|
|
2075
1837
|
});
|
|
2076
1838
|
return;
|
|
2077
|
-
|
|
2078
1839
|
case 'done':
|
|
2079
1840
|
resolve({
|
|
2080
1841
|
value: undefined,
|
|
@@ -2083,17 +1844,14 @@ var createChatHistoryIterator = function createChatHistoryIterator(sdk, chatId)
|
|
|
2083
1844
|
return;
|
|
2084
1845
|
}
|
|
2085
1846
|
};
|
|
2086
|
-
|
|
2087
1847
|
return {
|
|
2088
1848
|
next: function (_next) {
|
|
2089
1849
|
function next() {
|
|
2090
1850
|
return _next.apply(this, arguments);
|
|
2091
1851
|
}
|
|
2092
|
-
|
|
2093
1852
|
next.toString = function () {
|
|
2094
1853
|
return _next.toString();
|
|
2095
1854
|
};
|
|
2096
|
-
|
|
2097
1855
|
return next;
|
|
2098
1856
|
}(function () {
|
|
2099
1857
|
return new Promise(next);
|
|
@@ -2111,17 +1869,14 @@ var initialize = function initialize(store, emitter) {
|
|
|
2111
1869
|
emitter: emitter
|
|
2112
1870
|
});
|
|
2113
1871
|
};
|
|
2114
|
-
|
|
2115
1872
|
var createSocketClient = function createSocketClient(store) {
|
|
2116
1873
|
var emitter = mitt();
|
|
2117
1874
|
var client = initialize(store, emitter);
|
|
2118
1875
|
return _extends({}, Object.keys(client).reduce(function (proxy, method) {
|
|
2119
1876
|
proxy[method] = function () {
|
|
2120
1877
|
var _client;
|
|
2121
|
-
|
|
2122
1878
|
return (_client = client)[method].apply(_client, arguments);
|
|
2123
1879
|
};
|
|
2124
|
-
|
|
2125
1880
|
return proxy;
|
|
2126
1881
|
}, {}), {
|
|
2127
1882
|
reinitialize: function reinitialize() {
|
|
@@ -2138,14 +1893,12 @@ var parseChatPropertiesDeletedPush = function parseChatPropertiesDeletedPush(pay
|
|
|
2138
1893
|
properties: payload.properties
|
|
2139
1894
|
};
|
|
2140
1895
|
};
|
|
2141
|
-
|
|
2142
1896
|
var parseChatPropertiesUpdatedPush = function parseChatPropertiesUpdatedPush(payload) {
|
|
2143
1897
|
return {
|
|
2144
1898
|
chatId: payload.chat_id,
|
|
2145
1899
|
properties: payload.properties
|
|
2146
1900
|
};
|
|
2147
1901
|
};
|
|
2148
|
-
|
|
2149
1902
|
var parseChatTransferredPush = function parseChatTransferredPush(payload) {
|
|
2150
1903
|
var basePayload = {
|
|
2151
1904
|
chatId: payload.chat_id,
|
|
@@ -2157,19 +1910,16 @@ var parseChatTransferredPush = function parseChatTransferredPush(payload) {
|
|
|
2157
1910
|
}),
|
|
2158
1911
|
queue: payload.queue ? parseQueue(payload.queue) : null
|
|
2159
1912
|
};
|
|
2160
|
-
|
|
2161
1913
|
if (payload.reason === 'manual') {
|
|
2162
1914
|
return _extends({}, basePayload, {
|
|
2163
1915
|
reason: payload.reason,
|
|
2164
1916
|
requesterId: payload.requester_id
|
|
2165
1917
|
});
|
|
2166
1918
|
}
|
|
2167
|
-
|
|
2168
1919
|
return _extends({}, basePayload, {
|
|
2169
1920
|
reason: payload.reason
|
|
2170
1921
|
});
|
|
2171
1922
|
};
|
|
2172
|
-
|
|
2173
1923
|
var parseCustomerPageUpdatedPush = function parseCustomerPageUpdatedPush(payload) {
|
|
2174
1924
|
return {
|
|
2175
1925
|
url: payload.url,
|
|
@@ -2177,13 +1927,11 @@ var parseCustomerPageUpdatedPush = function parseCustomerPageUpdatedPush(payload
|
|
|
2177
1927
|
openedAt: payload.opened_at
|
|
2178
1928
|
};
|
|
2179
1929
|
};
|
|
2180
|
-
|
|
2181
1930
|
var parseCustomerUpdatedPush = function parseCustomerUpdatedPush(payload) {
|
|
2182
1931
|
return _extends({
|
|
2183
1932
|
id: payload.id
|
|
2184
1933
|
}, parseCustomerOptionalProps(payload));
|
|
2185
1934
|
};
|
|
2186
|
-
|
|
2187
1935
|
var parseEventPropertiesDeletedPush = function parseEventPropertiesDeletedPush(payload) {
|
|
2188
1936
|
return {
|
|
2189
1937
|
chatId: payload.chat_id,
|
|
@@ -2192,7 +1940,6 @@ var parseEventPropertiesDeletedPush = function parseEventPropertiesDeletedPush(p
|
|
|
2192
1940
|
properties: payload.properties
|
|
2193
1941
|
};
|
|
2194
1942
|
};
|
|
2195
|
-
|
|
2196
1943
|
var parseEventPropertiesUpdatedPush = function parseEventPropertiesUpdatedPush(payload) {
|
|
2197
1944
|
return {
|
|
2198
1945
|
chatId: payload.chat_id,
|
|
@@ -2201,7 +1948,6 @@ var parseEventPropertiesUpdatedPush = function parseEventPropertiesUpdatedPush(p
|
|
|
2201
1948
|
properties: payload.properties
|
|
2202
1949
|
};
|
|
2203
1950
|
};
|
|
2204
|
-
|
|
2205
1951
|
var parseEventUpdatedPush = function parseEventUpdatedPush(payload) {
|
|
2206
1952
|
var threadId = payload.thread_id;
|
|
2207
1953
|
return {
|
|
@@ -2210,7 +1956,6 @@ var parseEventUpdatedPush = function parseEventUpdatedPush(payload) {
|
|
|
2210
1956
|
event: parseEvent$1(threadId, payload.event)
|
|
2211
1957
|
};
|
|
2212
1958
|
};
|
|
2213
|
-
|
|
2214
1959
|
var parseEventsMarkedAsSeenPush = function parseEventsMarkedAsSeenPush(payload) {
|
|
2215
1960
|
return {
|
|
2216
1961
|
chatId: payload.chat_id,
|
|
@@ -2218,19 +1963,16 @@ var parseEventsMarkedAsSeenPush = function parseEventsMarkedAsSeenPush(payload)
|
|
|
2218
1963
|
seenUpTo: payload.seen_up_to
|
|
2219
1964
|
};
|
|
2220
1965
|
};
|
|
2221
|
-
|
|
2222
1966
|
var parseGreetingAcceptedPush = function parseGreetingAcceptedPush(payload) {
|
|
2223
1967
|
return {
|
|
2224
1968
|
uniqueId: payload.unique_id
|
|
2225
1969
|
};
|
|
2226
1970
|
};
|
|
2227
|
-
|
|
2228
1971
|
var parseGetChatResponse = function parseGetChatResponse(payload) {
|
|
2229
1972
|
return _extends({}, parseChatCommon(payload), {
|
|
2230
1973
|
thread: payload.thread ? parseThread(payload.id, payload.thread) : null
|
|
2231
1974
|
});
|
|
2232
1975
|
};
|
|
2233
|
-
|
|
2234
1976
|
var parseIncomingChatPush = function parseIncomingChatPush(payload) {
|
|
2235
1977
|
var chat = payload.chat;
|
|
2236
1978
|
return {
|
|
@@ -2239,18 +1981,15 @@ var parseIncomingChatPush = function parseIncomingChatPush(payload) {
|
|
|
2239
1981
|
})
|
|
2240
1982
|
};
|
|
2241
1983
|
};
|
|
2242
|
-
|
|
2243
1984
|
var parseIncomingEventPush = function parseIncomingEventPush(payload) {
|
|
2244
1985
|
return {
|
|
2245
1986
|
chatId: payload.chat_id,
|
|
2246
1987
|
event: parseEvent$1(payload.thread_id, payload.event)
|
|
2247
1988
|
};
|
|
2248
1989
|
};
|
|
2249
|
-
|
|
2250
1990
|
var parseIncomingGreetingPush = function parseIncomingGreetingPush(payload) {
|
|
2251
1991
|
return parseGreeting(payload);
|
|
2252
1992
|
};
|
|
2253
|
-
|
|
2254
1993
|
var parseIncomingRichMessagePostbackPush = function parseIncomingRichMessagePostbackPush(payload) {
|
|
2255
1994
|
return {
|
|
2256
1995
|
userId: payload.user_id,
|
|
@@ -2260,10 +1999,9 @@ var parseIncomingRichMessagePostbackPush = function parseIncomingRichMessagePost
|
|
|
2260
1999
|
postback: payload.postback
|
|
2261
2000
|
};
|
|
2262
2001
|
};
|
|
2263
|
-
|
|
2264
2002
|
var parseIncomingTypingIndicatorPush = function parseIncomingTypingIndicatorPush(payload) {
|
|
2265
2003
|
var chatId = payload.chat_id,
|
|
2266
|
-
|
|
2004
|
+
typingIndicator = payload.typing_indicator;
|
|
2267
2005
|
return {
|
|
2268
2006
|
chatId: chatId,
|
|
2269
2007
|
typingIndicator: {
|
|
@@ -2272,7 +2010,6 @@ var parseIncomingTypingIndicatorPush = function parseIncomingTypingIndicatorPush
|
|
|
2272
2010
|
}
|
|
2273
2011
|
};
|
|
2274
2012
|
};
|
|
2275
|
-
|
|
2276
2013
|
var parseQueuePositionUpdatedPush = function parseQueuePositionUpdatedPush(payload) {
|
|
2277
2014
|
return {
|
|
2278
2015
|
chatId: payload.chat_id,
|
|
@@ -2280,7 +2017,6 @@ var parseQueuePositionUpdatedPush = function parseQueuePositionUpdatedPush(paylo
|
|
|
2280
2017
|
queue: parseQueueUpdate(payload.queue)
|
|
2281
2018
|
};
|
|
2282
2019
|
};
|
|
2283
|
-
|
|
2284
2020
|
var parseThreadPropertiesDeletedPush = function parseThreadPropertiesDeletedPush(payload) {
|
|
2285
2021
|
return {
|
|
2286
2022
|
chatId: payload.chat_id,
|
|
@@ -2288,7 +2024,6 @@ var parseThreadPropertiesDeletedPush = function parseThreadPropertiesDeletedPush
|
|
|
2288
2024
|
properties: payload.properties
|
|
2289
2025
|
};
|
|
2290
2026
|
};
|
|
2291
|
-
|
|
2292
2027
|
var parseThreadPropertiesUpdatedPush = function parseThreadPropertiesUpdatedPush(payload) {
|
|
2293
2028
|
return {
|
|
2294
2029
|
chatId: payload.chat_id,
|
|
@@ -2296,7 +2031,6 @@ var parseThreadPropertiesUpdatedPush = function parseThreadPropertiesUpdatedPush
|
|
|
2296
2031
|
properties: payload.properties
|
|
2297
2032
|
};
|
|
2298
2033
|
};
|
|
2299
|
-
|
|
2300
2034
|
var parseUserAddedToChatPush = function parseUserAddedToChatPush(payload) {
|
|
2301
2035
|
return {
|
|
2302
2036
|
chatId: payload.chat_id,
|
|
@@ -2304,14 +2038,12 @@ var parseUserAddedToChatPush = function parseUserAddedToChatPush(payload) {
|
|
|
2304
2038
|
present: payload.user.present
|
|
2305
2039
|
};
|
|
2306
2040
|
};
|
|
2307
|
-
|
|
2308
2041
|
var parseUserRemovedFromChatPush = function parseUserRemovedFromChatPush(payload) {
|
|
2309
2042
|
return {
|
|
2310
2043
|
chatId: payload.chat_id,
|
|
2311
2044
|
userId: payload.user_id
|
|
2312
2045
|
};
|
|
2313
2046
|
};
|
|
2314
|
-
|
|
2315
2047
|
var parseFields = function parseFields(fields) {
|
|
2316
2048
|
return fields.map(function (field) {
|
|
2317
2049
|
switch (field.type) {
|
|
@@ -2319,30 +2051,25 @@ var parseFields = function parseFields(fields) {
|
|
|
2319
2051
|
return _extends({}, field, {
|
|
2320
2052
|
options: field.options.map(function (_ref) {
|
|
2321
2053
|
var groupId = _ref.group_id,
|
|
2322
|
-
|
|
2323
|
-
|
|
2054
|
+
option = _objectWithoutPropertiesLoose(_ref, ["group_id"]);
|
|
2324
2055
|
return _extends({}, option, {
|
|
2325
2056
|
groupId: groupId
|
|
2326
2057
|
});
|
|
2327
2058
|
})
|
|
2328
2059
|
});
|
|
2329
|
-
|
|
2330
2060
|
case 'rating':
|
|
2331
2061
|
{
|
|
2332
2062
|
var commentLabel = field.comment_label,
|
|
2333
|
-
|
|
2334
|
-
|
|
2063
|
+
parsed = _objectWithoutPropertiesLoose(field, ["comment_label"]);
|
|
2335
2064
|
return _extends({}, parsed, {
|
|
2336
2065
|
commentLabel: commentLabel
|
|
2337
2066
|
});
|
|
2338
2067
|
}
|
|
2339
|
-
|
|
2340
2068
|
default:
|
|
2341
2069
|
return field;
|
|
2342
2070
|
}
|
|
2343
2071
|
});
|
|
2344
2072
|
};
|
|
2345
|
-
|
|
2346
2073
|
var parseTicketFormFields = function parseTicketFormFields(fields) {
|
|
2347
2074
|
var withFakeIds = fields.map(function (field, index) {
|
|
2348
2075
|
return _extends({}, field, {
|
|
@@ -2351,7 +2078,6 @@ var parseTicketFormFields = function parseTicketFormFields(fields) {
|
|
|
2351
2078
|
});
|
|
2352
2079
|
return parseFields(withFakeIds);
|
|
2353
2080
|
};
|
|
2354
|
-
|
|
2355
2081
|
var parseForm$1 = function parseForm(form) {
|
|
2356
2082
|
var isTicketForm = !('id' in form.fields[0]);
|
|
2357
2083
|
return {
|
|
@@ -2359,66 +2085,54 @@ var parseForm$1 = function parseForm(form) {
|
|
|
2359
2085
|
fields: isTicketForm ? parseTicketFormFields(form.fields) : parseFields(form.fields)
|
|
2360
2086
|
};
|
|
2361
2087
|
};
|
|
2362
|
-
|
|
2363
2088
|
var parseGetFormResponse = function parseGetFormResponse(payload) {
|
|
2364
2089
|
if (!payload.enabled) {
|
|
2365
2090
|
return payload;
|
|
2366
2091
|
}
|
|
2367
|
-
|
|
2368
2092
|
return _extends({}, payload, {
|
|
2369
2093
|
form: parseForm$1(payload.form)
|
|
2370
2094
|
});
|
|
2371
2095
|
};
|
|
2372
|
-
|
|
2373
2096
|
var parseGetUrlInfoResponse = function parseGetUrlInfoResponse(payload) {
|
|
2374
2097
|
var urlInfo = {
|
|
2375
2098
|
url: payload.url
|
|
2376
2099
|
};
|
|
2377
|
-
|
|
2378
2100
|
if (payload.title) {
|
|
2379
2101
|
urlInfo.title = payload.title;
|
|
2380
2102
|
}
|
|
2381
|
-
|
|
2382
2103
|
if (payload.description) {
|
|
2383
2104
|
urlInfo.description = payload.description;
|
|
2384
2105
|
}
|
|
2385
|
-
|
|
2386
2106
|
if (payload.image_url) {
|
|
2387
|
-
urlInfo.imageUrl = "https://" + payload.image_url;
|
|
2388
|
-
|
|
2107
|
+
urlInfo.imageUrl = "https://" + removeProtocol(payload.image_url);
|
|
2389
2108
|
if (payload.image_width && payload.image_height) {
|
|
2390
2109
|
urlInfo.imageWidth = payload.image_width;
|
|
2391
2110
|
urlInfo.imageHeight = payload.image_height;
|
|
2392
2111
|
}
|
|
2393
2112
|
}
|
|
2394
|
-
|
|
2395
2113
|
return urlInfo;
|
|
2396
2114
|
};
|
|
2397
|
-
|
|
2398
2115
|
var getAvailabilityBasedOnDynamicConfig = function getAvailabilityBasedOnDynamicConfig(_ref2) {
|
|
2399
2116
|
var onlineGroups = _ref2.online_groups_ids,
|
|
2400
|
-
|
|
2401
|
-
|
|
2117
|
+
customerGroups = _ref2.customer_groups;
|
|
2402
2118
|
// this might be missing if all groups are offline
|
|
2403
2119
|
if (!onlineGroups) {
|
|
2404
2120
|
return 'offline';
|
|
2405
2121
|
}
|
|
2406
|
-
|
|
2407
2122
|
var monitoringGroupId = customerGroups.monitoring.id;
|
|
2408
2123
|
return includes(monitoringGroupId, onlineGroups) ? 'online' : 'offline';
|
|
2409
2124
|
};
|
|
2410
|
-
|
|
2411
2125
|
var parseListChatsResponse = function parseListChatsResponse(payload) {
|
|
2412
2126
|
var chatsSummary = payload.chats_summary.map(function (_ref3) {
|
|
2413
2127
|
var id = _ref3.id,
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2128
|
+
active = _ref3.active,
|
|
2129
|
+
access = _ref3.access,
|
|
2130
|
+
lastThreadCreatedAt = _ref3.last_thread_created_at,
|
|
2131
|
+
lastThreadId = _ref3.last_thread_id,
|
|
2132
|
+
lastEventsPerType = _ref3.last_event_per_type,
|
|
2133
|
+
_ref3$properties = _ref3.properties,
|
|
2134
|
+
properties = _ref3$properties === void 0 ? {} : _ref3$properties,
|
|
2135
|
+
users = _ref3.users;
|
|
2422
2136
|
var chatSummary = {
|
|
2423
2137
|
id: id,
|
|
2424
2138
|
active: active,
|
|
@@ -2429,11 +2143,9 @@ var parseListChatsResponse = function parseListChatsResponse(payload) {
|
|
|
2429
2143
|
lastThreadCreatedAt: lastThreadCreatedAt || null,
|
|
2430
2144
|
eventsSeenUpToMap: getEventsSeenUpToMap(users)
|
|
2431
2145
|
};
|
|
2432
|
-
|
|
2433
2146
|
if (!lastEventsPerType) {
|
|
2434
2147
|
return chatSummary;
|
|
2435
2148
|
}
|
|
2436
|
-
|
|
2437
2149
|
chatSummary.lastEventsPerType = mapValues(function (lastEventPerType) {
|
|
2438
2150
|
return parseEvent$1(lastEventPerType.thread_id, lastEventPerType.event);
|
|
2439
2151
|
}, lastEventsPerType);
|
|
@@ -2444,17 +2156,15 @@ var parseListChatsResponse = function parseListChatsResponse(payload) {
|
|
|
2444
2156
|
var lastEventSummary = last(lastEventSummariesArray.sort(function (eventSummaryA, eventSummaryB) {
|
|
2445
2157
|
return eventSummaryA.thread_id === eventSummaryB.thread_id ? stringCompare(eventSummaryA.event.created_at, eventSummaryB.event.created_at) : stringCompare(eventSummaryA.thread_created_at, eventSummaryB.thread_created_at);
|
|
2446
2158
|
}));
|
|
2447
|
-
|
|
2448
2159
|
if (lastEventSummary) {
|
|
2449
2160
|
chatSummary.lastEvent = chatSummary.lastEventsPerType[lastEventSummary.event.type];
|
|
2450
2161
|
}
|
|
2451
|
-
|
|
2452
2162
|
return chatSummary;
|
|
2453
2163
|
});
|
|
2454
2164
|
return {
|
|
2455
2165
|
chatsSummary: numericSortBy(function (_ref4) {
|
|
2456
2166
|
var lastEvent = _ref4.lastEvent,
|
|
2457
|
-
|
|
2167
|
+
order = _ref4.order;
|
|
2458
2168
|
return -1 * (lastEvent !== undefined ? lastEvent.timestamp : order);
|
|
2459
2169
|
}, chatsSummary),
|
|
2460
2170
|
totalChats: payload.total_chats,
|
|
@@ -2467,11 +2177,9 @@ var parseListChatsResponse = function parseListChatsResponse(payload) {
|
|
|
2467
2177
|
nextPageId: payload.next_page_id || null
|
|
2468
2178
|
};
|
|
2469
2179
|
};
|
|
2470
|
-
|
|
2471
2180
|
var parseListGroupStatusesResponse = function parseListGroupStatusesResponse(payload) {
|
|
2472
2181
|
return payload.groups_status;
|
|
2473
2182
|
};
|
|
2474
|
-
|
|
2475
2183
|
var parseListThreadsResponse = function parseListThreadsResponse(request, payload) {
|
|
2476
2184
|
return {
|
|
2477
2185
|
threads: payload.threads.map(function (thread) {
|
|
@@ -2481,11 +2189,10 @@ var parseListThreadsResponse = function parseListThreadsResponse(request, payloa
|
|
|
2481
2189
|
nextPageId: payload.next_page_id || null
|
|
2482
2190
|
};
|
|
2483
2191
|
};
|
|
2484
|
-
|
|
2485
2192
|
var parseLoginResponse = function parseLoginResponse(payload) {
|
|
2486
2193
|
var dynamicConfig = payload.__priv_dynamic_config,
|
|
2487
|
-
|
|
2488
|
-
|
|
2194
|
+
chats = payload.chats,
|
|
2195
|
+
greeting = payload.greeting;
|
|
2489
2196
|
return _extends({
|
|
2490
2197
|
dynamicConfig: dynamicConfig,
|
|
2491
2198
|
customer: parseCustomer(payload.customer),
|
|
@@ -2493,7 +2200,8 @@ var parseLoginResponse = function parseLoginResponse(payload) {
|
|
|
2493
2200
|
chats: chats.map(function (chat) {
|
|
2494
2201
|
return {
|
|
2495
2202
|
id: chat.chat_id,
|
|
2496
|
-
active: 'has_active_thread' in chat ? chat.has_active_thread :
|
|
2203
|
+
active: 'has_active_thread' in chat ? chat.has_active_thread :
|
|
2204
|
+
// temporary fallback, waiting for API to move this flag into `chats` array
|
|
2497
2205
|
payload.has_active_thread,
|
|
2498
2206
|
hasUnreadEvents: chat.has_unread_events
|
|
2499
2207
|
};
|
|
@@ -2502,7 +2210,6 @@ var parseLoginResponse = function parseLoginResponse(payload) {
|
|
|
2502
2210
|
greeting: parseGreeting(greeting)
|
|
2503
2211
|
});
|
|
2504
2212
|
};
|
|
2505
|
-
|
|
2506
2213
|
var parsePush = function parsePush(push) {
|
|
2507
2214
|
switch (push.action) {
|
|
2508
2215
|
case CHAT_DEACTIVATED:
|
|
@@ -2512,146 +2219,122 @@ var parsePush = function parsePush(push) {
|
|
|
2512
2219
|
chatId: push.payload.chat_id
|
|
2513
2220
|
}
|
|
2514
2221
|
};
|
|
2515
|
-
|
|
2516
2222
|
case CHAT_PROPERTIES_DELETED:
|
|
2517
2223
|
return {
|
|
2518
2224
|
action: push.action,
|
|
2519
2225
|
payload: parseChatPropertiesDeletedPush(push.payload)
|
|
2520
2226
|
};
|
|
2521
|
-
|
|
2522
2227
|
case CHAT_PROPERTIES_UPDATED:
|
|
2523
2228
|
return {
|
|
2524
2229
|
action: push.action,
|
|
2525
2230
|
payload: parseChatPropertiesUpdatedPush(push.payload)
|
|
2526
2231
|
};
|
|
2527
|
-
|
|
2528
2232
|
case CHAT_TRANSFERRED:
|
|
2529
2233
|
return {
|
|
2530
2234
|
action: push.action,
|
|
2531
2235
|
payload: parseChatTransferredPush(push.payload)
|
|
2532
2236
|
};
|
|
2533
|
-
|
|
2534
2237
|
case CUSTOMER_SIDE_STORAGE_UPDATED:
|
|
2535
2238
|
return {
|
|
2536
2239
|
action: push.action,
|
|
2537
2240
|
payload: push.payload
|
|
2538
2241
|
};
|
|
2539
|
-
|
|
2540
2242
|
case CUSTOMER_DISCONNECTED:
|
|
2541
2243
|
return {
|
|
2542
2244
|
action: push.action,
|
|
2543
2245
|
payload: push.payload
|
|
2544
2246
|
};
|
|
2545
|
-
|
|
2546
2247
|
case CUSTOMER_PAGE_UPDATED:
|
|
2547
2248
|
return {
|
|
2548
2249
|
action: push.action,
|
|
2549
2250
|
payload: parseCustomerPageUpdatedPush(push.payload)
|
|
2550
2251
|
};
|
|
2551
|
-
|
|
2552
2252
|
case CUSTOMER_UPDATED:
|
|
2553
2253
|
return {
|
|
2554
2254
|
action: push.action,
|
|
2555
2255
|
payload: parseCustomerUpdatedPush(push.payload)
|
|
2556
2256
|
};
|
|
2557
|
-
|
|
2558
2257
|
case EVENT_PROPERTIES_DELETED:
|
|
2559
2258
|
return {
|
|
2560
2259
|
action: push.action,
|
|
2561
2260
|
payload: parseEventPropertiesDeletedPush(push.payload)
|
|
2562
2261
|
};
|
|
2563
|
-
|
|
2564
2262
|
case EVENT_PROPERTIES_UPDATED:
|
|
2565
2263
|
return {
|
|
2566
2264
|
action: push.action,
|
|
2567
2265
|
payload: parseEventPropertiesUpdatedPush(push.payload)
|
|
2568
2266
|
};
|
|
2569
|
-
|
|
2570
2267
|
case EVENT_UPDATED:
|
|
2571
2268
|
return {
|
|
2572
2269
|
action: push.action,
|
|
2573
2270
|
payload: parseEventUpdatedPush(push.payload)
|
|
2574
2271
|
};
|
|
2575
|
-
|
|
2576
2272
|
case EVENTS_MARKED_AS_SEEN:
|
|
2577
2273
|
return {
|
|
2578
2274
|
action: push.action,
|
|
2579
2275
|
payload: parseEventsMarkedAsSeenPush(push.payload)
|
|
2580
2276
|
};
|
|
2581
|
-
|
|
2582
2277
|
case GREETING_ACCEPTED:
|
|
2583
2278
|
return {
|
|
2584
2279
|
action: push.action,
|
|
2585
2280
|
payload: parseGreetingAcceptedPush(push.payload)
|
|
2586
2281
|
};
|
|
2587
|
-
|
|
2588
2282
|
case GREETING_CANCELED:
|
|
2589
2283
|
return {
|
|
2590
2284
|
action: push.action,
|
|
2591
2285
|
// 'greeting_canceled' has the same payload as `greeting_accepted`
|
|
2592
2286
|
payload: parseGreetingAcceptedPush(push.payload)
|
|
2593
2287
|
};
|
|
2594
|
-
|
|
2595
2288
|
case INCOMING_CHAT:
|
|
2596
2289
|
return {
|
|
2597
2290
|
action: push.action,
|
|
2598
2291
|
payload: parseIncomingChatPush(push.payload)
|
|
2599
2292
|
};
|
|
2600
|
-
|
|
2601
2293
|
case INCOMING_EVENT:
|
|
2602
2294
|
return {
|
|
2603
2295
|
action: push.action,
|
|
2604
2296
|
payload: parseIncomingEventPush(push.payload)
|
|
2605
2297
|
};
|
|
2606
|
-
|
|
2607
2298
|
case INCOMING_GREETING:
|
|
2608
2299
|
return {
|
|
2609
2300
|
action: push.action,
|
|
2610
2301
|
payload: parseIncomingGreetingPush(push.payload)
|
|
2611
2302
|
};
|
|
2612
|
-
|
|
2613
2303
|
case INCOMING_MULTICAST:
|
|
2614
2304
|
return {
|
|
2615
2305
|
action: push.action,
|
|
2616
2306
|
payload: push.payload
|
|
2617
2307
|
};
|
|
2618
|
-
|
|
2619
2308
|
case INCOMING_RICH_MESSAGE_POSTBACK:
|
|
2620
2309
|
return {
|
|
2621
2310
|
action: push.action,
|
|
2622
2311
|
payload: parseIncomingRichMessagePostbackPush(push.payload)
|
|
2623
2312
|
};
|
|
2624
|
-
|
|
2625
2313
|
case INCOMING_TYPING_INDICATOR:
|
|
2626
2314
|
return {
|
|
2627
2315
|
action: push.action,
|
|
2628
2316
|
payload: parseIncomingTypingIndicatorPush(push.payload)
|
|
2629
2317
|
};
|
|
2630
|
-
|
|
2631
2318
|
case QUEUE_POSITION_UPDATED:
|
|
2632
2319
|
return {
|
|
2633
2320
|
action: push.action,
|
|
2634
2321
|
payload: parseQueuePositionUpdatedPush(push.payload)
|
|
2635
2322
|
};
|
|
2636
|
-
|
|
2637
2323
|
case THREAD_PROPERTIES_DELETED:
|
|
2638
2324
|
return {
|
|
2639
2325
|
action: push.action,
|
|
2640
2326
|
payload: parseThreadPropertiesDeletedPush(push.payload)
|
|
2641
2327
|
};
|
|
2642
|
-
|
|
2643
2328
|
case THREAD_PROPERTIES_UPDATED:
|
|
2644
2329
|
return {
|
|
2645
2330
|
action: push.action,
|
|
2646
2331
|
payload: parseThreadPropertiesUpdatedPush(push.payload)
|
|
2647
2332
|
};
|
|
2648
|
-
|
|
2649
2333
|
case USER_ADDED_TO_CHAT:
|
|
2650
2334
|
return {
|
|
2651
2335
|
action: push.action,
|
|
2652
2336
|
payload: parseUserAddedToChatPush(push.payload)
|
|
2653
2337
|
};
|
|
2654
|
-
|
|
2655
2338
|
case USER_REMOVED_FROM_CHAT:
|
|
2656
2339
|
return {
|
|
2657
2340
|
action: push.action,
|
|
@@ -2661,141 +2344,118 @@ var parsePush = function parsePush(push) {
|
|
|
2661
2344
|
};
|
|
2662
2345
|
var parseResponse = function parseResponse(_ref5) {
|
|
2663
2346
|
var request = _ref5.request,
|
|
2664
|
-
|
|
2665
|
-
|
|
2347
|
+
response = _ref5.response;
|
|
2666
2348
|
switch (response.action) {
|
|
2667
2349
|
case ACCEPT_GREETING:
|
|
2668
2350
|
return {
|
|
2669
2351
|
action: response.action,
|
|
2670
2352
|
payload: SUCCESS
|
|
2671
2353
|
};
|
|
2672
|
-
|
|
2673
2354
|
case CANCEL_GREETING:
|
|
2674
2355
|
return {
|
|
2675
2356
|
action: response.action,
|
|
2676
2357
|
payload: SUCCESS
|
|
2677
2358
|
};
|
|
2678
|
-
|
|
2679
2359
|
case DELETE_CHAT_PROPERTIES:
|
|
2680
2360
|
return {
|
|
2681
2361
|
action: response.action,
|
|
2682
2362
|
payload: SUCCESS
|
|
2683
2363
|
};
|
|
2684
|
-
|
|
2685
2364
|
case DELETE_EVENT_PROPERTIES:
|
|
2686
2365
|
return {
|
|
2687
2366
|
action: response.action,
|
|
2688
2367
|
payload: SUCCESS
|
|
2689
2368
|
};
|
|
2690
|
-
|
|
2691
2369
|
case DELETE_THREAD_PROPERTIES:
|
|
2692
2370
|
return {
|
|
2693
2371
|
action: response.action,
|
|
2694
2372
|
payload: SUCCESS
|
|
2695
2373
|
};
|
|
2696
|
-
|
|
2697
2374
|
case GET_CHAT:
|
|
2698
2375
|
return {
|
|
2699
2376
|
action: response.action,
|
|
2700
2377
|
payload: parseGetChatResponse(response.payload)
|
|
2701
2378
|
};
|
|
2702
|
-
|
|
2703
2379
|
case GET_CUSTOMER:
|
|
2704
2380
|
return {
|
|
2705
2381
|
action: response.action,
|
|
2706
2382
|
payload: parseCustomer(response.payload)
|
|
2707
2383
|
};
|
|
2708
|
-
|
|
2709
2384
|
case GET_FORM:
|
|
2710
2385
|
return {
|
|
2711
2386
|
action: response.action,
|
|
2712
2387
|
payload: parseGetFormResponse(response.payload)
|
|
2713
2388
|
};
|
|
2714
|
-
|
|
2715
2389
|
case GET_PREDICTED_AGENT:
|
|
2716
2390
|
return {
|
|
2717
2391
|
action: response.action,
|
|
2718
2392
|
payload: parsePredictedAgent(response.payload)
|
|
2719
2393
|
};
|
|
2720
|
-
|
|
2721
2394
|
case GET_URL_INFO:
|
|
2722
2395
|
return {
|
|
2723
2396
|
action: response.action,
|
|
2724
2397
|
payload: parseGetUrlInfoResponse(response.payload)
|
|
2725
2398
|
};
|
|
2726
|
-
|
|
2727
2399
|
case LIST_CHATS:
|
|
2728
2400
|
return {
|
|
2729
2401
|
action: response.action,
|
|
2730
2402
|
payload: parseListChatsResponse(response.payload)
|
|
2731
2403
|
};
|
|
2732
|
-
|
|
2733
2404
|
case LIST_GROUP_STATUSES:
|
|
2734
2405
|
return {
|
|
2735
2406
|
action: response.action,
|
|
2736
2407
|
payload: parseListGroupStatusesResponse(response.payload)
|
|
2737
2408
|
};
|
|
2738
|
-
|
|
2739
2409
|
case LIST_THREADS:
|
|
2740
2410
|
return {
|
|
2741
2411
|
action: response.action,
|
|
2742
2412
|
payload: parseListThreadsResponse(request, response.payload)
|
|
2743
2413
|
};
|
|
2744
|
-
|
|
2745
2414
|
case LOGIN:
|
|
2746
2415
|
return {
|
|
2747
2416
|
action: response.action,
|
|
2748
2417
|
payload: parseLoginResponse(response.payload)
|
|
2749
2418
|
};
|
|
2750
|
-
|
|
2751
2419
|
case MARK_EVENTS_AS_SEEN:
|
|
2752
2420
|
return {
|
|
2753
2421
|
action: response.action,
|
|
2754
2422
|
payload: SUCCESS
|
|
2755
2423
|
};
|
|
2756
|
-
|
|
2757
2424
|
case SEND_SNEAK_PEEK:
|
|
2758
2425
|
return {
|
|
2759
2426
|
action: response.action,
|
|
2760
2427
|
payload: SUCCESS
|
|
2761
2428
|
};
|
|
2762
|
-
|
|
2763
2429
|
case SET_CUSTOMER_SESSION_FIELDS:
|
|
2764
2430
|
return {
|
|
2765
2431
|
action: response.action,
|
|
2766
2432
|
payload: SUCCESS
|
|
2767
2433
|
};
|
|
2768
|
-
|
|
2769
2434
|
case SEND_RICH_MESSAGE_POSTBACK:
|
|
2770
2435
|
return {
|
|
2771
2436
|
action: response.action,
|
|
2772
2437
|
payload: SUCCESS
|
|
2773
2438
|
};
|
|
2774
|
-
|
|
2775
2439
|
case UPDATE_CHAT_PROPERTIES:
|
|
2776
2440
|
return {
|
|
2777
2441
|
action: response.action,
|
|
2778
2442
|
payload: SUCCESS
|
|
2779
2443
|
};
|
|
2780
|
-
|
|
2781
2444
|
case UPDATE_CUSTOMER:
|
|
2782
2445
|
return {
|
|
2783
2446
|
action: response.action,
|
|
2784
2447
|
payload: SUCCESS
|
|
2785
2448
|
};
|
|
2786
|
-
|
|
2787
2449
|
case UPDATE_CUSTOMER_PAGE$1:
|
|
2788
2450
|
return {
|
|
2789
2451
|
action: response.action,
|
|
2790
2452
|
payload: SUCCESS
|
|
2791
2453
|
};
|
|
2792
|
-
|
|
2793
2454
|
case UPDATE_EVENT_PROPERTIES:
|
|
2794
2455
|
return {
|
|
2795
2456
|
action: response.action,
|
|
2796
2457
|
payload: SUCCESS
|
|
2797
2458
|
};
|
|
2798
|
-
|
|
2799
2459
|
case UPDATE_THREAD_PROPERTIES:
|
|
2800
2460
|
return {
|
|
2801
2461
|
action: response.action,
|
|
@@ -2812,13 +2472,11 @@ var parseServerError = function parseServerError(error) {
|
|
|
2812
2472
|
|
|
2813
2473
|
var handleResponseError = function handleResponseError(_ref, response) {
|
|
2814
2474
|
var dispatch = _ref.dispatch,
|
|
2815
|
-
|
|
2475
|
+
getState = _ref.getState;
|
|
2816
2476
|
var requestId = response.request_id,
|
|
2817
|
-
|
|
2818
|
-
|
|
2477
|
+
payload = response.payload;
|
|
2819
2478
|
var _getRequest = getRequest(getState(), requestId),
|
|
2820
|
-
|
|
2821
|
-
|
|
2479
|
+
reject = _getRequest.reject;
|
|
2822
2480
|
dispatch({
|
|
2823
2481
|
type: REQUEST_FAILED,
|
|
2824
2482
|
payload: {
|
|
@@ -2828,17 +2486,14 @@ var handleResponseError = function handleResponseError(_ref, response) {
|
|
|
2828
2486
|
}
|
|
2829
2487
|
});
|
|
2830
2488
|
};
|
|
2831
|
-
|
|
2832
2489
|
var handleResponse$1 = function handleResponse(_ref2, response) {
|
|
2833
2490
|
var dispatch = _ref2.dispatch,
|
|
2834
|
-
|
|
2491
|
+
getState = _ref2.getState;
|
|
2835
2492
|
var requestId = response.request_id;
|
|
2836
|
-
|
|
2837
2493
|
var _getRequest2 = getRequest(getState(), requestId),
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2494
|
+
promise = _getRequest2.promise,
|
|
2495
|
+
resolve = _getRequest2.resolve,
|
|
2496
|
+
request = _getRequest2.request;
|
|
2842
2497
|
var parsedResponse = parseResponse({
|
|
2843
2498
|
request: request,
|
|
2844
2499
|
response: response
|
|
@@ -2852,16 +2507,13 @@ var handleResponse$1 = function handleResponse(_ref2, response) {
|
|
|
2852
2507
|
}, parsedResponse)
|
|
2853
2508
|
});
|
|
2854
2509
|
};
|
|
2855
|
-
|
|
2856
2510
|
var handlePushResponse = function handlePushResponse(_ref3, response) {
|
|
2857
2511
|
var dispatch = _ref3.dispatch,
|
|
2858
|
-
|
|
2512
|
+
getState = _ref3.getState;
|
|
2859
2513
|
var requestId = response.request_id;
|
|
2860
|
-
|
|
2861
2514
|
var _getRequest3 = getRequest(getState(), requestId),
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2515
|
+
promise = _getRequest3.promise,
|
|
2516
|
+
resolve = _getRequest3.resolve;
|
|
2865
2517
|
var parsedPush = parsePush(response);
|
|
2866
2518
|
dispatch({
|
|
2867
2519
|
type: PUSH_RESPONSE_RECEIVED,
|
|
@@ -2872,21 +2524,17 @@ var handlePushResponse = function handlePushResponse(_ref3, response) {
|
|
|
2872
2524
|
}, parsedPush)
|
|
2873
2525
|
});
|
|
2874
2526
|
};
|
|
2875
|
-
|
|
2876
2527
|
var handlePush$1 = function handlePush(store, push) {
|
|
2877
2528
|
var parsedPush = parsePush(push);
|
|
2878
|
-
|
|
2879
2529
|
if (!parsedPush) {
|
|
2880
2530
|
// defensive measure against receiving unknown push
|
|
2881
2531
|
return;
|
|
2882
2532
|
}
|
|
2883
|
-
|
|
2884
2533
|
store.dispatch({
|
|
2885
2534
|
type: PUSH_RECEIVED,
|
|
2886
2535
|
payload: parsedPush
|
|
2887
2536
|
});
|
|
2888
2537
|
};
|
|
2889
|
-
|
|
2890
2538
|
var socketListener = (function (store, socket) {
|
|
2891
2539
|
var dispatch = store.dispatch;
|
|
2892
2540
|
socket.on('connect', function () {
|
|
@@ -2900,20 +2548,17 @@ var socketListener = (function (store, socket) {
|
|
|
2900
2548
|
handleResponseError(store, message);
|
|
2901
2549
|
return;
|
|
2902
2550
|
}
|
|
2903
|
-
|
|
2904
2551
|
switch (message.action) {
|
|
2905
2552
|
case RESUME_CHAT:
|
|
2906
2553
|
case SEND_EVENT:
|
|
2907
2554
|
case START_CHAT:
|
|
2908
2555
|
// those are requests with indirect responses
|
|
2909
2556
|
return;
|
|
2910
|
-
|
|
2911
2557
|
default:
|
|
2912
2558
|
handleResponse$1(store, message);
|
|
2913
2559
|
return;
|
|
2914
2560
|
}
|
|
2915
2561
|
}
|
|
2916
|
-
|
|
2917
2562
|
if ('request_id' in message) {
|
|
2918
2563
|
switch (message.action) {
|
|
2919
2564
|
case INCOMING_CHAT:
|
|
@@ -2923,12 +2568,10 @@ var socketListener = (function (store, socket) {
|
|
|
2923
2568
|
return;
|
|
2924
2569
|
}
|
|
2925
2570
|
}
|
|
2926
|
-
|
|
2927
2571
|
handlePush$1(store, message);
|
|
2928
2572
|
});
|
|
2929
2573
|
socket.on('disconnect', function () {
|
|
2930
2574
|
failAllRequests(store, CONNECTION_LOST);
|
|
2931
|
-
|
|
2932
2575
|
if (getConnectionStatus(store.getState()) === CONNECTED) {
|
|
2933
2576
|
store.dispatch(socketDisconnected());
|
|
2934
2577
|
}
|
|
@@ -2947,18 +2590,15 @@ var socketListener = (function (store, socket) {
|
|
|
2947
2590
|
});
|
|
2948
2591
|
|
|
2949
2592
|
var INCORRECT_REQUESTER_STRUCTURE = 'incorrect requester structure';
|
|
2950
|
-
|
|
2951
2593
|
var appendString = function appendString(input, str) {
|
|
2952
2594
|
return input.length ? input + "\n" + str : str;
|
|
2953
2595
|
};
|
|
2954
|
-
|
|
2955
2596
|
var createTicketBody = function createTicketBody(state, _ref) {
|
|
2956
2597
|
var fields = _ref.fields,
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2598
|
+
customerId = _ref.customerId,
|
|
2599
|
+
_ref$groupId = _ref.groupId,
|
|
2600
|
+
groupId = _ref$groupId === void 0 ? state.groupId : _ref$groupId,
|
|
2601
|
+
timeZone = _ref.timeZone;
|
|
2962
2602
|
var ticketBody = _extends({
|
|
2963
2603
|
licence_id: state.licenseId,
|
|
2964
2604
|
ticket_message: '',
|
|
@@ -2974,101 +2614,78 @@ var createTicketBody = function createTicketBody(state, _ref) {
|
|
|
2974
2614
|
}, timeZone && {
|
|
2975
2615
|
timezone: timeZone
|
|
2976
2616
|
});
|
|
2977
|
-
|
|
2978
2617
|
return fields.reduce(function (body, field) {
|
|
2979
2618
|
switch (field.type) {
|
|
2980
2619
|
case 'subject':
|
|
2981
2620
|
{
|
|
2982
2621
|
var value = field.answer;
|
|
2983
2622
|
var text = value ? field.label + " " + value : field.label;
|
|
2984
|
-
|
|
2985
2623
|
if (value) {
|
|
2986
2624
|
body.subject = value;
|
|
2987
2625
|
}
|
|
2988
|
-
|
|
2989
2626
|
body.offline_message = appendString(body.offline_message, text);
|
|
2990
2627
|
return body;
|
|
2991
2628
|
}
|
|
2992
|
-
|
|
2993
2629
|
case 'name':
|
|
2994
2630
|
{
|
|
2995
2631
|
var _value = field.answer;
|
|
2996
|
-
|
|
2997
2632
|
var _text = _value ? field.label + " " + _value : field.label;
|
|
2998
|
-
|
|
2999
2633
|
if (_value) {
|
|
3000
2634
|
body.requester.name = _value;
|
|
3001
2635
|
}
|
|
3002
|
-
|
|
3003
2636
|
body.offline_message = appendString(body.offline_message, _text);
|
|
3004
2637
|
return body;
|
|
3005
2638
|
}
|
|
3006
|
-
|
|
3007
2639
|
case 'email':
|
|
3008
2640
|
{
|
|
3009
2641
|
var _value2 = field.answer;
|
|
3010
|
-
|
|
3011
2642
|
var _text2 = _value2 ? field.label + " " + _value2 : field.label;
|
|
3012
|
-
|
|
3013
2643
|
body.requester.mail = _value2;
|
|
3014
2644
|
body.offline_message = appendString(body.offline_message, _text2);
|
|
3015
2645
|
return body;
|
|
3016
2646
|
}
|
|
3017
|
-
|
|
3018
2647
|
case 'question':
|
|
3019
2648
|
case 'textarea':
|
|
3020
2649
|
{
|
|
3021
2650
|
var _value3 = field.answer;
|
|
3022
|
-
|
|
3023
2651
|
var _text3 = _value3 ? field.label + " " + _value3 : field.label;
|
|
3024
|
-
|
|
3025
2652
|
body.offline_message = appendString(body.offline_message, _text3);
|
|
3026
2653
|
body.ticket_message = appendString(body.ticket_message, _text3);
|
|
3027
2654
|
return body;
|
|
3028
2655
|
}
|
|
3029
|
-
|
|
3030
2656
|
case 'radio':
|
|
3031
2657
|
case 'select':
|
|
3032
2658
|
{
|
|
3033
2659
|
var _value4 = field.answer && field.answer.label;
|
|
3034
|
-
|
|
3035
2660
|
var _text4 = _value4 ? field.label + " " + _value4 : field.label;
|
|
3036
|
-
|
|
3037
2661
|
body.offline_message = appendString(body.offline_message, _text4);
|
|
3038
2662
|
body.ticket_message = appendString(body.ticket_message, _text4);
|
|
3039
2663
|
return body;
|
|
3040
2664
|
}
|
|
3041
|
-
|
|
3042
2665
|
case 'checkbox':
|
|
3043
2666
|
{
|
|
3044
2667
|
var _value5 = field.answers && field.answers.map(function (answer) {
|
|
3045
2668
|
return answer.label;
|
|
3046
2669
|
}).join(', ');
|
|
3047
|
-
|
|
3048
2670
|
var _text5 = _value5 ? field.label + " " + _value5 : field.label;
|
|
3049
|
-
|
|
3050
2671
|
body.offline_message = appendString(body.offline_message, _text5);
|
|
3051
2672
|
body.ticket_message = appendString(body.ticket_message, _text5);
|
|
3052
2673
|
return body;
|
|
3053
2674
|
}
|
|
3054
|
-
|
|
3055
2675
|
default:
|
|
3056
2676
|
return body;
|
|
3057
2677
|
}
|
|
3058
2678
|
}, ticketBody);
|
|
3059
2679
|
};
|
|
3060
|
-
|
|
3061
2680
|
var sendTicketForm = function sendTicketForm(store, auth, _ref2) {
|
|
3062
2681
|
var filledForm = _ref2.filledForm,
|
|
3063
|
-
|
|
3064
|
-
|
|
2682
|
+
groupId = _ref2.groupId,
|
|
2683
|
+
timeZone = _ref2.timeZone;
|
|
3065
2684
|
return auth.getToken().then(function (token) {
|
|
3066
2685
|
var state = store.getState();
|
|
3067
|
-
|
|
3068
2686
|
if (getSelfId(state) === null) {
|
|
3069
2687
|
store.dispatch(setSelfId(token.entityId));
|
|
3070
2688
|
}
|
|
3071
|
-
|
|
3072
2689
|
var url = getApiOrigin(state) + "/v2/tickets/new";
|
|
3073
2690
|
var body = createTicketBody(state, {
|
|
3074
2691
|
fields: filledForm.fields,
|
|
@@ -3089,33 +2706,28 @@ var sendTicketForm = function sendTicketForm(store, auth, _ref2) {
|
|
|
3089
2706
|
text: body.ticket_message
|
|
3090
2707
|
});
|
|
3091
2708
|
});
|
|
3092
|
-
}
|
|
3093
|
-
|
|
2709
|
+
}
|
|
3094
2710
|
|
|
2711
|
+
// we actually should normalize this somehow
|
|
3095
2712
|
if (response.status === 400 || response.status === 422) {
|
|
3096
2713
|
var errHandler = function errHandler(error) {
|
|
3097
2714
|
if (!error || !error.errors) {
|
|
3098
2715
|
// TODO: I honestly don't know if this can even be reached and even if it is - What error should be thrown here
|
|
3099
2716
|
throw new Error();
|
|
3100
|
-
}
|
|
3101
|
-
|
|
3102
|
-
|
|
2717
|
+
}
|
|
2718
|
+
// we receive some hardcore aggregate error here 😱
|
|
3103
2719
|
var firstError = error.errors[0];
|
|
3104
2720
|
var type = Object.keys(firstError)[0];
|
|
3105
|
-
|
|
3106
2721
|
if (type === INCORRECT_REQUESTER_STRUCTURE) {
|
|
3107
2722
|
throw createError({
|
|
3108
2723
|
message: firstError[INCORRECT_REQUESTER_STRUCTURE][0],
|
|
3109
2724
|
code: 'VALIDATION'
|
|
3110
2725
|
});
|
|
3111
2726
|
}
|
|
3112
|
-
|
|
3113
2727
|
throw new Error();
|
|
3114
2728
|
};
|
|
3115
|
-
|
|
3116
2729
|
return response.json().then(errHandler, errHandler);
|
|
3117
2730
|
}
|
|
3118
|
-
|
|
3119
2731
|
throw new Error();
|
|
3120
2732
|
});
|
|
3121
2733
|
});
|
|
@@ -3125,32 +2737,24 @@ var KILOBYTE = 1024;
|
|
|
3125
2737
|
var MEGABYTE = 1024 * KILOBYTE;
|
|
3126
2738
|
var GIGABYTE = 1024 * MEGABYTE;
|
|
3127
2739
|
var SIZE_LIMIT = 10 * MEGABYTE;
|
|
3128
|
-
|
|
3129
2740
|
var formatBytes = function formatBytes(bytes, precision) {
|
|
3130
2741
|
if (precision === void 0) {
|
|
3131
2742
|
precision = 2;
|
|
3132
2743
|
}
|
|
3133
|
-
|
|
3134
2744
|
if (bytes < KILOBYTE) {
|
|
3135
2745
|
return bytes + " b";
|
|
3136
2746
|
}
|
|
3137
|
-
|
|
3138
2747
|
var kilobytes = bytes / 1024;
|
|
3139
|
-
|
|
3140
2748
|
if (bytes < MEGABYTE) {
|
|
3141
2749
|
return kilobytes.toFixed(precision) + " kb";
|
|
3142
2750
|
}
|
|
3143
|
-
|
|
3144
2751
|
var megabytes = kilobytes / 1024;
|
|
3145
|
-
|
|
3146
2752
|
if (bytes < GIGABYTE) {
|
|
3147
2753
|
return megabytes.toFixed(precision) + " MB";
|
|
3148
2754
|
}
|
|
3149
|
-
|
|
3150
2755
|
var gigabytes = megabytes / 1024;
|
|
3151
2756
|
return gigabytes.toFixed(precision) + " GB";
|
|
3152
2757
|
};
|
|
3153
|
-
|
|
3154
2758
|
var validateFile = function validateFile(file) {
|
|
3155
2759
|
if (file.size > SIZE_LIMIT) {
|
|
3156
2760
|
throw createError({
|
|
@@ -3162,9 +2766,9 @@ var validateFile = function validateFile(file) {
|
|
|
3162
2766
|
|
|
3163
2767
|
var uploadFile = function uploadFile(_ref, _ref2) {
|
|
3164
2768
|
var auth = _ref.auth,
|
|
3165
|
-
|
|
2769
|
+
store = _ref.store;
|
|
3166
2770
|
var file = _ref2.file,
|
|
3167
|
-
|
|
2771
|
+
onProgress = _ref2.onProgress;
|
|
3168
2772
|
var upload;
|
|
3169
2773
|
var cancelled = false;
|
|
3170
2774
|
var send = new Promise(function (resolve, reject) {
|
|
@@ -3182,7 +2786,6 @@ var uploadFile = function uploadFile(_ref, _ref2) {
|
|
|
3182
2786
|
reject(new Error('Upload cancelled.'));
|
|
3183
2787
|
return;
|
|
3184
2788
|
}
|
|
3185
|
-
|
|
3186
2789
|
upload = rawUploadFile(url, payload, {
|
|
3187
2790
|
headers: {
|
|
3188
2791
|
Authorization: token.tokenType + " " + token.accessToken
|
|
@@ -3195,10 +2798,9 @@ var uploadFile = function uploadFile(_ref, _ref2) {
|
|
|
3195
2798
|
reject(uploadError);
|
|
3196
2799
|
return;
|
|
3197
2800
|
}
|
|
3198
|
-
|
|
3199
2801
|
var _uploadError$response = uploadError.response.error,
|
|
3200
|
-
|
|
3201
|
-
|
|
2802
|
+
type = _uploadError$response.type,
|
|
2803
|
+
message = _uploadError$response.message;
|
|
3202
2804
|
reject(createError({
|
|
3203
2805
|
message: message,
|
|
3204
2806
|
code: type.toUpperCase()
|
|
@@ -3212,9 +2814,7 @@ var uploadFile = function uploadFile(_ref, _ref2) {
|
|
|
3212
2814
|
if (cancelled) {
|
|
3213
2815
|
return;
|
|
3214
2816
|
}
|
|
3215
|
-
|
|
3216
2817
|
cancelled = true;
|
|
3217
|
-
|
|
3218
2818
|
if (upload) {
|
|
3219
2819
|
upload.cancel();
|
|
3220
2820
|
}
|
|
@@ -3227,7 +2827,6 @@ var makeGraylogRequest = function makeGraylogRequest(url, body) {
|
|
|
3227
2827
|
var img = new Image();
|
|
3228
2828
|
img.src = url + "?" + body;
|
|
3229
2829
|
img.onerror = noop;
|
|
3230
|
-
|
|
3231
2830
|
img.onload = function () {
|
|
3232
2831
|
return resolve();
|
|
3233
2832
|
};
|
|
@@ -3242,17 +2841,15 @@ var makeGraylogRequest = function makeGraylogRequest(url, body) {
|
|
|
3242
2841
|
*/
|
|
3243
2842
|
var log = function log(_ref) {
|
|
3244
2843
|
var env = _ref.env,
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
2844
|
+
licenseId = _ref.licenseId,
|
|
2845
|
+
eventName = _ref.eventName;
|
|
3248
2846
|
if (env !== 'production' || "customer_sdk" !== 'customer_sdk') {
|
|
3249
2847
|
return Promise.resolve();
|
|
3250
2848
|
}
|
|
3251
|
-
|
|
3252
2849
|
var message = {
|
|
3253
2850
|
event_name: eventName,
|
|
3254
2851
|
severity: 'Informational',
|
|
3255
|
-
sdkVersion: "3.1.
|
|
2852
|
+
sdkVersion: "3.1.2"
|
|
3256
2853
|
};
|
|
3257
2854
|
var body = {
|
|
3258
2855
|
licence_id: licenseId,
|
|
@@ -3264,26 +2861,20 @@ var log = function log(_ref) {
|
|
|
3264
2861
|
|
|
3265
2862
|
var LISTENER_IDENTITY = 'LISTENER_IDENTITY';
|
|
3266
2863
|
var listenersMap = {};
|
|
3267
|
-
|
|
3268
2864
|
var createDebuggedMethods = function createDebuggedMethods(methods, prefix) {
|
|
3269
2865
|
if (prefix === void 0) {
|
|
3270
2866
|
prefix = '';
|
|
3271
2867
|
}
|
|
3272
|
-
|
|
3273
2868
|
var methodNames = Object.keys(methods);
|
|
3274
2869
|
return methodNames.map(function (methodName) {
|
|
3275
2870
|
var method = methods[methodName];
|
|
3276
2871
|
return function () {
|
|
3277
2872
|
var _console;
|
|
3278
|
-
|
|
3279
2873
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
3280
2874
|
args[_key] = arguments[_key];
|
|
3281
2875
|
}
|
|
3282
|
-
|
|
3283
2876
|
(_console = console).info.apply(_console, [prefix + "." + methodName + "() ===>"].concat(args));
|
|
3284
|
-
|
|
3285
2877
|
var result = method.apply(void 0, args);
|
|
3286
|
-
|
|
3287
2878
|
if (typeof (result == null ? void 0 : result.then) === 'function') {
|
|
3288
2879
|
return result.then(function (data) {
|
|
3289
2880
|
console.info(prefix + "." + methodName + "() <===", data);
|
|
@@ -3293,7 +2884,6 @@ var createDebuggedMethods = function createDebuggedMethods(methods, prefix) {
|
|
|
3293
2884
|
throw err;
|
|
3294
2885
|
});
|
|
3295
2886
|
}
|
|
3296
|
-
|
|
3297
2887
|
return result;
|
|
3298
2888
|
};
|
|
3299
2889
|
}).reduce(function (acc, method, index) {
|
|
@@ -3301,78 +2891,61 @@ var createDebuggedMethods = function createDebuggedMethods(methods, prefix) {
|
|
|
3301
2891
|
return acc;
|
|
3302
2892
|
}, {});
|
|
3303
2893
|
};
|
|
3304
|
-
|
|
3305
2894
|
var createEnhancedListener = function createEnhancedListener(label, event, listener) {
|
|
3306
2895
|
if (listener[LISTENER_IDENTITY] === undefined) {
|
|
3307
2896
|
Object.defineProperty(listener, LISTENER_IDENTITY, {
|
|
3308
2897
|
value: {}
|
|
3309
2898
|
});
|
|
3310
2899
|
}
|
|
3311
|
-
|
|
3312
2900
|
if (listener[LISTENER_IDENTITY][event]) {
|
|
3313
2901
|
var enhancedListenerId = listener[LISTENER_IDENTITY][event];
|
|
3314
2902
|
return listenersMap[enhancedListenerId];
|
|
3315
2903
|
}
|
|
3316
|
-
|
|
3317
2904
|
var enhancedListener = function enhancedListener(data) {
|
|
3318
2905
|
console.info("." + label + "(\"" + event + "\") <===", data);
|
|
3319
2906
|
listener(data);
|
|
3320
2907
|
};
|
|
3321
|
-
|
|
3322
2908
|
var uniqueId = generateUniqueId(listenersMap);
|
|
3323
2909
|
listener[LISTENER_IDENTITY][event] = uniqueId;
|
|
3324
2910
|
listenersMap[uniqueId] = enhancedListener;
|
|
3325
2911
|
return enhancedListener;
|
|
3326
|
-
};
|
|
3327
|
-
|
|
2912
|
+
};
|
|
3328
2913
|
|
|
2914
|
+
// TODO: this really should just accept & return CustomerSdk type
|
|
3329
2915
|
var debug = (function (_sdk) {
|
|
3330
2916
|
var sdk = _sdk;
|
|
3331
|
-
|
|
3332
2917
|
if (process.env.NODE_ENV === 'production') {
|
|
3333
2918
|
console.warn('You probably do not want to use debug(customerSDK) in your production environment.');
|
|
3334
2919
|
}
|
|
3335
|
-
|
|
3336
2920
|
var _on = sdk.on,
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
2921
|
+
_once = sdk.once,
|
|
2922
|
+
_off = sdk.off,
|
|
2923
|
+
_getChatHistory = sdk.getChatHistory,
|
|
2924
|
+
auth = sdk.auth,
|
|
2925
|
+
rest = _objectWithoutPropertiesLoose(sdk, ["on", "once", "off", "getChatHistory", "auth"]);
|
|
3343
2926
|
var methods = createDebuggedMethods(rest);
|
|
3344
2927
|
return Object.freeze(_extends({
|
|
3345
2928
|
auth: Object.freeze(createDebuggedMethods(auth, '.auth'))
|
|
3346
2929
|
}, methods, {
|
|
3347
2930
|
getChatHistory: function getChatHistory() {
|
|
3348
2931
|
var _console2;
|
|
3349
|
-
|
|
3350
2932
|
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
3351
2933
|
args[_key2] = arguments[_key2];
|
|
3352
2934
|
}
|
|
3353
|
-
|
|
3354
2935
|
(_console2 = console).info.apply(_console2, [".getChatHistory()"].concat(args));
|
|
3355
|
-
|
|
3356
2936
|
var history = _getChatHistory.apply(void 0, args);
|
|
3357
|
-
|
|
3358
2937
|
var logLabel = 'history.next()';
|
|
3359
2938
|
return {
|
|
3360
2939
|
next: function next() {
|
|
3361
2940
|
var _console3;
|
|
3362
|
-
|
|
3363
2941
|
(_console3 = console).info.apply(_console3, [logLabel + " ===>"].concat(args));
|
|
3364
|
-
|
|
3365
2942
|
return history.next().then(function (data) {
|
|
3366
2943
|
var _console4;
|
|
3367
|
-
|
|
3368
2944
|
(_console4 = console).info.apply(_console4, [logLabel + " <==="].concat(args, [data]));
|
|
3369
|
-
|
|
3370
2945
|
return data;
|
|
3371
2946
|
}, function (err) {
|
|
3372
2947
|
var _console5;
|
|
3373
|
-
|
|
3374
2948
|
(_console5 = console).error.apply(_console5, [logLabel + " <==="].concat(args, [err]));
|
|
3375
|
-
|
|
3376
2949
|
throw err;
|
|
3377
2950
|
});
|
|
3378
2951
|
}
|
|
@@ -3381,12 +2954,10 @@ var debug = (function (_sdk) {
|
|
|
3381
2954
|
off: function off(event, listener) {
|
|
3382
2955
|
console.info(".off(\"" + event + "\", " + (listener.name || 'anonymous') + ")");
|
|
3383
2956
|
var enhancedListener = listener;
|
|
3384
|
-
|
|
3385
2957
|
if (listener[LISTENER_IDENTITY] !== undefined) {
|
|
3386
2958
|
var enhancedListenerId = listener[LISTENER_IDENTITY][event];
|
|
3387
2959
|
enhancedListener = listenersMap[enhancedListenerId];
|
|
3388
2960
|
}
|
|
3389
|
-
|
|
3390
2961
|
_off(event, enhancedListener);
|
|
3391
2962
|
},
|
|
3392
2963
|
on: function on(event, listener) {
|
|
@@ -3403,15 +2974,12 @@ var init = function init(config, env) {
|
|
|
3403
2974
|
if (env === void 0) {
|
|
3404
2975
|
env = 'production';
|
|
3405
2976
|
}
|
|
3406
|
-
|
|
3407
2977
|
validateConfig(config);
|
|
3408
|
-
|
|
3409
2978
|
var _config$autoConnect = config.autoConnect,
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
2979
|
+
autoConnect = _config$autoConnect === void 0 ? true : _config$autoConnect,
|
|
2980
|
+
customerDataProvider = config.customerDataProvider,
|
|
2981
|
+
identityProvider = config.identityProvider,
|
|
2982
|
+
instanceConfig = _objectWithoutPropertiesLoose(config, ["autoConnect", "customerDataProvider", "identityProvider"]);
|
|
3415
2983
|
var store = finalCreateStore(_extends({}, instanceConfig, {
|
|
3416
2984
|
env: env
|
|
3417
2985
|
}));
|
|
@@ -3425,19 +2993,16 @@ var init = function init(config, env) {
|
|
|
3425
2993
|
customerDataProvider: customerDataProvider
|
|
3426
2994
|
}));
|
|
3427
2995
|
socketListener(store, socket);
|
|
3428
|
-
|
|
3429
2996
|
var sendRequestAction$1 = sendRequestAction.bind(null, store);
|
|
3430
|
-
|
|
3431
2997
|
var startConnection = function startConnection() {
|
|
3432
2998
|
store.dispatch({
|
|
3433
2999
|
type: START_CONNECTION
|
|
3434
3000
|
});
|
|
3435
3001
|
};
|
|
3436
|
-
|
|
3437
3002
|
var api = Object.freeze({
|
|
3438
3003
|
acceptGreeting: function acceptGreeting(_ref) {
|
|
3439
3004
|
var greetingId = _ref.greetingId,
|
|
3440
|
-
|
|
3005
|
+
uniqueId = _ref.uniqueId;
|
|
3441
3006
|
return sendRequestAction$1(sendRequest(ACCEPT_GREETING, {
|
|
3442
3007
|
greeting_id: greetingId,
|
|
3443
3008
|
unique_id: uniqueId
|
|
@@ -3452,20 +3017,18 @@ var init = function init(config, env) {
|
|
|
3452
3017
|
},
|
|
3453
3018
|
cancelRate: function cancelRate(params) {
|
|
3454
3019
|
var chatId = params.chatId,
|
|
3455
|
-
|
|
3456
|
-
|
|
3020
|
+
_params$properties = params.properties,
|
|
3021
|
+
properties = _params$properties === void 0 ? ['score'] : _params$properties;
|
|
3457
3022
|
return api.listThreads({
|
|
3458
3023
|
chatId: chatId
|
|
3459
3024
|
}).then(function (_ref3) {
|
|
3460
3025
|
var threads = _ref3.threads;
|
|
3461
|
-
|
|
3462
3026
|
if (!threads.length) {
|
|
3463
3027
|
throw createError({
|
|
3464
3028
|
message: "There is no thread in \"" + chatId + "\".",
|
|
3465
3029
|
code: MISSING_CHAT_THREAD
|
|
3466
3030
|
});
|
|
3467
3031
|
}
|
|
3468
|
-
|
|
3469
3032
|
return api.deleteThreadProperties({
|
|
3470
3033
|
chatId: chatId,
|
|
3471
3034
|
threadId: threads[0].id,
|
|
@@ -3484,7 +3047,7 @@ var init = function init(config, env) {
|
|
|
3484
3047
|
},
|
|
3485
3048
|
deleteChatProperties: function deleteChatProperties(_ref5) {
|
|
3486
3049
|
var id = _ref5.id,
|
|
3487
|
-
|
|
3050
|
+
properties = _ref5.properties;
|
|
3488
3051
|
return sendRequestAction$1(sendRequest(DELETE_CHAT_PROPERTIES, {
|
|
3489
3052
|
id: id,
|
|
3490
3053
|
properties: properties
|
|
@@ -3492,9 +3055,9 @@ var init = function init(config, env) {
|
|
|
3492
3055
|
},
|
|
3493
3056
|
deleteEventProperties: function deleteEventProperties(_ref6) {
|
|
3494
3057
|
var chatId = _ref6.chatId,
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
3058
|
+
threadId = _ref6.threadId,
|
|
3059
|
+
eventId = _ref6.eventId,
|
|
3060
|
+
properties = _ref6.properties;
|
|
3498
3061
|
return sendRequestAction$1(sendRequest(DELETE_EVENT_PROPERTIES, {
|
|
3499
3062
|
chat_id: chatId,
|
|
3500
3063
|
thread_id: threadId,
|
|
@@ -3504,8 +3067,8 @@ var init = function init(config, env) {
|
|
|
3504
3067
|
},
|
|
3505
3068
|
deleteThreadProperties: function deleteThreadProperties(_ref7) {
|
|
3506
3069
|
var chatId = _ref7.chatId,
|
|
3507
|
-
|
|
3508
|
-
|
|
3070
|
+
threadId = _ref7.threadId,
|
|
3071
|
+
properties = _ref7.properties;
|
|
3509
3072
|
return sendRequestAction$1(sendRequest(DELETE_THREAD_PROPERTIES, {
|
|
3510
3073
|
chat_id: chatId,
|
|
3511
3074
|
thread_id: threadId,
|
|
@@ -3520,7 +3083,7 @@ var init = function init(config, env) {
|
|
|
3520
3083
|
},
|
|
3521
3084
|
getChat: function getChat(_ref8) {
|
|
3522
3085
|
var chatId = _ref8.chatId,
|
|
3523
|
-
|
|
3086
|
+
threadId = _ref8.threadId;
|
|
3524
3087
|
return sendRequestAction$1(sendRequest(GET_CHAT, {
|
|
3525
3088
|
chat_id: chatId,
|
|
3526
3089
|
thread_id: threadId
|
|
@@ -3535,7 +3098,7 @@ var init = function init(config, env) {
|
|
|
3535
3098
|
},
|
|
3536
3099
|
getForm: function getForm(_ref10) {
|
|
3537
3100
|
var groupId = _ref10.groupId,
|
|
3538
|
-
|
|
3101
|
+
type = _ref10.type;
|
|
3539
3102
|
return sendRequestAction$1(sendRequest(GET_FORM, {
|
|
3540
3103
|
group_id: groupId,
|
|
3541
3104
|
type: type
|
|
@@ -3545,9 +3108,8 @@ var init = function init(config, env) {
|
|
|
3545
3108
|
if (params === void 0) {
|
|
3546
3109
|
params = {};
|
|
3547
3110
|
}
|
|
3548
|
-
|
|
3549
3111
|
var _params = params,
|
|
3550
|
-
|
|
3112
|
+
groupId = _params.groupId;
|
|
3551
3113
|
return sendRequestAction$1(sendRequest(GET_PREDICTED_AGENT, typeof groupId === 'number' ? {
|
|
3552
3114
|
group_id: groupId
|
|
3553
3115
|
} : {}));
|
|
@@ -3562,11 +3124,9 @@ var init = function init(config, env) {
|
|
|
3562
3124
|
if (params === void 0) {
|
|
3563
3125
|
params = {};
|
|
3564
3126
|
}
|
|
3565
|
-
|
|
3566
3127
|
if ('limit' in params && typeof params.limit === 'number' && params.limit > CHATS_PAGINATION_MAX_LIMIT) {
|
|
3567
3128
|
return Promise.reject(new Error("Specified limit is too high (max " + CHATS_PAGINATION_MAX_LIMIT + ")."));
|
|
3568
3129
|
}
|
|
3569
|
-
|
|
3570
3130
|
return sendRequestAction$1(sendRequest(LIST_CHATS, params.pageId === undefined ? {
|
|
3571
3131
|
limit: params.limit || 10
|
|
3572
3132
|
} : {
|
|
@@ -3575,8 +3135,7 @@ var init = function init(config, env) {
|
|
|
3575
3135
|
},
|
|
3576
3136
|
listGroupStatuses: function listGroupStatuses(_temp) {
|
|
3577
3137
|
var _ref12 = _temp === void 0 ? {} : _temp,
|
|
3578
|
-
|
|
3579
|
-
|
|
3138
|
+
groupIds = _ref12.groupIds;
|
|
3580
3139
|
return sendRequestAction$1(sendRequest(LIST_GROUP_STATUSES, groupIds ? {
|
|
3581
3140
|
group_ids: groupIds
|
|
3582
3141
|
} : {
|
|
@@ -3596,7 +3155,7 @@ var init = function init(config, env) {
|
|
|
3596
3155
|
},
|
|
3597
3156
|
markEventsAsSeen: function markEventsAsSeen(_ref13) {
|
|
3598
3157
|
var chatId = _ref13.chatId,
|
|
3599
|
-
|
|
3158
|
+
seenUpTo = _ref13.seenUpTo;
|
|
3600
3159
|
return sendRequestAction$1(sendRequest(MARK_EVENTS_AS_SEEN, {
|
|
3601
3160
|
chat_id: chatId,
|
|
3602
3161
|
seen_up_to: seenUpTo
|
|
@@ -3607,19 +3166,17 @@ var init = function init(config, env) {
|
|
|
3607
3166
|
off: emitter.off,
|
|
3608
3167
|
rateChat: function rateChat(params) {
|
|
3609
3168
|
var chatId = params.chatId,
|
|
3610
|
-
|
|
3169
|
+
rating = params.rating;
|
|
3611
3170
|
return api.listThreads({
|
|
3612
3171
|
chatId: chatId
|
|
3613
3172
|
}).then(function (_ref14) {
|
|
3614
3173
|
var threads = _ref14.threads;
|
|
3615
|
-
|
|
3616
3174
|
if (!threads.length) {
|
|
3617
3175
|
throw createError({
|
|
3618
3176
|
message: "There is no thread in \"" + chatId + "\".",
|
|
3619
3177
|
code: MISSING_CHAT_THREAD
|
|
3620
3178
|
});
|
|
3621
3179
|
}
|
|
3622
|
-
|
|
3623
3180
|
return api.updateThreadProperties({
|
|
3624
3181
|
chatId: chatId,
|
|
3625
3182
|
threadId: threads[0].id,
|
|
@@ -3641,11 +3198,9 @@ var init = function init(config, env) {
|
|
|
3641
3198
|
function sendEvent(_x) {
|
|
3642
3199
|
return _sendEvent.apply(this, arguments);
|
|
3643
3200
|
}
|
|
3644
|
-
|
|
3645
3201
|
sendEvent.toString = function () {
|
|
3646
3202
|
return _sendEvent.toString();
|
|
3647
3203
|
};
|
|
3648
|
-
|
|
3649
3204
|
return sendEvent;
|
|
3650
3205
|
}(function (params) {
|
|
3651
3206
|
return sendRequestAction$1(sendEvent(params));
|
|
@@ -3655,9 +3210,9 @@ var init = function init(config, env) {
|
|
|
3655
3210
|
},
|
|
3656
3211
|
sendRichMessagePostback: function sendRichMessagePostback(_ref15) {
|
|
3657
3212
|
var chatId = _ref15.chatId,
|
|
3658
|
-
|
|
3659
|
-
|
|
3660
|
-
|
|
3213
|
+
threadId = _ref15.threadId,
|
|
3214
|
+
eventId = _ref15.eventId,
|
|
3215
|
+
postback = _ref15.postback;
|
|
3661
3216
|
return sendRequestAction$1(sendRequest(SEND_RICH_MESSAGE_POSTBACK, {
|
|
3662
3217
|
chat_id: chatId,
|
|
3663
3218
|
event_id: eventId,
|
|
@@ -3673,13 +3228,11 @@ var init = function init(config, env) {
|
|
|
3673
3228
|
},
|
|
3674
3229
|
setSneakPeek: function setSneakPeek(_ref17) {
|
|
3675
3230
|
var chatId = _ref17.chatId,
|
|
3676
|
-
|
|
3231
|
+
sneakPeekText = _ref17.sneakPeekText;
|
|
3677
3232
|
var state = store.getState();
|
|
3678
|
-
|
|
3679
3233
|
if (!isChatActive(state, chatId) || !isConnected(state)) {
|
|
3680
3234
|
return;
|
|
3681
3235
|
}
|
|
3682
|
-
|
|
3683
3236
|
sendRequestAction$1(sendRequest(SEND_SNEAK_PEEK, {
|
|
3684
3237
|
chat_id: chatId,
|
|
3685
3238
|
sneak_peek_text: sneakPeekText
|
|
@@ -3689,7 +3242,6 @@ var init = function init(config, env) {
|
|
|
3689
3242
|
if (data === void 0) {
|
|
3690
3243
|
data = {};
|
|
3691
3244
|
}
|
|
3692
|
-
|
|
3693
3245
|
log({
|
|
3694
3246
|
env: env,
|
|
3695
3247
|
licenseId: config.licenseId,
|
|
@@ -3699,7 +3251,7 @@ var init = function init(config, env) {
|
|
|
3699
3251
|
},
|
|
3700
3252
|
updateChatProperties: function updateChatProperties(_ref18) {
|
|
3701
3253
|
var id = _ref18.id,
|
|
3702
|
-
|
|
3254
|
+
properties = _ref18.properties;
|
|
3703
3255
|
return sendRequestAction$1(sendRequest(UPDATE_CHAT_PROPERTIES, {
|
|
3704
3256
|
id: id,
|
|
3705
3257
|
properties: properties
|
|
@@ -3716,9 +3268,9 @@ var init = function init(config, env) {
|
|
|
3716
3268
|
},
|
|
3717
3269
|
updateEventProperties: function updateEventProperties(_ref19) {
|
|
3718
3270
|
var chatId = _ref19.chatId,
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
|
|
3271
|
+
threadId = _ref19.threadId,
|
|
3272
|
+
eventId = _ref19.eventId,
|
|
3273
|
+
properties = _ref19.properties;
|
|
3722
3274
|
return sendRequestAction$1(sendRequest(UPDATE_EVENT_PROPERTIES, {
|
|
3723
3275
|
chat_id: chatId,
|
|
3724
3276
|
event_id: eventId,
|
|
@@ -3728,8 +3280,8 @@ var init = function init(config, env) {
|
|
|
3728
3280
|
},
|
|
3729
3281
|
updateThreadProperties: function updateThreadProperties(_ref20) {
|
|
3730
3282
|
var chatId = _ref20.chatId,
|
|
3731
|
-
|
|
3732
|
-
|
|
3283
|
+
threadId = _ref20.threadId,
|
|
3284
|
+
properties = _ref20.properties;
|
|
3733
3285
|
return sendRequestAction$1(sendRequest(UPDATE_THREAD_PROPERTIES, {
|
|
3734
3286
|
chat_id: chatId,
|
|
3735
3287
|
thread_id: threadId,
|
|
@@ -3743,7 +3295,6 @@ var init = function init(config, env) {
|
|
|
3743
3295
|
}, options);
|
|
3744
3296
|
}
|
|
3745
3297
|
});
|
|
3746
|
-
|
|
3747
3298
|
if (autoConnect) {
|
|
3748
3299
|
startConnection();
|
|
3749
3300
|
} else {
|
|
@@ -3754,7 +3305,6 @@ var init = function init(config, env) {
|
|
|
3754
3305
|
}
|
|
3755
3306
|
});
|
|
3756
3307
|
}
|
|
3757
|
-
|
|
3758
3308
|
return api;
|
|
3759
3309
|
};
|
|
3760
3310
|
|