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