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