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