@twilio/conversations 3.0.0-rc.8 → 3.0.0
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 +39 -29
- package/builds/browser.esm.js +10838 -0
- package/builds/browser.esm.js.map +1 -0
- package/builds/browser.js +2494 -476
- package/builds/browser.js.map +1 -1
- package/builds/lib.d.ts +805 -70
- package/builds/lib.esm.d.ts +3178 -0
- package/builds/lib.esm.js +10837 -0
- package/builds/lib.js +2494 -476
- package/builds/lib.js.map +1 -1
- package/builds/twilio-conversations.js +29167 -26611
- package/builds/twilio-conversations.js.map +1 -0
- package/builds/twilio-conversations.min.js +2 -1
- package/builds/twilio-conversations.min.js.map +1 -0
- package/dist/aggregated-delivery-receipt.js +10 -5
- package/dist/aggregated-delivery-receipt.js.map +1 -1
- package/dist/channel-metadata-client.js +187 -0
- package/dist/channel-metadata-client.js.map +1 -0
- package/dist/client.js +266 -192
- package/dist/client.js.map +1 -1
- package/dist/command-executor.js +51 -14
- package/dist/command-executor.js.map +1 -1
- package/dist/configuration.js +23 -12
- package/dist/configuration.js.map +1 -1
- package/dist/content-client.js +180 -0
- package/dist/content-client.js.map +1 -0
- package/dist/content-template.js +304 -0
- package/dist/content-template.js.map +1 -0
- package/dist/conversation.js +213 -134
- package/dist/conversation.js.map +1 -1
- package/dist/data/conversations.js +70 -50
- package/dist/data/conversations.js.map +1 -1
- package/dist/data/messages.js +40 -27
- package/dist/data/messages.js.map +1 -1
- package/dist/data/participants.js +38 -32
- package/dist/data/participants.js.map +1 -1
- package/dist/data/users.js +19 -14
- package/dist/data/users.js.map +1 -1
- package/dist/detailed-delivery-receipt.js +9 -4
- package/dist/detailed-delivery-receipt.js.map +1 -1
- package/dist/index.js +26 -41
- package/dist/index.js.map +1 -1
- package/dist/interfaces/notification-types.js +9 -4
- package/dist/interfaces/notification-types.js.map +1 -1
- package/dist/interfaces/{attributes.js → rules.js} +26 -13
- package/dist/interfaces/rules.js.map +1 -0
- package/dist/logger.js +17 -28
- package/dist/logger.js.map +1 -1
- package/dist/media.js +40 -24
- package/dist/media.js.map +1 -1
- package/dist/message-builder.js +79 -12
- package/dist/message-builder.js.map +1 -1
- package/dist/message-recipients-client.js +231 -0
- package/dist/message-recipients-client.js.map +1 -0
- package/dist/message.js +258 -92
- package/dist/message.js.map +1 -1
- package/dist/node_modules/quick-lru/index.js +261 -0
- package/dist/node_modules/quick-lru/index.js.map +1 -0
- package/dist/node_modules/tslib/tslib.es6.js +15 -5
- package/dist/node_modules/tslib/tslib.es6.js.map +1 -1
- package/dist/packages/conversations/package.json.js +12 -7
- package/dist/packages/conversations/package.json.js.map +1 -1
- package/dist/participant.js +42 -38
- package/dist/participant.js.map +1 -1
- package/dist/push-notification.js +9 -4
- package/dist/push-notification.js.map +1 -1
- package/dist/rest-paginator.js +9 -4
- package/dist/rest-paginator.js.map +1 -1
- package/dist/services/network.js +11 -6
- package/dist/services/network.js.map +1 -1
- package/dist/services/typing-indicator.js +17 -11
- package/dist/services/typing-indicator.js.map +1 -1
- package/dist/unsent-message.js +14 -9
- package/dist/unsent-message.js.map +1 -1
- package/dist/user.js +40 -32
- package/dist/user.js.map +1 -1
- package/dist/util/deferred.js +9 -4
- package/dist/util/deferred.js.map +1 -1
- package/dist/util/index.js +44 -8
- package/dist/util/index.js.map +1 -1
- package/docs/assets/js/search.js +1 -1
- package/docs/classes/AggregatedDeliveryReceipt.html +1 -1
- package/docs/classes/ChannelMetadata.html +3050 -0
- package/docs/classes/Client.html +98 -27
- package/docs/classes/ContentTemplate.html +3116 -0
- package/docs/classes/ContentTemplateVariable.html +3116 -0
- package/docs/classes/Conversation.html +46 -9
- package/docs/classes/EmailRecipientDescriptor.html +3098 -0
- package/docs/classes/Message.html +99 -5
- package/docs/classes/MessageBuilder.html +41 -0
- package/docs/classes/Participant.html +2 -2
- package/docs/classes/UnknownRecipientDescriptor.html +3067 -0
- package/docs/index.html +892 -28
- package/docs/interfaces/ClientOptions.html +32 -0
- package/docs/interfaces/CreateConversationOptions.html +17 -0
- package/docs/modules.html +891 -27
- package/package.json +21 -19
- package/CHANGELOG.md +0 -501
- package/dist/interfaces/attributes.js.map +0 -1
package/builds/lib.js
CHANGED
|
@@ -128,6 +128,15 @@ This software includes platform.js under the following license.
|
|
|
128
128
|
*/
|
|
129
129
|
'use strict';
|
|
130
130
|
|
|
131
|
+
var global =
|
|
132
|
+
typeof global !== "undefined"
|
|
133
|
+
? global
|
|
134
|
+
: typeof self !== "undefined"
|
|
135
|
+
? self
|
|
136
|
+
: typeof window !== "undefined"
|
|
137
|
+
? window
|
|
138
|
+
: {};
|
|
139
|
+
|
|
131
140
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
132
141
|
|
|
133
142
|
require('core-js/modules/es.reflect.to-string-tag.js');
|
|
@@ -145,10 +154,10 @@ var _getPrototypeOf = require('@babel/runtime/helpers/getPrototypeOf');
|
|
|
145
154
|
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
146
155
|
var _createClass = require('@babel/runtime/helpers/createClass');
|
|
147
156
|
var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
|
|
148
|
-
require('core-js/modules/es.object.to-string.js');
|
|
149
|
-
require('core-js/modules/es.promise.js');
|
|
150
157
|
require('core-js/modules/es.array.map.js');
|
|
158
|
+
require('core-js/modules/es.object.to-string.js');
|
|
151
159
|
require('core-js/modules/web.dom-collections.for-each.js');
|
|
160
|
+
require('core-js/modules/es.promise.js');
|
|
152
161
|
var _regeneratorRuntime = require('@babel/runtime/regenerator');
|
|
153
162
|
var _typeof = require('@babel/runtime/helpers/typeof');
|
|
154
163
|
require('core-js/modules/es.array.concat.js');
|
|
@@ -164,9 +173,9 @@ require('core-js/modules/es.regexp.exec.js');
|
|
|
164
173
|
require('core-js/modules/es.string.replace.js');
|
|
165
174
|
require('core-js/modules/es.array.join.js');
|
|
166
175
|
var declarativeTypeValidator = require('@twilio/declarative-type-validator');
|
|
176
|
+
var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
|
|
167
177
|
require('core-js/modules/es.array.includes.js');
|
|
168
178
|
var replayEventEmitter = require('@twilio/replay-event-emitter');
|
|
169
|
-
var isEqual = require('lodash.isequal');
|
|
170
179
|
require('core-js/modules/es.array.slice.js');
|
|
171
180
|
require('core-js/modules/es.function.name.js');
|
|
172
181
|
require('core-js/modules/es.regexp.test.js');
|
|
@@ -179,7 +188,6 @@ var twilsock = require('twilsock');
|
|
|
179
188
|
var notifications = require('@twilio/notifications');
|
|
180
189
|
var twilioSync = require('twilio-sync');
|
|
181
190
|
var mcsClient = require('@twilio/mcs-client');
|
|
182
|
-
var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
|
|
183
191
|
require('core-js/modules/es.set.js');
|
|
184
192
|
require('core-js/modules/es.number.is-integer.js');
|
|
185
193
|
require('core-js/modules/es.typed-array.uint8-array.js');
|
|
@@ -208,13 +216,17 @@ require('core-js/modules/es.typed-array.subarray.js');
|
|
|
208
216
|
require('core-js/modules/es.typed-array.to-locale-string.js');
|
|
209
217
|
require('core-js/modules/es.typed-array.to-string.js');
|
|
210
218
|
require('core-js/modules/es.array-buffer.constructor.js');
|
|
211
|
-
require('isomorphic-form-data');
|
|
212
219
|
require('core-js/modules/es.array.sort.js');
|
|
213
220
|
require('core-js/modules/es.string.includes.js');
|
|
221
|
+
require('core-js/modules/es.string.starts-with.js');
|
|
222
|
+
require('core-js/modules/es.weak-set.js');
|
|
223
|
+
var deprecationDecorator = require('@twilio/deprecation-decorator');
|
|
224
|
+
require('core-js/modules/es.object.entries.js');
|
|
214
225
|
require('core-js/modules/es.array.find.js');
|
|
215
226
|
require('core-js/modules/es.array.splice.js');
|
|
216
|
-
require('
|
|
227
|
+
var _wrapNativeSuper = require('@babel/runtime/helpers/wrapNativeSuper');
|
|
217
228
|
var uuid = require('uuid');
|
|
229
|
+
require('core-js/modules/es.object.freeze.js');
|
|
218
230
|
|
|
219
231
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
220
232
|
|
|
@@ -247,9 +259,9 @@ var _classCallCheck__default = /*#__PURE__*/_interopDefaultLegacy(_classCallChec
|
|
|
247
259
|
var _regeneratorRuntime__default = /*#__PURE__*/_interopDefaultLegacy(_regeneratorRuntime);
|
|
248
260
|
var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof);
|
|
249
261
|
var loglevelLog__namespace = /*#__PURE__*/_interopNamespace(loglevelLog);
|
|
250
|
-
var isEqual__default = /*#__PURE__*/_interopDefaultLegacy(isEqual);
|
|
251
|
-
var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);
|
|
252
262
|
var _toConsumableArray__default = /*#__PURE__*/_interopDefaultLegacy(_toConsumableArray);
|
|
263
|
+
var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);
|
|
264
|
+
var _wrapNativeSuper__default = /*#__PURE__*/_interopDefaultLegacy(_wrapNativeSuper);
|
|
253
265
|
|
|
254
266
|
function __decorate(decorators, target, key, desc) {
|
|
255
267
|
var c = arguments.length,
|
|
@@ -287,11 +299,13 @@ var Logger = /*#__PURE__*/function () {
|
|
|
287
299
|
}, {
|
|
288
300
|
key: "trace",
|
|
289
301
|
value: function trace() {
|
|
290
|
-
|
|
291
|
-
args
|
|
292
|
-
|
|
302
|
+
if (log$7.getLevel() == log$7.levels.TRACE) {
|
|
303
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
304
|
+
args[_key] = arguments[_key];
|
|
305
|
+
}
|
|
293
306
|
|
|
294
|
-
|
|
307
|
+
log$7.debug.apply(null, prepareLine(this.prefix + "T", args));
|
|
308
|
+
}
|
|
295
309
|
}
|
|
296
310
|
}, {
|
|
297
311
|
key: "debug",
|
|
@@ -342,11 +356,13 @@ var Logger = /*#__PURE__*/function () {
|
|
|
342
356
|
}, {
|
|
343
357
|
key: "trace",
|
|
344
358
|
value: function trace() {
|
|
345
|
-
|
|
346
|
-
args
|
|
347
|
-
|
|
359
|
+
if (log$7.getLevel() == log$7.levels.TRACE) {
|
|
360
|
+
for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
|
|
361
|
+
args[_key6] = arguments[_key6];
|
|
362
|
+
}
|
|
348
363
|
|
|
349
|
-
|
|
364
|
+
log$7.debug.apply(null, prepareLine("T", args));
|
|
365
|
+
}
|
|
350
366
|
}
|
|
351
367
|
}, {
|
|
352
368
|
key: "debug",
|
|
@@ -389,9 +405,9 @@ var Logger = /*#__PURE__*/function () {
|
|
|
389
405
|
return Logger;
|
|
390
406
|
}();
|
|
391
407
|
|
|
392
|
-
function ownKeys$
|
|
408
|
+
function ownKeys$5(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
393
409
|
|
|
394
|
-
function _objectSpread$
|
|
410
|
+
function _objectSpread$5(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$5(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$5(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
395
411
|
var TYPING_TIMEOUT = 5;
|
|
396
412
|
var HTTP_CACHE_LIFETIME = "PT5S";
|
|
397
413
|
var CONSUMPTION_HORIZON_SENDING_INTERVAL = "PT5S";
|
|
@@ -400,9 +416,11 @@ var MINIMUM_RETRY_DELAY = 1000;
|
|
|
400
416
|
var MAXIMUM_RETRY_DELAY = 4000;
|
|
401
417
|
var MAXIMUM_ATTEMPTS_COUNT = 3;
|
|
402
418
|
var RETRY_WHEN_THROTTLED = true;
|
|
419
|
+
var CHANNEL_METADATA_CACHE_CAPACITY = 100;
|
|
420
|
+
var MESSAGE_RECIPIENTS_CACHE_CAPACITY = 1000;
|
|
403
421
|
|
|
404
422
|
var Configuration = /*#__PURE__*/_createClass__default["default"](function Configuration() {
|
|
405
|
-
var _ref, _constructorOptions$u, _ref2, _constructorOptions$h, _ref3, _constructorOptions$c;
|
|
423
|
+
var _ref, _constructorOptions$u, _ref2, _constructorOptions$h, _ref3, _constructorOptions$c, _options$channelMetad, _options$messageRecip;
|
|
406
424
|
|
|
407
425
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
408
426
|
var configurationResponse = arguments.length > 1 ? arguments[1] : undefined;
|
|
@@ -432,7 +450,7 @@ var Configuration = /*#__PURE__*/_createClass__default["default"](function Confi
|
|
|
432
450
|
emailBodiesAllowedContentTypes: configurationResponse.options.email_bodies_allowed_mime_types
|
|
433
451
|
};
|
|
434
452
|
this.typingIndicatorTimeoutOverride = constructorOptions.typingIndicatorTimeoutOverride;
|
|
435
|
-
this.backoffConfiguration = _objectSpread$
|
|
453
|
+
this.backoffConfiguration = _objectSpread$5({
|
|
436
454
|
min: MINIMUM_RETRY_DELAY,
|
|
437
455
|
max: MAXIMUM_RETRY_DELAY,
|
|
438
456
|
maxAttemptsCount: MAXIMUM_ATTEMPTS_COUNT
|
|
@@ -460,6 +478,9 @@ var Configuration = /*#__PURE__*/_createClass__default["default"](function Confi
|
|
|
460
478
|
logger.error("Failed to parse consumption report interval ".concat(consumptionReportInterval, ", using default value ").concat(CONSUMPTION_HORIZON_SENDING_INTERVAL));
|
|
461
479
|
this.consumptionReportInterval = iso8601Duration.toSeconds(iso8601Duration.parse(CONSUMPTION_HORIZON_SENDING_INTERVAL));
|
|
462
480
|
}
|
|
481
|
+
|
|
482
|
+
this.channelMetadataCacheCapacity = (_options$channelMetad = options.channelMetadataCacheCapacity) !== null && _options$channelMetad !== void 0 ? _options$channelMetad : CHANNEL_METADATA_CACHE_CAPACITY;
|
|
483
|
+
this.messageRecipientsCacheCapacity = (_options$messageRecip = options.messageRecipientsCacheCapacity) !== null && _options$messageRecip !== void 0 ? _options$messageRecip : MESSAGE_RECIPIENTS_CACHE_CAPACITY;
|
|
463
484
|
});
|
|
464
485
|
|
|
465
486
|
/**
|
|
@@ -551,17 +572,72 @@ var UriBuilder = /*#__PURE__*/function () {
|
|
|
551
572
|
|
|
552
573
|
return UriBuilder;
|
|
553
574
|
}();
|
|
575
|
+
/**
|
|
576
|
+
* Deep equality check for objects
|
|
577
|
+
* @param a - first value to compare
|
|
578
|
+
* @param b - second value to compare
|
|
579
|
+
* @returns true if values are deeply equal
|
|
580
|
+
*/
|
|
581
|
+
|
|
582
|
+
|
|
583
|
+
function isEqual(a, b) {
|
|
584
|
+
if (a === b) {
|
|
585
|
+
return true;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
if (a === null || b === null || a === undefined || b === undefined) {
|
|
589
|
+
return a === b;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
if (_typeof__default["default"](a) !== _typeof__default["default"](b)) {
|
|
593
|
+
return false;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
if (_typeof__default["default"](a) !== "object") {
|
|
597
|
+
return a === b;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
601
|
+
if (a.length !== b.length) {
|
|
602
|
+
return false;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
return a.every(function (item, index) {
|
|
606
|
+
return isEqual(item, b[index]);
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
if (Array.isArray(a) || Array.isArray(b)) {
|
|
611
|
+
return false;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
var aKeys = Object.keys(a);
|
|
615
|
+
var bKeys = Object.keys(b);
|
|
616
|
+
|
|
617
|
+
if (aKeys.length !== bKeys.length) {
|
|
618
|
+
return false;
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
return aKeys.every(function (key) {
|
|
622
|
+
return isEqual(a[key], b[key]);
|
|
623
|
+
});
|
|
624
|
+
}
|
|
554
625
|
|
|
555
|
-
var
|
|
626
|
+
var json = declarativeTypeValidator.custom(function (value) {
|
|
556
627
|
return [["string", "number", "boolean", "object"].includes(_typeof__default["default"](value)), "a JSON type"];
|
|
557
628
|
});
|
|
558
|
-
var
|
|
629
|
+
var optionalJson = declarativeTypeValidator.custom(function (value) {
|
|
559
630
|
return [["undefined", "string", "number", "boolean", "object"].includes(_typeof__default["default"](value)), "an optional JSON type"];
|
|
560
631
|
});
|
|
632
|
+
var sendMediaOptions = declarativeTypeValidator.objectSchema("send media options", {
|
|
633
|
+
contentType: [declarativeTypeValidator.literal(null), "string"],
|
|
634
|
+
filename: ["string", "undefined"],
|
|
635
|
+
media: [declarativeTypeValidator.literal("null"), "string"].concat(_toConsumableArray__default["default"](typeof Buffer === "function" ? [Buffer] : []), _toConsumableArray__default["default"](typeof Blob === "function" ? [Blob] : []))
|
|
636
|
+
});
|
|
561
637
|
|
|
562
|
-
function _createSuper$
|
|
638
|
+
function _createSuper$9(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$9(); return function _createSuperInternal() { var Super = _getPrototypeOf__default["default"](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default["default"](this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default["default"](this, result); }; }
|
|
563
639
|
|
|
564
|
-
function _isNativeReflectConstruct$
|
|
640
|
+
function _isNativeReflectConstruct$9() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
565
641
|
var log$6 = Logger.scope("User");
|
|
566
642
|
/**
|
|
567
643
|
* Extended user information.
|
|
@@ -573,7 +649,7 @@ var log$6 = Logger.scope("User");
|
|
|
573
649
|
var User = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
574
650
|
_inherits__default["default"](User, _ReplayEventEmitter);
|
|
575
651
|
|
|
576
|
-
var _super = _createSuper$
|
|
652
|
+
var _super = _createSuper$9(User);
|
|
577
653
|
|
|
578
654
|
/**
|
|
579
655
|
* @internal
|
|
@@ -626,6 +702,22 @@ var User = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
626
702
|
* @event
|
|
627
703
|
*/
|
|
628
704
|
|
|
705
|
+
/**
|
|
706
|
+
* Fired when the client has subscribed to the user.
|
|
707
|
+
*
|
|
708
|
+
* Parameters:
|
|
709
|
+
* 1. {@link User} `user` - the user in question
|
|
710
|
+
* @event
|
|
711
|
+
*/
|
|
712
|
+
|
|
713
|
+
/**
|
|
714
|
+
* Fired when the client has unsubscribed from the user.
|
|
715
|
+
*
|
|
716
|
+
* Parameters:
|
|
717
|
+
* 1. {@link User} `user` - the user in question
|
|
718
|
+
* @event
|
|
719
|
+
*/
|
|
720
|
+
|
|
629
721
|
|
|
630
722
|
_createClass__default["default"](User, [{
|
|
631
723
|
key: "identity",
|
|
@@ -720,7 +812,7 @@ var User = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
720
812
|
case 9:
|
|
721
813
|
updateAttributes = parseAttributes(value.value, "Retrieved malformed attributes from the server for user: ".concat(this.state.identity), log$6);
|
|
722
814
|
|
|
723
|
-
if (!
|
|
815
|
+
if (!isEqual(this.state.attributes, updateAttributes)) {
|
|
724
816
|
this.state.attributes = updateAttributes;
|
|
725
817
|
updateReasons.push("attributes");
|
|
726
818
|
}
|
|
@@ -839,6 +931,10 @@ var User = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
839
931
|
log$6.debug(_this3.state.entityName + " (" + _this3.state.identity + ") itemUpdated: " + args.item.key);
|
|
840
932
|
return _this3._update(args.item.key, args.item.data);
|
|
841
933
|
});
|
|
934
|
+
map.on("itemAdded", function (args) {
|
|
935
|
+
log$6.debug(_this3.state.entityName + " (" + _this3.state.identity + ") itemAdded: " + args.item.key);
|
|
936
|
+
return _this3._update(args.item.key, args.item.data);
|
|
937
|
+
});
|
|
842
938
|
return Promise.all([map.get("friendlyName").then(function (item) {
|
|
843
939
|
return _this3._update(item.key, item.data);
|
|
844
940
|
}), map.get("attributes").then(function (item) {
|
|
@@ -1047,7 +1143,7 @@ var User = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
1047
1143
|
this.identity = identity;
|
|
1048
1144
|
this.entityName = entityName;
|
|
1049
1145
|
this.links = {
|
|
1050
|
-
self: "".concat(this.configuration.links.users, "/").concat(this.identity)
|
|
1146
|
+
self: "".concat(this.configuration.links.users, "/").concat(encodeURIComponent(this.identity))
|
|
1051
1147
|
};
|
|
1052
1148
|
|
|
1053
1149
|
this._resolveInitializationPromise();
|
|
@@ -1064,15 +1160,15 @@ var User = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
1064
1160
|
return User;
|
|
1065
1161
|
}(replayEventEmitter.ReplayEventEmitter);
|
|
1066
1162
|
|
|
1067
|
-
__decorate([declarativeTypeValidator.validateTypesAsync(
|
|
1163
|
+
__decorate([declarativeTypeValidator.validateTypesAsync(json), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise)], User.prototype, "updateAttributes", null);
|
|
1068
1164
|
|
|
1069
1165
|
__decorate([declarativeTypeValidator.validateTypesAsync(["string"]), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", Promise)], User.prototype, "updateFriendlyName", null);
|
|
1070
1166
|
|
|
1071
|
-
function _createForOfIteratorHelper$
|
|
1167
|
+
function _createForOfIteratorHelper$5(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$5(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
1072
1168
|
|
|
1073
|
-
function _unsupportedIterableToArray$
|
|
1169
|
+
function _unsupportedIterableToArray$5(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$5(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$5(o, minLen); }
|
|
1074
1170
|
|
|
1075
|
-
function _arrayLikeToArray$
|
|
1171
|
+
function _arrayLikeToArray$5(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
1076
1172
|
|
|
1077
1173
|
var Network = /*#__PURE__*/function () {
|
|
1078
1174
|
function Network(configuration, services) {
|
|
@@ -1093,7 +1189,7 @@ var Network = /*#__PURE__*/function () {
|
|
|
1093
1189
|
}, {
|
|
1094
1190
|
key: "cleanupCache",
|
|
1095
1191
|
value: function cleanupCache() {
|
|
1096
|
-
var _iterator = _createForOfIteratorHelper$
|
|
1192
|
+
var _iterator = _createForOfIteratorHelper$5(this.cache),
|
|
1097
1193
|
_step;
|
|
1098
1194
|
|
|
1099
1195
|
try {
|
|
@@ -1237,9 +1333,9 @@ _defineProperty__default["default"](NotificationTypes, "REMOVED_FROM_CONVERSATIO
|
|
|
1237
1333
|
|
|
1238
1334
|
_defineProperty__default["default"](NotificationTypes, "CONSUMPTION_UPDATE", "twilio.channel.consumption_update");
|
|
1239
1335
|
|
|
1240
|
-
function _createSuper$
|
|
1336
|
+
function _createSuper$8(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$8(); return function _createSuperInternal() { var Super = _getPrototypeOf__default["default"](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default["default"](this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default["default"](this, result); }; }
|
|
1241
1337
|
|
|
1242
|
-
function _isNativeReflectConstruct$
|
|
1338
|
+
function _isNativeReflectConstruct$8() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
1243
1339
|
var log$5 = Logger.scope("Participant");
|
|
1244
1340
|
/**
|
|
1245
1341
|
* A participant represents a remote client in a conversation.
|
|
@@ -1248,7 +1344,7 @@ var log$5 = Logger.scope("Participant");
|
|
|
1248
1344
|
var Participant = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
1249
1345
|
_inherits__default["default"](Participant, _ReplayEventEmitter);
|
|
1250
1346
|
|
|
1251
|
-
var _super = _createSuper$
|
|
1347
|
+
var _super = _createSuper$8(Participant);
|
|
1252
1348
|
|
|
1253
1349
|
/**
|
|
1254
1350
|
* @internal
|
|
@@ -1294,6 +1390,24 @@ var Participant = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
1294
1390
|
* @event
|
|
1295
1391
|
*/
|
|
1296
1392
|
|
|
1393
|
+
/**
|
|
1394
|
+
* Fired when the participant has stopped typing.
|
|
1395
|
+
*
|
|
1396
|
+
* Parameters:
|
|
1397
|
+
* 1. {@link Participant} `participant` - the participant in question
|
|
1398
|
+
* @event
|
|
1399
|
+
*/
|
|
1400
|
+
|
|
1401
|
+
/**
|
|
1402
|
+
* Fired when the fields of the participant have been updated.
|
|
1403
|
+
*
|
|
1404
|
+
* Parameters:
|
|
1405
|
+
* 1. object `data` - info object provided with the event. It has the following properties:
|
|
1406
|
+
* * {@link Participant} participant - the participant in question
|
|
1407
|
+
* * {@link ParticipantUpdateReason}[] updateReasons - array of reasons for the update
|
|
1408
|
+
* @event
|
|
1409
|
+
*/
|
|
1410
|
+
|
|
1297
1411
|
|
|
1298
1412
|
_createClass__default["default"](Participant, [{
|
|
1299
1413
|
key: "sid",
|
|
@@ -1420,8 +1534,9 @@ var Participant = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
1420
1534
|
}
|
|
1421
1535
|
|
|
1422
1536
|
this.state.isTyping = true;
|
|
1423
|
-
this.emit(
|
|
1424
|
-
this.conversation.emit(
|
|
1537
|
+
this.emit(Participant.typingStarted, this);
|
|
1538
|
+
this.conversation.emit(Conversation.typingStarted, this); // @fixme layering violation
|
|
1539
|
+
|
|
1425
1540
|
this.state.typingTimeout = Number(setTimeout(function () {
|
|
1426
1541
|
return _this2._endTyping();
|
|
1427
1542
|
}, timeout));
|
|
@@ -1440,8 +1555,8 @@ var Participant = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
1440
1555
|
}
|
|
1441
1556
|
|
|
1442
1557
|
this.state.isTyping = false;
|
|
1443
|
-
this.emit(
|
|
1444
|
-
this.conversation.emit(
|
|
1558
|
+
this.emit(Participant.typingEnded, this);
|
|
1559
|
+
this.conversation.emit(Conversation.typingEnded, this);
|
|
1445
1560
|
clearInterval(this.state.typingTimeout);
|
|
1446
1561
|
this.state.typingTimeout = null;
|
|
1447
1562
|
}
|
|
@@ -1456,7 +1571,7 @@ var Participant = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
1456
1571
|
var updateReasons = [];
|
|
1457
1572
|
var updateAttributes = parseAttributes(data.attributes, "Retrieved malformed attributes from the server for participant: " + this.state.sid, log$5);
|
|
1458
1573
|
|
|
1459
|
-
if (data.attributes && !
|
|
1574
|
+
if (data.attributes && !isEqual(this.state.attributes, updateAttributes)) {
|
|
1460
1575
|
this.state.attributes = updateAttributes;
|
|
1461
1576
|
updateReasons.push("attributes");
|
|
1462
1577
|
}
|
|
@@ -1494,13 +1609,13 @@ var Participant = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
1494
1609
|
}
|
|
1495
1610
|
}
|
|
1496
1611
|
|
|
1497
|
-
if (data.bindings && !
|
|
1612
|
+
if (data.bindings && !isEqual(this.state.bindings, data.bindings)) {
|
|
1498
1613
|
this.state.bindings = data.bindings;
|
|
1499
1614
|
updateReasons.push("bindings");
|
|
1500
1615
|
}
|
|
1501
1616
|
|
|
1502
1617
|
if (updateReasons.length > 0) {
|
|
1503
|
-
this.emit(
|
|
1618
|
+
this.emit(Participant.updated, {
|
|
1504
1619
|
participant: this,
|
|
1505
1620
|
updateReasons: updateReasons
|
|
1506
1621
|
});
|
|
@@ -1618,11 +1733,11 @@ _defineProperty__default["default"](Participant, "typingEnded", "typingEnded");
|
|
|
1618
1733
|
|
|
1619
1734
|
_defineProperty__default["default"](Participant, "updated", "updated");
|
|
1620
1735
|
|
|
1621
|
-
__decorate([declarativeTypeValidator.validateTypesAsync(
|
|
1736
|
+
__decorate([declarativeTypeValidator.validateTypesAsync(json), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise)], Participant.prototype, "updateAttributes", null);
|
|
1622
1737
|
|
|
1623
|
-
function _createSuper$
|
|
1738
|
+
function _createSuper$7(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$7(); return function _createSuperInternal() { var Super = _getPrototypeOf__default["default"](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default["default"](this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default["default"](this, result); }; }
|
|
1624
1739
|
|
|
1625
|
-
function _isNativeReflectConstruct$
|
|
1740
|
+
function _isNativeReflectConstruct$7() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
1626
1741
|
var log$4 = Logger.scope("Participants");
|
|
1627
1742
|
/**
|
|
1628
1743
|
* @classdesc Represents the collection of participants for the conversation
|
|
@@ -1634,9 +1749,10 @@ var log$4 = Logger.scope("Participants");
|
|
|
1634
1749
|
var Participants = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
1635
1750
|
_inherits__default["default"](Participants, _ReplayEventEmitter);
|
|
1636
1751
|
|
|
1637
|
-
var _super = _createSuper$
|
|
1752
|
+
var _super = _createSuper$7(Participants);
|
|
1638
1753
|
|
|
1639
|
-
|
|
1754
|
+
// passed in from Conversation
|
|
1755
|
+
function Participants(conversation, participants, links, services) {
|
|
1640
1756
|
var _this;
|
|
1641
1757
|
|
|
1642
1758
|
_classCallCheck__default["default"](this, Participants);
|
|
@@ -1648,7 +1764,6 @@ var Participants = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
1648
1764
|
_this.conversation = conversation;
|
|
1649
1765
|
_this.participants = participants;
|
|
1650
1766
|
_this.links = links;
|
|
1651
|
-
_this.configuration = configuration;
|
|
1652
1767
|
_this.services = services;
|
|
1653
1768
|
return _this;
|
|
1654
1769
|
}
|
|
@@ -1691,21 +1806,22 @@ var Participants = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
1691
1806
|
}()
|
|
1692
1807
|
}, {
|
|
1693
1808
|
key: "subscribe",
|
|
1694
|
-
value: function subscribe(
|
|
1809
|
+
value: function subscribe(arg) {
|
|
1695
1810
|
var _this2 = this;
|
|
1696
1811
|
|
|
1697
|
-
|
|
1698
|
-
id:
|
|
1812
|
+
var participantsMapPromise = typeof arg === "string" ? this.services.syncClient.map({
|
|
1813
|
+
id: arg,
|
|
1699
1814
|
mode: "open_existing"
|
|
1700
|
-
}).
|
|
1701
|
-
|
|
1815
|
+
}) : Promise.resolve(arg);
|
|
1816
|
+
return this.rosterEntityPromise = this.rosterEntityPromise || participantsMapPromise.then(function (rosterMap) {
|
|
1817
|
+
rosterMap.on(twilioSync.SyncMap.itemAdded, function (args) {
|
|
1702
1818
|
log$4.debug(_this2.conversation.sid + " itemAdded: " + args.item.key);
|
|
1703
1819
|
|
|
1704
1820
|
_this2.upsertParticipant(args.item.key, args.item.data).then(function (participant) {
|
|
1705
|
-
_this2.emit(
|
|
1821
|
+
_this2.emit(Conversation.participantJoined, participant);
|
|
1706
1822
|
});
|
|
1707
1823
|
});
|
|
1708
|
-
rosterMap.on(
|
|
1824
|
+
rosterMap.on(twilioSync.SyncMap.itemRemoved, function (args) {
|
|
1709
1825
|
log$4.debug(_this2.conversation.sid + " itemRemoved: " + args.key);
|
|
1710
1826
|
var participantSid = args.key;
|
|
1711
1827
|
|
|
@@ -1721,12 +1837,14 @@ var Participants = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
1721
1837
|
return;
|
|
1722
1838
|
}
|
|
1723
1839
|
|
|
1724
|
-
_this2.emit(
|
|
1840
|
+
_this2.emit(Conversation.participantLeft, leftParticipant);
|
|
1725
1841
|
});
|
|
1726
|
-
rosterMap.on(
|
|
1842
|
+
rosterMap.on(twilioSync.SyncMap.itemUpdated, function (args) {
|
|
1727
1843
|
log$4.debug(_this2.conversation.sid + " itemUpdated: " + args.item.key);
|
|
1728
1844
|
|
|
1729
|
-
_this2.upsertParticipant(args.item.key, args.item.data)
|
|
1845
|
+
_this2.upsertParticipant(args.item.key, args.item.data).catch(function (e) {
|
|
1846
|
+
return log$4.error(e);
|
|
1847
|
+
});
|
|
1730
1848
|
});
|
|
1731
1849
|
var participantsPromises = [];
|
|
1732
1850
|
|
|
@@ -1820,8 +1938,8 @@ var Participants = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
1820
1938
|
};
|
|
1821
1939
|
participant = new Participant(data, participantSid, this.conversation, links, this.services);
|
|
1822
1940
|
this.participants.set(participantSid, participant);
|
|
1823
|
-
participant.on(
|
|
1824
|
-
return _this3.emit(
|
|
1941
|
+
participant.on(Participant.updated, function (args) {
|
|
1942
|
+
return _this3.emit(Conversation.participantUpdated, args);
|
|
1825
1943
|
});
|
|
1826
1944
|
return _context3.abrupt("return", participant);
|
|
1827
1945
|
|
|
@@ -1969,7 +2087,6 @@ var Participants = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
1969
2087
|
key: "add",
|
|
1970
2088
|
value: function () {
|
|
1971
2089
|
var _add = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee7(identity, attributes) {
|
|
1972
|
-
var participantResponse;
|
|
1973
2090
|
return _regeneratorRuntime__default["default"].wrap(function _callee7$(_context7) {
|
|
1974
2091
|
while (1) {
|
|
1975
2092
|
switch (_context7.prev = _context7.next) {
|
|
@@ -1981,14 +2098,9 @@ var Participants = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
1981
2098
|
});
|
|
1982
2099
|
|
|
1983
2100
|
case 2:
|
|
1984
|
-
participantResponse = _context7.sent;
|
|
1985
|
-
_context7.next = 5;
|
|
1986
|
-
return this.upsertParticipantFromResponse(participantResponse);
|
|
1987
|
-
|
|
1988
|
-
case 5:
|
|
1989
2101
|
return _context7.abrupt("return", _context7.sent);
|
|
1990
2102
|
|
|
1991
|
-
case
|
|
2103
|
+
case 3:
|
|
1992
2104
|
case "end":
|
|
1993
2105
|
return _context7.stop();
|
|
1994
2106
|
}
|
|
@@ -2014,7 +2126,6 @@ var Participants = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
2014
2126
|
|
|
2015
2127
|
var attributes,
|
|
2016
2128
|
bindingOptions,
|
|
2017
|
-
participantResponse,
|
|
2018
2129
|
_args8 = arguments;
|
|
2019
2130
|
return _regeneratorRuntime__default["default"].wrap(function _callee8$(_context8) {
|
|
2020
2131
|
while (1) {
|
|
@@ -2034,14 +2145,9 @@ var Participants = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
2034
2145
|
});
|
|
2035
2146
|
|
|
2036
2147
|
case 4:
|
|
2037
|
-
participantResponse = _context8.sent;
|
|
2038
|
-
_context8.next = 7;
|
|
2039
|
-
return this.upsertParticipantFromResponse(participantResponse);
|
|
2040
|
-
|
|
2041
|
-
case 7:
|
|
2042
2148
|
return _context8.abrupt("return", _context8.sent);
|
|
2043
2149
|
|
|
2044
|
-
case
|
|
2150
|
+
case 5:
|
|
2045
2151
|
case "end":
|
|
2046
2152
|
return _context8.stop();
|
|
2047
2153
|
}
|
|
@@ -2062,7 +2168,7 @@ var Participants = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
2062
2168
|
}, {
|
|
2063
2169
|
key: "remove",
|
|
2064
2170
|
value: function remove(identity) {
|
|
2065
|
-
return this.services.commandExecutor.mutateResource("delete", "".concat(this.links.participants, "/").concat(identity));
|
|
2171
|
+
return this.services.commandExecutor.mutateResource("delete", "".concat(this.links.participants, "/").concat(encodeURIComponent(identity)));
|
|
2066
2172
|
}
|
|
2067
2173
|
}]);
|
|
2068
2174
|
|
|
@@ -2097,6 +2203,8 @@ var Media = /*#__PURE__*/function () {
|
|
|
2097
2203
|
* @internal
|
|
2098
2204
|
*/
|
|
2099
2205
|
function Media(data, services) {
|
|
2206
|
+
var _data$filename;
|
|
2207
|
+
|
|
2100
2208
|
_classCallCheck__default["default"](this, Media);
|
|
2101
2209
|
|
|
2102
2210
|
_defineProperty__default["default"](this, "mcsMedia", null);
|
|
@@ -2110,7 +2218,7 @@ var Media = /*#__PURE__*/function () {
|
|
|
2110
2218
|
this.state = {
|
|
2111
2219
|
sid: data.sid,
|
|
2112
2220
|
category: data.category,
|
|
2113
|
-
filename: data.filename,
|
|
2221
|
+
filename: (_data$filename = data.filename) !== null && _data$filename !== void 0 ? _data$filename : null,
|
|
2114
2222
|
contentType: data.contentType,
|
|
2115
2223
|
size: data.size
|
|
2116
2224
|
};
|
|
@@ -2183,10 +2291,12 @@ var Media = /*#__PURE__*/function () {
|
|
|
2183
2291
|
while (1) {
|
|
2184
2292
|
switch (_context.prev = _context.next) {
|
|
2185
2293
|
case 0:
|
|
2186
|
-
fetchMediaRequest = _this._fetchMcsMedia();
|
|
2294
|
+
fetchMediaRequest = _this.mcsMedia ? undefined : _this._fetchMcsMedia();
|
|
2187
2295
|
contentUrlRequest = (_this$mcsMedia = _this.mcsMedia) === null || _this$mcsMedia === void 0 ? void 0 : _this$mcsMedia.getContentUrl();
|
|
2188
2296
|
onCancel(function () {
|
|
2189
|
-
fetchMediaRequest
|
|
2297
|
+
if (fetchMediaRequest) {
|
|
2298
|
+
fetchMediaRequest.cancel();
|
|
2299
|
+
}
|
|
2190
2300
|
|
|
2191
2301
|
if (contentUrlRequest) {
|
|
2192
2302
|
contentUrlRequest.cancel();
|
|
@@ -2194,7 +2304,7 @@ var Media = /*#__PURE__*/function () {
|
|
|
2194
2304
|
});
|
|
2195
2305
|
_context.prev = 3;
|
|
2196
2306
|
|
|
2197
|
-
if (
|
|
2307
|
+
if (contentUrlRequest) {
|
|
2198
2308
|
_context.next = 9;
|
|
2199
2309
|
break;
|
|
2200
2310
|
}
|
|
@@ -2204,7 +2314,7 @@ var Media = /*#__PURE__*/function () {
|
|
|
2204
2314
|
|
|
2205
2315
|
case 7:
|
|
2206
2316
|
mcsMedia = _context.sent;
|
|
2207
|
-
contentUrlRequest = mcsMedia.getContentUrl();
|
|
2317
|
+
contentUrlRequest = mcsMedia === null || mcsMedia === void 0 ? void 0 : mcsMedia.getContentUrl();
|
|
2208
2318
|
|
|
2209
2319
|
case 9:
|
|
2210
2320
|
_context.t0 = resolve;
|
|
@@ -2261,13 +2371,11 @@ var Media = /*#__PURE__*/function () {
|
|
|
2261
2371
|
while (1) {
|
|
2262
2372
|
switch (_context2.prev = _context2.next) {
|
|
2263
2373
|
case 0:
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
if (!_this2.services.mcsClient) {
|
|
2267
|
-
_context2.next = 14;
|
|
2268
|
-
break;
|
|
2374
|
+
if (_this2.services.mcsClient === null) {
|
|
2375
|
+
reject(new Error("Media Content Service is unavailable"));
|
|
2269
2376
|
}
|
|
2270
2377
|
|
|
2378
|
+
request = _this2.services.mcsClient.get(_this2.state.sid);
|
|
2271
2379
|
onCancel(function () {
|
|
2272
2380
|
return request.cancel();
|
|
2273
2381
|
});
|
|
@@ -2277,27 +2385,22 @@ var Media = /*#__PURE__*/function () {
|
|
|
2277
2385
|
|
|
2278
2386
|
case 6:
|
|
2279
2387
|
_this2.mcsMedia = _context2.sent;
|
|
2388
|
+
_this2.state = _this2.mcsMedia._state();
|
|
2280
2389
|
resolve(_this2.mcsMedia);
|
|
2281
|
-
_context2.next =
|
|
2390
|
+
_context2.next = 14;
|
|
2282
2391
|
break;
|
|
2283
2392
|
|
|
2284
|
-
case
|
|
2285
|
-
_context2.prev =
|
|
2393
|
+
case 11:
|
|
2394
|
+
_context2.prev = 11;
|
|
2286
2395
|
_context2.t0 = _context2["catch"](3);
|
|
2287
2396
|
reject(_context2.t0);
|
|
2288
2397
|
|
|
2289
|
-
case 13:
|
|
2290
|
-
return _context2.abrupt("return");
|
|
2291
|
-
|
|
2292
2398
|
case 14:
|
|
2293
|
-
reject(new Error("Media Content Service is unavailable"));
|
|
2294
|
-
|
|
2295
|
-
case 15:
|
|
2296
2399
|
case "end":
|
|
2297
2400
|
return _context2.stop();
|
|
2298
2401
|
}
|
|
2299
2402
|
}
|
|
2300
|
-
}, _callee2, null, [[3,
|
|
2403
|
+
}, _callee2, null, [[3, 11]]);
|
|
2301
2404
|
}));
|
|
2302
2405
|
|
|
2303
2406
|
return function (_x4, _x5, _x6) {
|
|
@@ -2305,6 +2408,15 @@ var Media = /*#__PURE__*/function () {
|
|
|
2305
2408
|
};
|
|
2306
2409
|
}());
|
|
2307
2410
|
}
|
|
2411
|
+
/**
|
|
2412
|
+
* @internal
|
|
2413
|
+
*/
|
|
2414
|
+
|
|
2415
|
+
}, {
|
|
2416
|
+
key: "_state",
|
|
2417
|
+
value: function _state() {
|
|
2418
|
+
return this.state;
|
|
2419
|
+
}
|
|
2308
2420
|
}]);
|
|
2309
2421
|
|
|
2310
2422
|
return Media;
|
|
@@ -2314,7 +2426,7 @@ var Media = /*#__PURE__*/function () {
|
|
|
2314
2426
|
* Contains aggregated information about delivery statuses of a message across all participants
|
|
2315
2427
|
* of a conversation.
|
|
2316
2428
|
*
|
|
2317
|
-
* At any moment during the message delivery to a participant, the message can have zero or more of following
|
|
2429
|
+
* At any moment during the message delivery to a participant, the message can have zero or more of the following
|
|
2318
2430
|
* delivery statuses:
|
|
2319
2431
|
* * Message is considered as **sent** to a participant if the nearest upstream carrier accepted the message.
|
|
2320
2432
|
* * Message is considered as **delivered** to a participant if Twilio has received confirmation of message
|
|
@@ -2557,22 +2669,274 @@ function DetailedDeliveryReceipt(descriptor) {
|
|
|
2557
2669
|
this.dateUpdated = descriptor.date_updated;
|
|
2558
2670
|
});
|
|
2559
2671
|
|
|
2560
|
-
|
|
2672
|
+
var collectActions = function collectActions(actions) {
|
|
2673
|
+
return actions.map(function (action) {
|
|
2674
|
+
var _action$id, _action$index, _action$phone, _action$url;
|
|
2561
2675
|
|
|
2562
|
-
|
|
2676
|
+
var rawData = JSON.stringify(action);
|
|
2563
2677
|
|
|
2564
|
-
|
|
2678
|
+
switch (action.type) {
|
|
2679
|
+
case "QUICK_REPLY":
|
|
2680
|
+
return {
|
|
2681
|
+
type: "reply",
|
|
2682
|
+
title: action.title,
|
|
2683
|
+
id: (_action$id = action.id) !== null && _action$id !== void 0 ? _action$id : "",
|
|
2684
|
+
index: (_action$index = action.index) !== null && _action$index !== void 0 ? _action$index : 0,
|
|
2685
|
+
rawData: rawData
|
|
2686
|
+
};
|
|
2565
2687
|
|
|
2566
|
-
|
|
2688
|
+
case "PHONE_NUMBER":
|
|
2689
|
+
return {
|
|
2690
|
+
type: "phone",
|
|
2691
|
+
title: action.title,
|
|
2692
|
+
phone: (_action$phone = action.phone) !== null && _action$phone !== void 0 ? _action$phone : "",
|
|
2693
|
+
rawData: rawData
|
|
2694
|
+
};
|
|
2695
|
+
|
|
2696
|
+
case "URL":
|
|
2697
|
+
return {
|
|
2698
|
+
type: "url",
|
|
2699
|
+
title: action.title,
|
|
2700
|
+
url: (_action$url = action.url) !== null && _action$url !== void 0 ? _action$url : "",
|
|
2701
|
+
rawData: rawData
|
|
2702
|
+
};
|
|
2703
|
+
|
|
2704
|
+
default:
|
|
2705
|
+
return {
|
|
2706
|
+
type: "other",
|
|
2707
|
+
rawData: rawData
|
|
2708
|
+
};
|
|
2709
|
+
}
|
|
2710
|
+
});
|
|
2711
|
+
};
|
|
2712
|
+
|
|
2713
|
+
var parseVariant = function parseVariant(type, data) {
|
|
2714
|
+
var rawData = JSON.stringify(data);
|
|
2715
|
+
|
|
2716
|
+
switch (type) {
|
|
2717
|
+
case "twilio/text":
|
|
2718
|
+
{
|
|
2719
|
+
var variant = data;
|
|
2720
|
+
return {
|
|
2721
|
+
type: "text",
|
|
2722
|
+
body: variant.body,
|
|
2723
|
+
rawData: rawData
|
|
2724
|
+
};
|
|
2725
|
+
}
|
|
2726
|
+
|
|
2727
|
+
case "twilio/media":
|
|
2728
|
+
{
|
|
2729
|
+
var _variant = data;
|
|
2730
|
+
return {
|
|
2731
|
+
type: "media",
|
|
2732
|
+
body: _variant.body,
|
|
2733
|
+
media: _variant.media,
|
|
2734
|
+
rawData: rawData
|
|
2735
|
+
};
|
|
2736
|
+
}
|
|
2737
|
+
|
|
2738
|
+
case "twilio/location":
|
|
2739
|
+
{
|
|
2740
|
+
var _variant2 = data;
|
|
2741
|
+
return {
|
|
2742
|
+
type: "location",
|
|
2743
|
+
longitude: _variant2.longitude,
|
|
2744
|
+
latitude: _variant2.latitude,
|
|
2745
|
+
label: _variant2.label,
|
|
2746
|
+
rawData: rawData
|
|
2747
|
+
};
|
|
2748
|
+
}
|
|
2749
|
+
|
|
2750
|
+
case "twilio/quick-reply":
|
|
2751
|
+
{
|
|
2752
|
+
var _variant3 = data;
|
|
2753
|
+
return {
|
|
2754
|
+
type: "quickReply",
|
|
2755
|
+
body: _variant3.body,
|
|
2756
|
+
replies: _variant3.actions,
|
|
2757
|
+
rawData: rawData
|
|
2758
|
+
};
|
|
2759
|
+
}
|
|
2760
|
+
|
|
2761
|
+
case "twilio/call-to-action":
|
|
2762
|
+
{
|
|
2763
|
+
var _variant4 = data;
|
|
2764
|
+
return {
|
|
2765
|
+
type: "callToAction",
|
|
2766
|
+
body: _variant4.body,
|
|
2767
|
+
actions: collectActions(_variant4.actions),
|
|
2768
|
+
rawData: rawData
|
|
2769
|
+
};
|
|
2770
|
+
}
|
|
2771
|
+
|
|
2772
|
+
case "twilio/list-picker":
|
|
2773
|
+
{
|
|
2774
|
+
var _variant5 = data;
|
|
2775
|
+
return {
|
|
2776
|
+
type: "listPicker",
|
|
2777
|
+
body: _variant5.body,
|
|
2778
|
+
button: _variant5.button,
|
|
2779
|
+
items: _variant5.items,
|
|
2780
|
+
rawData: rawData
|
|
2781
|
+
};
|
|
2782
|
+
}
|
|
2783
|
+
|
|
2784
|
+
case "twilio/card":
|
|
2785
|
+
{
|
|
2786
|
+
var _variant6$media, _variant6$actions;
|
|
2787
|
+
|
|
2788
|
+
var _variant6 = data;
|
|
2789
|
+
return {
|
|
2790
|
+
type: "card",
|
|
2791
|
+
title: _variant6.title,
|
|
2792
|
+
subtitle: _variant6.subtitle,
|
|
2793
|
+
media: (_variant6$media = _variant6.media) !== null && _variant6$media !== void 0 ? _variant6$media : [],
|
|
2794
|
+
actions: collectActions((_variant6$actions = _variant6.actions) !== null && _variant6$actions !== void 0 ? _variant6$actions : []),
|
|
2795
|
+
rawData: rawData
|
|
2796
|
+
};
|
|
2797
|
+
}
|
|
2798
|
+
|
|
2799
|
+
default:
|
|
2800
|
+
return {
|
|
2801
|
+
type: "other",
|
|
2802
|
+
rawData: rawData
|
|
2803
|
+
};
|
|
2804
|
+
}
|
|
2805
|
+
};
|
|
2806
|
+
|
|
2807
|
+
var collectVariants = function collectVariants(variants) {
|
|
2808
|
+
var variantsMap = new Map();
|
|
2809
|
+
|
|
2810
|
+
for (var _i = 0, _Object$entries = Object.entries(variants); _i < _Object$entries.length; _i++) {
|
|
2811
|
+
var _Object$entries$_i = _slicedToArray__default["default"](_Object$entries[_i], 2),
|
|
2812
|
+
key = _Object$entries$_i[0],
|
|
2813
|
+
value = _Object$entries$_i[1];
|
|
2814
|
+
|
|
2815
|
+
variantsMap.set(key, parseVariant(key, value));
|
|
2816
|
+
}
|
|
2817
|
+
|
|
2818
|
+
return variantsMap;
|
|
2819
|
+
};
|
|
2820
|
+
/**
|
|
2821
|
+
* Represents a variable for a content template. See
|
|
2822
|
+
* {@link ContentTemplate.variables}.
|
|
2823
|
+
*/
|
|
2824
|
+
|
|
2825
|
+
|
|
2826
|
+
var ContentTemplateVariable = /*#__PURE__*/function () {
|
|
2827
|
+
function ContentTemplateVariable(
|
|
2828
|
+
/**
|
|
2829
|
+
* Name of the variable.
|
|
2830
|
+
*/
|
|
2831
|
+
name,
|
|
2832
|
+
/**
|
|
2833
|
+
* Key of the variable
|
|
2834
|
+
*/
|
|
2835
|
+
value) {
|
|
2836
|
+
_classCallCheck__default["default"](this, ContentTemplateVariable);
|
|
2837
|
+
|
|
2838
|
+
this.name = name;
|
|
2839
|
+
this.value = value;
|
|
2840
|
+
}
|
|
2841
|
+
/**
|
|
2842
|
+
* Copies the variable with a new value.
|
|
2843
|
+
*
|
|
2844
|
+
* @param value The new value for the variable.
|
|
2845
|
+
*/
|
|
2846
|
+
|
|
2847
|
+
|
|
2848
|
+
_createClass__default["default"](ContentTemplateVariable, [{
|
|
2849
|
+
key: "copyWithValue",
|
|
2850
|
+
value: function copyWithValue(value) {
|
|
2851
|
+
return new ContentTemplateVariable(this.name, value);
|
|
2852
|
+
}
|
|
2853
|
+
}]);
|
|
2854
|
+
|
|
2855
|
+
return ContentTemplateVariable;
|
|
2856
|
+
}();
|
|
2857
|
+
/**
|
|
2858
|
+
* A rich content template.
|
|
2859
|
+
*
|
|
2860
|
+
* Use {@Link Client.getContentTemplates} to request all the templates available
|
|
2861
|
+
* for the current account.
|
|
2862
|
+
*/
|
|
2863
|
+
|
|
2864
|
+
|
|
2865
|
+
var ContentTemplate = /*#__PURE__*/_createClass__default["default"](
|
|
2866
|
+
/**
|
|
2867
|
+
* The server-assigned unique identifier for the template.
|
|
2868
|
+
*/
|
|
2869
|
+
|
|
2870
|
+
/**
|
|
2871
|
+
* Friendly name used to describe the content. Not visible to the recipient.
|
|
2872
|
+
*/
|
|
2873
|
+
|
|
2874
|
+
/**
|
|
2875
|
+
* Variables used by this template.
|
|
2876
|
+
*/
|
|
2877
|
+
|
|
2878
|
+
/**
|
|
2879
|
+
* Variants of the content. See {@link ContentData}.
|
|
2880
|
+
*/
|
|
2881
|
+
|
|
2882
|
+
/**
|
|
2883
|
+
* Date of creation.
|
|
2884
|
+
*/
|
|
2885
|
+
|
|
2886
|
+
/**
|
|
2887
|
+
* Date of the last update.
|
|
2888
|
+
*/
|
|
2889
|
+
|
|
2890
|
+
/**
|
|
2891
|
+
* @internal
|
|
2892
|
+
*/
|
|
2893
|
+
function ContentTemplate(contentTemplateResponse) {
|
|
2894
|
+
_classCallCheck__default["default"](this, ContentTemplate);
|
|
2895
|
+
|
|
2896
|
+
this.sid = contentTemplateResponse.sid;
|
|
2897
|
+
this.friendlyName = contentTemplateResponse.friendly_name;
|
|
2898
|
+
this.variables = Object.entries(JSON.parse(contentTemplateResponse.variables)).map(function (_ref) {
|
|
2899
|
+
var _ref2 = _slicedToArray__default["default"](_ref, 2),
|
|
2900
|
+
key = _ref2[0],
|
|
2901
|
+
value = _ref2[1];
|
|
2902
|
+
|
|
2903
|
+
return new ContentTemplateVariable(key, value);
|
|
2904
|
+
});
|
|
2905
|
+
this.variants = collectVariants(contentTemplateResponse.variants);
|
|
2906
|
+
this.dateCreated = new Date(contentTemplateResponse.date_created);
|
|
2907
|
+
this.dateUpdated = new Date(contentTemplateResponse.date_updated);
|
|
2908
|
+
});
|
|
2909
|
+
|
|
2910
|
+
function ownKeys$4(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2911
|
+
|
|
2912
|
+
function _objectSpread$4(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$4(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$4(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
2913
|
+
|
|
2914
|
+
function _createSuper$6(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$6(); return function _createSuperInternal() { var Super = _getPrototypeOf__default["default"](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default["default"](this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default["default"](this, result); }; }
|
|
2915
|
+
|
|
2916
|
+
function _isNativeReflectConstruct$6() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
2917
|
+
|
|
2918
|
+
function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
|
|
2919
|
+
|
|
2920
|
+
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
|
|
2921
|
+
|
|
2922
|
+
function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
|
|
2567
2923
|
var log$3 = Logger.scope("Message");
|
|
2924
|
+
|
|
2925
|
+
var XHR = // eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
2926
|
+
global["XMLHttpRequest"] || require("xmlhttprequest").XMLHttpRequest;
|
|
2568
2927
|
/**
|
|
2569
2928
|
* A message in a conversation.
|
|
2570
2929
|
*/
|
|
2571
2930
|
|
|
2931
|
+
|
|
2932
|
+
var _wrapMedia = /*#__PURE__*/new WeakSet();
|
|
2933
|
+
|
|
2934
|
+
var _assignMedias = /*#__PURE__*/new WeakSet();
|
|
2935
|
+
|
|
2572
2936
|
var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
2573
2937
|
_inherits__default["default"](Message, _ReplayEventEmitter);
|
|
2574
2938
|
|
|
2575
|
-
var _super = _createSuper$
|
|
2939
|
+
var _super = _createSuper$6(Message);
|
|
2576
2940
|
|
|
2577
2941
|
/**
|
|
2578
2942
|
* Conversation that the message is in.
|
|
@@ -2582,13 +2946,18 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
2582
2946
|
* @internal
|
|
2583
2947
|
*/
|
|
2584
2948
|
function Message(index, data, conversation, links, configuration, services) {
|
|
2585
|
-
var _data$text, _data$lastUpdatedBy, _data$type, _data$memberSid;
|
|
2949
|
+
var _data$text, _data$lastUpdatedBy, _data$type, _data$memberSid, _data$channelMetadata, _data$medias, _data$media;
|
|
2586
2950
|
|
|
2587
2951
|
var _this;
|
|
2588
2952
|
|
|
2589
2953
|
_classCallCheck__default["default"](this, Message);
|
|
2590
2954
|
|
|
2591
2955
|
_this = _super.call(this);
|
|
2956
|
+
|
|
2957
|
+
_classPrivateMethodInitSpec(_assertThisInitialized__default["default"](_this), _assignMedias);
|
|
2958
|
+
|
|
2959
|
+
_classPrivateMethodInitSpec(_assertThisInitialized__default["default"](_this), _wrapMedia);
|
|
2960
|
+
|
|
2592
2961
|
_this.conversation = conversation;
|
|
2593
2962
|
_this.links = links;
|
|
2594
2963
|
_this.configuration = configuration;
|
|
@@ -2598,21 +2967,22 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
2598
2967
|
index: index,
|
|
2599
2968
|
author: data.author,
|
|
2600
2969
|
subject: data.subject,
|
|
2970
|
+
contentSid: data.contentSid,
|
|
2601
2971
|
body: (_data$text = data.text) !== null && _data$text !== void 0 ? _data$text : null,
|
|
2602
2972
|
timestamp: data.timestamp ? new Date(data.timestamp) : null,
|
|
2603
2973
|
dateUpdated: data.dateUpdated ? new Date(data.dateUpdated) : null,
|
|
2604
2974
|
lastUpdatedBy: (_data$lastUpdatedBy = data.lastUpdatedBy) !== null && _data$lastUpdatedBy !== void 0 ? _data$lastUpdatedBy : null,
|
|
2605
2975
|
attributes: parseAttributes(data.attributes, "Got malformed attributes for the message ".concat(data.sid), log$3),
|
|
2606
2976
|
type: (_data$type = data.type) !== null && _data$type !== void 0 ? _data$type : "text",
|
|
2607
|
-
media:
|
|
2608
|
-
medias:
|
|
2609
|
-
return new Media(m, _this.services);
|
|
2610
|
-
}) : data.type === "media" && data.media && !data.medias ? [new Media(_objectSpread$3(_objectSpread$3({}, data.media), {}, {
|
|
2611
|
-
category: "media"
|
|
2612
|
-
}), _this.services)] : null,
|
|
2977
|
+
media: null,
|
|
2978
|
+
medias: null,
|
|
2613
2979
|
participantSid: (_data$memberSid = data.memberSid) !== null && _data$memberSid !== void 0 ? _data$memberSid : null,
|
|
2614
|
-
aggregatedDeliveryReceipt: data.delivery ? new AggregatedDeliveryReceipt(data.delivery) : null
|
|
2980
|
+
aggregatedDeliveryReceipt: data.delivery ? new AggregatedDeliveryReceipt(data.delivery) : null,
|
|
2981
|
+
hasChannelMetadata: (_data$channelMetadata = data.channelMetadata) !== null && _data$channelMetadata !== void 0 ? _data$channelMetadata : false
|
|
2615
2982
|
};
|
|
2983
|
+
|
|
2984
|
+
_classPrivateMethodGet(_assertThisInitialized__default["default"](_this), _assignMedias, _assignMedias2).call(_assertThisInitialized__default["default"](_this), (_data$medias = data.medias) !== null && _data$medias !== void 0 ? _data$medias : null, (_data$media = data.media) !== null && _data$media !== void 0 ? _data$media : null);
|
|
2985
|
+
|
|
2616
2986
|
return _this;
|
|
2617
2987
|
}
|
|
2618
2988
|
/**
|
|
@@ -2652,6 +3022,15 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
2652
3022
|
get: function get() {
|
|
2653
3023
|
return this.state.subject;
|
|
2654
3024
|
}
|
|
3025
|
+
/**
|
|
3026
|
+
* Unique identifier of {@link ContentTemplate} for this message.
|
|
3027
|
+
*/
|
|
3028
|
+
|
|
3029
|
+
}, {
|
|
3030
|
+
key: "contentSid",
|
|
3031
|
+
get: function get() {
|
|
3032
|
+
return this.state.contentSid;
|
|
3033
|
+
}
|
|
2655
3034
|
/**
|
|
2656
3035
|
* Body of the message.
|
|
2657
3036
|
*/
|
|
@@ -2671,14 +3050,15 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
2671
3050
|
return this.state.dateUpdated;
|
|
2672
3051
|
}
|
|
2673
3052
|
/**
|
|
2674
|
-
* Index of
|
|
2675
|
-
*
|
|
3053
|
+
* Index of this message in the conversation's list of messages.
|
|
3054
|
+
*
|
|
3055
|
+
* By design, the message indices may have arbitrary gaps between them,
|
|
2676
3056
|
* that does not necessarily mean they were deleted or otherwise modified - just that
|
|
2677
3057
|
* messages may have some non-contiguous indices even if they are being sent immediately one after another.
|
|
2678
3058
|
*
|
|
2679
3059
|
* Trying to use indices for some calculations is going to be unreliable.
|
|
2680
3060
|
*
|
|
2681
|
-
* To calculate the number of unread messages it is better to use the
|
|
3061
|
+
* To calculate the number of unread messages, it is better to use the Read Horizon API.
|
|
2682
3062
|
* See {@link Conversation.getUnreadMessagesCount} for details.
|
|
2683
3063
|
*/
|
|
2684
3064
|
|
|
@@ -2760,6 +3140,19 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
2760
3140
|
get: function get() {
|
|
2761
3141
|
return this.state.aggregatedDeliveryReceipt;
|
|
2762
3142
|
}
|
|
3143
|
+
/**
|
|
3144
|
+
* @deprecated
|
|
3145
|
+
* Return a (possibly empty) array of media matching a specific set of categories.
|
|
3146
|
+
* Allowed category is so far only 'media'.
|
|
3147
|
+
* @param categories Array of categories to match.
|
|
3148
|
+
* @returns Array of media descriptors matching given categories.
|
|
3149
|
+
*/
|
|
3150
|
+
|
|
3151
|
+
}, {
|
|
3152
|
+
key: "getMediaByCategory",
|
|
3153
|
+
value: function getMediaByCategory(categories) {
|
|
3154
|
+
return this.getMediaByCategories(categories);
|
|
3155
|
+
}
|
|
2763
3156
|
/**
|
|
2764
3157
|
* Return a (possibly empty) array of media matching a specific set of categories.
|
|
2765
3158
|
* Allowed category is so far only 'media'.
|
|
@@ -2811,6 +3204,12 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
2811
3204
|
}, {
|
|
2812
3205
|
key: "_update",
|
|
2813
3206
|
value: function _update(data) {
|
|
3207
|
+
var _data$medias2,
|
|
3208
|
+
_this2 = this,
|
|
3209
|
+
_this$state$medias2,
|
|
3210
|
+
_classPrivateMethodGe2,
|
|
3211
|
+
_this$state$media;
|
|
3212
|
+
|
|
2814
3213
|
var updateReasons = [];
|
|
2815
3214
|
|
|
2816
3215
|
if ((data.text || typeof data.text === "string") && data.text !== this.state.body) {
|
|
@@ -2845,7 +3244,7 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
2845
3244
|
|
|
2846
3245
|
var updatedAttributes = parseAttributes(data.attributes, "Got malformed attributes for the message ".concat(this.sid), log$3);
|
|
2847
3246
|
|
|
2848
|
-
if (!
|
|
3247
|
+
if (!isEqual(this.state.attributes, updatedAttributes)) {
|
|
2849
3248
|
this.state.attributes = updatedAttributes;
|
|
2850
3249
|
updateReasons.push("attributes");
|
|
2851
3250
|
}
|
|
@@ -2863,6 +3262,29 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
2863
3262
|
|
|
2864
3263
|
updateReasons.push("deliveryReceipt");
|
|
2865
3264
|
}
|
|
3265
|
+
} // @fixme: This is a fairly heavy check.
|
|
3266
|
+
// Map data back and forth to perform a necessary field massage.
|
|
3267
|
+
|
|
3268
|
+
|
|
3269
|
+
var input = ((_data$medias2 = data.medias) !== null && _data$medias2 !== void 0 ? _data$medias2 : []).map(function (value) {
|
|
3270
|
+
var _classPrivateMethodGe;
|
|
3271
|
+
|
|
3272
|
+
return (_classPrivateMethodGe = _classPrivateMethodGet(_this2, _wrapMedia, _wrapMedia2).call(_this2, value)) === null || _classPrivateMethodGe === void 0 ? void 0 : _classPrivateMethodGe._state();
|
|
3273
|
+
}).filter(function (el) {
|
|
3274
|
+
return !(el === null);
|
|
3275
|
+
});
|
|
3276
|
+
var current = ((_this$state$medias2 = this.state.medias) !== null && _this$state$medias2 !== void 0 ? _this$state$medias2 : []).map(function (value) {
|
|
3277
|
+
return value._state();
|
|
3278
|
+
}).filter(function (el) {
|
|
3279
|
+
return !(el === null);
|
|
3280
|
+
});
|
|
3281
|
+
|
|
3282
|
+
if (!isEqual(input, current) || !isEqual((_classPrivateMethodGe2 = _classPrivateMethodGet(this, _wrapMedia, _wrapMedia2).call(this, data.media)) === null || _classPrivateMethodGe2 === void 0 ? void 0 : _classPrivateMethodGe2._state(), (_this$state$media = this.state.media) === null || _this$state$media === void 0 ? void 0 : _this$state$media._state())) {
|
|
3283
|
+
var _data$medias3, _data$media2;
|
|
3284
|
+
|
|
3285
|
+
_classPrivateMethodGet(this, _assignMedias, _assignMedias2).call(this, (_data$medias3 = data.medias) !== null && _data$medias3 !== void 0 ? _data$medias3 : null, (_data$media2 = data.media) !== null && _data$media2 !== void 0 ? _data$media2 : null);
|
|
3286
|
+
|
|
3287
|
+
updateReasons.push("media");
|
|
2866
3288
|
}
|
|
2867
3289
|
|
|
2868
3290
|
if (updateReasons.length > 0) {
|
|
@@ -2880,9 +3302,9 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
2880
3302
|
key: "getParticipant",
|
|
2881
3303
|
value: function () {
|
|
2882
3304
|
var _getParticipant = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee() {
|
|
2883
|
-
var
|
|
3305
|
+
var _this3 = this;
|
|
2884
3306
|
|
|
2885
|
-
var participant,
|
|
3307
|
+
var participant, errorMessage;
|
|
2886
3308
|
return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
|
|
2887
3309
|
while (1) {
|
|
2888
3310
|
switch (_context.prev = _context.next) {
|
|
@@ -2896,7 +3318,7 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
2896
3318
|
|
|
2897
3319
|
_context.next = 4;
|
|
2898
3320
|
return this.conversation.getParticipantBySid(this.state.participantSid).catch(function () {
|
|
2899
|
-
log$3.debug("Participant with sid \"".concat(
|
|
3321
|
+
log$3.debug("Participant with sid \"".concat(_this3.participantSid, "\" not found for message ").concat(_this3.sid));
|
|
2900
3322
|
return null;
|
|
2901
3323
|
});
|
|
2902
3324
|
|
|
@@ -2911,7 +3333,7 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
2911
3333
|
|
|
2912
3334
|
_context.next = 8;
|
|
2913
3335
|
return this.conversation.getParticipantByIdentity(this.state.author).catch(function () {
|
|
2914
|
-
log$3.debug("Participant with identity \"".concat(
|
|
3336
|
+
log$3.debug("Participant with identity \"".concat(_this3.author, "\" not found for message ").concat(_this3.sid));
|
|
2915
3337
|
return null;
|
|
2916
3338
|
});
|
|
2917
3339
|
|
|
@@ -2927,26 +3349,26 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
2927
3349
|
return _context.abrupt("return", participant);
|
|
2928
3350
|
|
|
2929
3351
|
case 11:
|
|
2930
|
-
|
|
3352
|
+
errorMessage = "Participant with ";
|
|
2931
3353
|
|
|
2932
3354
|
if (this.state.participantSid) {
|
|
2933
|
-
|
|
3355
|
+
errorMessage += "SID '" + this.state.participantSid + "' ";
|
|
2934
3356
|
}
|
|
2935
3357
|
|
|
2936
3358
|
if (this.state.author) {
|
|
2937
3359
|
if (this.state.participantSid) {
|
|
2938
|
-
|
|
3360
|
+
errorMessage += "or ";
|
|
2939
3361
|
}
|
|
2940
3362
|
|
|
2941
|
-
|
|
3363
|
+
errorMessage += "identity '" + this.state.author + "' ";
|
|
2942
3364
|
}
|
|
2943
3365
|
|
|
2944
|
-
if (
|
|
2945
|
-
|
|
3366
|
+
if (errorMessage === "Participant with ") {
|
|
3367
|
+
errorMessage = "Participant ";
|
|
2946
3368
|
}
|
|
2947
3369
|
|
|
2948
|
-
|
|
2949
|
-
throw new Error(
|
|
3370
|
+
errorMessage += "was not found";
|
|
3371
|
+
throw new Error(errorMessage);
|
|
2950
3372
|
|
|
2951
3373
|
case 17:
|
|
2952
3374
|
case "end":
|
|
@@ -2980,32 +3402,27 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
2980
3402
|
|
|
2981
3403
|
case 2:
|
|
2982
3404
|
paginator = _context2.sent;
|
|
2983
|
-
detailedDeliveryReceipts =
|
|
3405
|
+
detailedDeliveryReceipts = paginator.items;
|
|
2984
3406
|
|
|
2985
3407
|
case 4:
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
if (paginator.hasNextPage) {
|
|
2990
|
-
_context2.next = 8;
|
|
3408
|
+
if (!paginator.hasNextPage) {
|
|
3409
|
+
_context2.next = 11;
|
|
2991
3410
|
break;
|
|
2992
3411
|
}
|
|
2993
3412
|
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
case 8:
|
|
2997
|
-
_context2.next = 10;
|
|
3413
|
+
_context2.next = 7;
|
|
2998
3414
|
return paginator.nextPage();
|
|
2999
3415
|
|
|
3000
|
-
case
|
|
3416
|
+
case 7:
|
|
3001
3417
|
paginator = _context2.sent;
|
|
3418
|
+
detailedDeliveryReceipts = [].concat(_toConsumableArray__default["default"](detailedDeliveryReceipts), _toConsumableArray__default["default"](paginator.items));
|
|
3002
3419
|
_context2.next = 4;
|
|
3003
3420
|
break;
|
|
3004
3421
|
|
|
3005
|
-
case
|
|
3422
|
+
case 11:
|
|
3006
3423
|
return _context2.abrupt("return", detailedDeliveryReceipts);
|
|
3007
3424
|
|
|
3008
|
-
case
|
|
3425
|
+
case 12:
|
|
3009
3426
|
case "end":
|
|
3010
3427
|
return _context2.stop();
|
|
3011
3428
|
}
|
|
@@ -3121,6 +3538,59 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
3121
3538
|
|
|
3122
3539
|
return updateAttributes;
|
|
3123
3540
|
}()
|
|
3541
|
+
/**
|
|
3542
|
+
* @deprecated
|
|
3543
|
+
* Get content URLs for all media attachments in the given set using a single operation.
|
|
3544
|
+
* @param contentSet Set of media attachments to query content URLs.
|
|
3545
|
+
*/
|
|
3546
|
+
|
|
3547
|
+
}, {
|
|
3548
|
+
key: "attachTemporaryUrlsFor",
|
|
3549
|
+
value: function () {
|
|
3550
|
+
var _attachTemporaryUrlsFor = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee6(contentSet) {
|
|
3551
|
+
var _this4 = this;
|
|
3552
|
+
|
|
3553
|
+
var sids;
|
|
3554
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee6$(_context6) {
|
|
3555
|
+
while (1) {
|
|
3556
|
+
switch (_context6.prev = _context6.next) {
|
|
3557
|
+
case 0:
|
|
3558
|
+
// We ignore existing mcsMedia members of each of the media entries.
|
|
3559
|
+
// Instead we just collect their sids and pull new descriptors from a mediaSet GET endpoint.
|
|
3560
|
+
sids = contentSet === null || contentSet === void 0 ? void 0 : contentSet.map(function (m) {
|
|
3561
|
+
return m.sid;
|
|
3562
|
+
});
|
|
3563
|
+
|
|
3564
|
+
if (!(this.services.mcsClient && sids)) {
|
|
3565
|
+
_context6.next = 7;
|
|
3566
|
+
break;
|
|
3567
|
+
}
|
|
3568
|
+
|
|
3569
|
+
_context6.next = 4;
|
|
3570
|
+
return this.services.mcsClient.mediaSetGet(sids);
|
|
3571
|
+
|
|
3572
|
+
case 4:
|
|
3573
|
+
return _context6.abrupt("return", _context6.sent.map(function (item) {
|
|
3574
|
+
return new Media(item, _this4.services);
|
|
3575
|
+
}));
|
|
3576
|
+
|
|
3577
|
+
case 7:
|
|
3578
|
+
throw new Error("Media Content Service is unavailable");
|
|
3579
|
+
|
|
3580
|
+
case 8:
|
|
3581
|
+
case "end":
|
|
3582
|
+
return _context6.stop();
|
|
3583
|
+
}
|
|
3584
|
+
}
|
|
3585
|
+
}, _callee6, this);
|
|
3586
|
+
}));
|
|
3587
|
+
|
|
3588
|
+
function attachTemporaryUrlsFor(_x3) {
|
|
3589
|
+
return _attachTemporaryUrlsFor.apply(this, arguments);
|
|
3590
|
+
}
|
|
3591
|
+
|
|
3592
|
+
return attachTemporaryUrlsFor;
|
|
3593
|
+
}()
|
|
3124
3594
|
/**
|
|
3125
3595
|
* Get content URLs for all media attachments in the given set using a single operation.
|
|
3126
3596
|
* @param contentSet Set of media attachments to query content URLs.
|
|
@@ -3144,53 +3614,53 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
3144
3614
|
}, {
|
|
3145
3615
|
key: "getTemporaryContentUrlsForMediaSids",
|
|
3146
3616
|
value: function getTemporaryContentUrlsForMediaSids(mediaSids) {
|
|
3147
|
-
var
|
|
3617
|
+
var _this5 = this;
|
|
3148
3618
|
|
|
3149
3619
|
return new mcsClient.CancellablePromise( /*#__PURE__*/function () {
|
|
3150
|
-
var _ref = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function
|
|
3620
|
+
var _ref = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee7(resolve, reject, onCancel) {
|
|
3151
3621
|
var mediaGetRequest, urls;
|
|
3152
|
-
return _regeneratorRuntime__default["default"].wrap(function
|
|
3622
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee7$(_context7) {
|
|
3153
3623
|
while (1) {
|
|
3154
|
-
switch (
|
|
3624
|
+
switch (_context7.prev = _context7.next) {
|
|
3155
3625
|
case 0:
|
|
3156
|
-
mediaGetRequest =
|
|
3626
|
+
mediaGetRequest = _this5.services.mcsClient.mediaSetGetContentUrls(mediaSids !== null && mediaSids !== void 0 ? mediaSids : []);
|
|
3157
3627
|
|
|
3158
|
-
if (!(!
|
|
3159
|
-
|
|
3628
|
+
if (!(!_this5.services.mcsClient || !mediaSids)) {
|
|
3629
|
+
_context7.next = 4;
|
|
3160
3630
|
break;
|
|
3161
3631
|
}
|
|
3162
3632
|
|
|
3163
3633
|
reject(new Error("Media Content Service is unavailable"));
|
|
3164
|
-
return
|
|
3634
|
+
return _context7.abrupt("return");
|
|
3165
3635
|
|
|
3166
3636
|
case 4:
|
|
3167
3637
|
onCancel(function () {
|
|
3168
3638
|
mediaGetRequest.cancel();
|
|
3169
3639
|
});
|
|
3170
|
-
|
|
3171
|
-
|
|
3640
|
+
_context7.prev = 5;
|
|
3641
|
+
_context7.next = 8;
|
|
3172
3642
|
return mediaGetRequest;
|
|
3173
3643
|
|
|
3174
3644
|
case 8:
|
|
3175
|
-
urls =
|
|
3645
|
+
urls = _context7.sent;
|
|
3176
3646
|
resolve(urls);
|
|
3177
|
-
|
|
3647
|
+
_context7.next = 15;
|
|
3178
3648
|
break;
|
|
3179
3649
|
|
|
3180
3650
|
case 12:
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
reject(
|
|
3651
|
+
_context7.prev = 12;
|
|
3652
|
+
_context7.t0 = _context7["catch"](5);
|
|
3653
|
+
reject(_context7.t0);
|
|
3184
3654
|
|
|
3185
3655
|
case 15:
|
|
3186
3656
|
case "end":
|
|
3187
|
-
return
|
|
3657
|
+
return _context7.stop();
|
|
3188
3658
|
}
|
|
3189
3659
|
}
|
|
3190
|
-
},
|
|
3660
|
+
}, _callee7, null, [[5, 12]]);
|
|
3191
3661
|
}));
|
|
3192
3662
|
|
|
3193
|
-
return function (
|
|
3663
|
+
return function (_x4, _x5, _x6) {
|
|
3194
3664
|
return _ref.apply(this, arguments);
|
|
3195
3665
|
};
|
|
3196
3666
|
}());
|
|
@@ -3213,25 +3683,25 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
3213
3683
|
}, {
|
|
3214
3684
|
key: "_getDetailedDeliveryReceiptsPaginator",
|
|
3215
3685
|
value: function () {
|
|
3216
|
-
var _getDetailedDeliveryReceiptsPaginator2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function
|
|
3217
|
-
var
|
|
3686
|
+
var _getDetailedDeliveryReceiptsPaginator2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee8(options) {
|
|
3687
|
+
var _this6 = this;
|
|
3218
3688
|
|
|
3219
3689
|
var messagesReceiptsUrl, url, response;
|
|
3220
|
-
return _regeneratorRuntime__default["default"].wrap(function
|
|
3690
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee8$(_context8) {
|
|
3221
3691
|
while (1) {
|
|
3222
|
-
switch (
|
|
3692
|
+
switch (_context8.prev = _context8.next) {
|
|
3223
3693
|
case 0:
|
|
3224
3694
|
messagesReceiptsUrl = this.configuration.links.messagesReceipts.replace("%s", this.conversation.sid).replace("%s", this.sid);
|
|
3225
3695
|
url = new UriBuilder(messagesReceiptsUrl).arg("PageToken", options === null || options === void 0 ? void 0 : options.pageToken).arg("PageSize", options === null || options === void 0 ? void 0 : options.pageSize).build();
|
|
3226
|
-
|
|
3696
|
+
_context8.next = 4;
|
|
3227
3697
|
return this.services.network.get(url);
|
|
3228
3698
|
|
|
3229
3699
|
case 4:
|
|
3230
|
-
response =
|
|
3231
|
-
return
|
|
3700
|
+
response = _context8.sent;
|
|
3701
|
+
return _context8.abrupt("return", new RestPaginator(response.body.delivery_receipts.map(function (x) {
|
|
3232
3702
|
return new DetailedDeliveryReceipt(x);
|
|
3233
3703
|
}), function (pageToken, pageSize) {
|
|
3234
|
-
return
|
|
3704
|
+
return _this6._getDetailedDeliveryReceiptsPaginator({
|
|
3235
3705
|
pageToken: pageToken,
|
|
3236
3706
|
pageSize: pageSize
|
|
3237
3707
|
});
|
|
@@ -3239,46 +3709,290 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
3239
3709
|
|
|
3240
3710
|
case 6:
|
|
3241
3711
|
case "end":
|
|
3242
|
-
return
|
|
3712
|
+
return _context8.stop();
|
|
3243
3713
|
}
|
|
3244
3714
|
}
|
|
3245
|
-
},
|
|
3715
|
+
}, _callee8, this);
|
|
3246
3716
|
}));
|
|
3247
3717
|
|
|
3248
|
-
function _getDetailedDeliveryReceiptsPaginator(
|
|
3718
|
+
function _getDetailedDeliveryReceiptsPaginator(_x7) {
|
|
3249
3719
|
return _getDetailedDeliveryReceiptsPaginator2.apply(this, arguments);
|
|
3250
3720
|
}
|
|
3251
3721
|
|
|
3252
3722
|
return _getDetailedDeliveryReceiptsPaginator;
|
|
3253
3723
|
}()
|
|
3724
|
+
/**
|
|
3725
|
+
* Get the {@link ContentData} for this message. Resolves to `null` when
|
|
3726
|
+
* {@link Message.contentSid} is null.
|
|
3727
|
+
*/
|
|
3728
|
+
|
|
3729
|
+
}, {
|
|
3730
|
+
key: "getContentData",
|
|
3731
|
+
value: function getContentData() {
|
|
3732
|
+
var _this7 = this;
|
|
3733
|
+
|
|
3734
|
+
return new mcsClient.CancellablePromise( /*#__PURE__*/function () {
|
|
3735
|
+
var _ref2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee9(resolve, reject, onCancel) {
|
|
3736
|
+
var bodies, twilioPrefix, filteredMedias, contentMedia, urlPromise, url, jsonStringPromise, json, jsonString, dataType;
|
|
3737
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee9$(_context9) {
|
|
3738
|
+
while (1) {
|
|
3739
|
+
switch (_context9.prev = _context9.next) {
|
|
3740
|
+
case 0:
|
|
3741
|
+
if (!(_this7.state.contentSid === null)) {
|
|
3742
|
+
_context9.next = 3;
|
|
3743
|
+
break;
|
|
3744
|
+
}
|
|
3745
|
+
|
|
3746
|
+
resolve(null);
|
|
3747
|
+
return _context9.abrupt("return");
|
|
3748
|
+
|
|
3749
|
+
case 3:
|
|
3750
|
+
bodies = _this7.getMediaByCategories(["body"]);
|
|
3751
|
+
|
|
3752
|
+
if (!(bodies === null)) {
|
|
3753
|
+
_context9.next = 7;
|
|
3754
|
+
break;
|
|
3755
|
+
}
|
|
3756
|
+
|
|
3757
|
+
resolve(null);
|
|
3758
|
+
return _context9.abrupt("return");
|
|
3759
|
+
|
|
3760
|
+
case 7:
|
|
3761
|
+
twilioPrefix = "application/x-vnd.com.twilio.rich.";
|
|
3762
|
+
filteredMedias = bodies.filter(function (media) {
|
|
3763
|
+
return media.contentType.startsWith(twilioPrefix);
|
|
3764
|
+
});
|
|
3765
|
+
|
|
3766
|
+
if (!(filteredMedias.length === 0)) {
|
|
3767
|
+
_context9.next = 12;
|
|
3768
|
+
break;
|
|
3769
|
+
}
|
|
3770
|
+
|
|
3771
|
+
resolve(null);
|
|
3772
|
+
return _context9.abrupt("return");
|
|
3773
|
+
|
|
3774
|
+
case 12:
|
|
3775
|
+
contentMedia = filteredMedias[0];
|
|
3776
|
+
urlPromise = contentMedia.getContentTemporaryUrl();
|
|
3777
|
+
onCancel(function () {
|
|
3778
|
+
urlPromise.cancel();
|
|
3779
|
+
});
|
|
3780
|
+
_context9.prev = 15;
|
|
3781
|
+
_context9.next = 18;
|
|
3782
|
+
return urlPromise;
|
|
3783
|
+
|
|
3784
|
+
case 18:
|
|
3785
|
+
url = _context9.sent;
|
|
3786
|
+
_context9.next = 25;
|
|
3787
|
+
break;
|
|
3788
|
+
|
|
3789
|
+
case 21:
|
|
3790
|
+
_context9.prev = 21;
|
|
3791
|
+
_context9.t0 = _context9["catch"](15);
|
|
3792
|
+
reject(_context9.t0);
|
|
3793
|
+
return _context9.abrupt("return");
|
|
3794
|
+
|
|
3795
|
+
case 25:
|
|
3796
|
+
if (!(url === null)) {
|
|
3797
|
+
_context9.next = 28;
|
|
3798
|
+
break;
|
|
3799
|
+
}
|
|
3800
|
+
|
|
3801
|
+
resolve(null);
|
|
3802
|
+
return _context9.abrupt("return");
|
|
3803
|
+
|
|
3804
|
+
case 28:
|
|
3805
|
+
jsonStringPromise = new Promise(function (resolve, reject) {
|
|
3806
|
+
var _url;
|
|
3807
|
+
|
|
3808
|
+
var isCancelled = false;
|
|
3809
|
+
var xhr = new XHR();
|
|
3810
|
+
xhr.open("GET", (_url = url) !== null && _url !== void 0 ? _url : "", true);
|
|
3811
|
+
xhr.responseType = "text";
|
|
3812
|
+
|
|
3813
|
+
xhr.onreadystatechange = function () {
|
|
3814
|
+
if (xhr.readyState !== 4 || isCancelled) {
|
|
3815
|
+
return;
|
|
3816
|
+
}
|
|
3817
|
+
|
|
3818
|
+
resolve(xhr.responseText);
|
|
3819
|
+
};
|
|
3820
|
+
|
|
3821
|
+
xhr.onerror = function () {
|
|
3822
|
+
reject(xhr.statusText);
|
|
3823
|
+
};
|
|
3824
|
+
|
|
3825
|
+
onCancel(function () {
|
|
3826
|
+
isCancelled = true;
|
|
3827
|
+
xhr.abort();
|
|
3828
|
+
reject(new Error("XHR has been aborted"));
|
|
3829
|
+
});
|
|
3830
|
+
xhr.send();
|
|
3831
|
+
});
|
|
3832
|
+
_context9.prev = 29;
|
|
3833
|
+
_context9.next = 32;
|
|
3834
|
+
return jsonStringPromise;
|
|
3835
|
+
|
|
3836
|
+
case 32:
|
|
3837
|
+
jsonString = _context9.sent;
|
|
3838
|
+
json = JSON.parse(jsonString);
|
|
3839
|
+
_context9.next = 40;
|
|
3840
|
+
break;
|
|
3841
|
+
|
|
3842
|
+
case 36:
|
|
3843
|
+
_context9.prev = 36;
|
|
3844
|
+
_context9.t1 = _context9["catch"](29);
|
|
3845
|
+
reject(_context9.t1);
|
|
3846
|
+
return _context9.abrupt("return");
|
|
3847
|
+
|
|
3848
|
+
case 40:
|
|
3849
|
+
dataType = contentMedia.contentType.replace(twilioPrefix, "").replace(".", "/");
|
|
3850
|
+
resolve(parseVariant(dataType, json.data));
|
|
3851
|
+
|
|
3852
|
+
case 42:
|
|
3853
|
+
case "end":
|
|
3854
|
+
return _context9.stop();
|
|
3855
|
+
}
|
|
3856
|
+
}
|
|
3857
|
+
}, _callee9, null, [[15, 21], [29, 36]]);
|
|
3858
|
+
}));
|
|
3859
|
+
|
|
3860
|
+
return function (_x8, _x9, _x10) {
|
|
3861
|
+
return _ref2.apply(this, arguments);
|
|
3862
|
+
};
|
|
3863
|
+
}());
|
|
3864
|
+
}
|
|
3865
|
+
/**
|
|
3866
|
+
* Get the {@link ChannelMetadata} for this message. Resolves to `null` if
|
|
3867
|
+
* the message doesn't have any channel metadata.
|
|
3868
|
+
*/
|
|
3869
|
+
|
|
3870
|
+
}, {
|
|
3871
|
+
key: "getChannelMetadata",
|
|
3872
|
+
value: function () {
|
|
3873
|
+
var _getChannelMetadata = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee10() {
|
|
3874
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee10$(_context10) {
|
|
3875
|
+
while (1) {
|
|
3876
|
+
switch (_context10.prev = _context10.next) {
|
|
3877
|
+
case 0:
|
|
3878
|
+
if (this.state.hasChannelMetadata) {
|
|
3879
|
+
_context10.next = 2;
|
|
3880
|
+
break;
|
|
3881
|
+
}
|
|
3882
|
+
|
|
3883
|
+
return _context10.abrupt("return", null);
|
|
3884
|
+
|
|
3885
|
+
case 2:
|
|
3886
|
+
_context10.next = 4;
|
|
3887
|
+
return this.services.channelMetadataClient.getChannelMetadata(this.conversation.sid, this.sid);
|
|
3888
|
+
|
|
3889
|
+
case 4:
|
|
3890
|
+
return _context10.abrupt("return", _context10.sent);
|
|
3891
|
+
|
|
3892
|
+
case 5:
|
|
3893
|
+
case "end":
|
|
3894
|
+
return _context10.stop();
|
|
3895
|
+
}
|
|
3896
|
+
}
|
|
3897
|
+
}, _callee10, this);
|
|
3898
|
+
}));
|
|
3899
|
+
|
|
3900
|
+
function getChannelMetadata() {
|
|
3901
|
+
return _getChannelMetadata.apply(this, arguments);
|
|
3902
|
+
}
|
|
3903
|
+
|
|
3904
|
+
return getChannelMetadata;
|
|
3905
|
+
}()
|
|
3906
|
+
/**
|
|
3907
|
+
* Get recipients of the message.
|
|
3908
|
+
*/
|
|
3909
|
+
|
|
3910
|
+
}, {
|
|
3911
|
+
key: "getMessageRecipients",
|
|
3912
|
+
value: function () {
|
|
3913
|
+
var _getMessageRecipients = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee11() {
|
|
3914
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee11$(_context11) {
|
|
3915
|
+
while (1) {
|
|
3916
|
+
switch (_context11.prev = _context11.next) {
|
|
3917
|
+
case 0:
|
|
3918
|
+
_context11.next = 2;
|
|
3919
|
+
return this.services.messageRecipientsClient.getRecipientsFromMessage(this.conversation.sid, this.sid);
|
|
3920
|
+
|
|
3921
|
+
case 2:
|
|
3922
|
+
return _context11.abrupt("return", _context11.sent);
|
|
3923
|
+
|
|
3924
|
+
case 3:
|
|
3925
|
+
case "end":
|
|
3926
|
+
return _context11.stop();
|
|
3927
|
+
}
|
|
3928
|
+
}
|
|
3929
|
+
}, _callee11, this);
|
|
3930
|
+
}));
|
|
3931
|
+
|
|
3932
|
+
function getMessageRecipients() {
|
|
3933
|
+
return _getMessageRecipients.apply(this, arguments);
|
|
3934
|
+
}
|
|
3935
|
+
|
|
3936
|
+
return getMessageRecipients;
|
|
3937
|
+
}()
|
|
3254
3938
|
}]);
|
|
3255
3939
|
|
|
3256
3940
|
return Message;
|
|
3257
3941
|
}(replayEventEmitter.ReplayEventEmitter);
|
|
3258
3942
|
|
|
3943
|
+
function _wrapMedia2(media) {
|
|
3944
|
+
var category = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
3945
|
+
return media ? category ? new Media(_objectSpread$4(_objectSpread$4({}, media), {}, {
|
|
3946
|
+
category: category
|
|
3947
|
+
}), this.services) : new Media(media, this.services) : null;
|
|
3948
|
+
}
|
|
3949
|
+
|
|
3950
|
+
function _assignMedias2(medias, media) {
|
|
3951
|
+
var _this8 = this;
|
|
3952
|
+
|
|
3953
|
+
this.state.media = _classPrivateMethodGet(this, _wrapMedia, _wrapMedia2).call(this, media); // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
3954
|
+
// @ts-ignore
|
|
3955
|
+
|
|
3956
|
+
this.state.medias = medias ? medias.map(function (m) {
|
|
3957
|
+
return _classPrivateMethodGet(_this8, _wrapMedia, _wrapMedia2).call(_this8, m);
|
|
3958
|
+
}).filter(function (el) {
|
|
3959
|
+
return el !== null;
|
|
3960
|
+
}) : media && !medias ? [_classPrivateMethodGet(this, _wrapMedia, _wrapMedia2).call(this, media, "media")].filter(function (el) {
|
|
3961
|
+
return el !== null;
|
|
3962
|
+
}) : null;
|
|
3963
|
+
}
|
|
3964
|
+
|
|
3259
3965
|
_defineProperty__default["default"](Message, "updated", "updated");
|
|
3260
3966
|
|
|
3967
|
+
__decorate([deprecationDecorator.deprecated("getMediaByCategory", "getMediaByCategories"), __metadata("design:type", Function), __metadata("design:paramtypes", [Array]), __metadata("design:returntype", Array)], Message.prototype, "getMediaByCategory", null);
|
|
3968
|
+
|
|
3261
3969
|
__decorate([declarativeTypeValidator.validateTypes([declarativeTypeValidator.nonEmptyString, "undefined"]), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Media)], Message.prototype, "getEmailBody", null);
|
|
3262
3970
|
|
|
3263
3971
|
__decorate([declarativeTypeValidator.validateTypes([declarativeTypeValidator.nonEmptyString, "undefined"]), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Media)], Message.prototype, "getEmailHistory", null);
|
|
3264
3972
|
|
|
3265
3973
|
__decorate([declarativeTypeValidator.validateTypesAsync("string"), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", Promise)], Message.prototype, "updateBody", null);
|
|
3266
3974
|
|
|
3267
|
-
__decorate([declarativeTypeValidator.validateTypesAsync(
|
|
3975
|
+
__decorate([declarativeTypeValidator.validateTypesAsync(json), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise)], Message.prototype, "updateAttributes", null);
|
|
3976
|
+
|
|
3977
|
+
__decorate([deprecationDecorator.deprecated("attachTemporaryUrlsFor", "getTemporaryContentUrlsForMedia"), __metadata("design:type", Function), __metadata("design:paramtypes", [Array]), __metadata("design:returntype", Promise)], Message.prototype, "attachTemporaryUrlsFor", null);
|
|
3268
3978
|
|
|
3269
3979
|
__decorate([declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyArray("media", Media)), __metadata("design:type", Function), __metadata("design:paramtypes", [Array]), __metadata("design:returntype", mcsClient.CancellablePromise)], Message.prototype, "getTemporaryContentUrlsForMedia", null);
|
|
3270
3980
|
|
|
3271
3981
|
__decorate([declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyArray("strings", "string")), __metadata("design:type", Function), __metadata("design:paramtypes", [Array]), __metadata("design:returntype", mcsClient.CancellablePromise)], Message.prototype, "getTemporaryContentUrlsForMediaSids", null);
|
|
3272
3982
|
|
|
3273
|
-
function
|
|
3983
|
+
function ownKeys$3(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3274
3984
|
|
|
3275
|
-
function
|
|
3985
|
+
function _objectSpread$3(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$3(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$3(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
3276
3986
|
|
|
3277
|
-
function
|
|
3987
|
+
function _createForOfIteratorHelper$4(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$4(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
3278
3988
|
|
|
3279
|
-
function
|
|
3989
|
+
function _unsupportedIterableToArray$4(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$4(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$4(o, minLen); }
|
|
3280
3990
|
|
|
3281
|
-
function
|
|
3991
|
+
function _arrayLikeToArray$4(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
3992
|
+
|
|
3993
|
+
function _createSuper$5(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$5(); return function _createSuperInternal() { var Super = _getPrototypeOf__default["default"](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default["default"](this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default["default"](this, result); }; }
|
|
3994
|
+
|
|
3995
|
+
function _isNativeReflectConstruct$5() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
3282
3996
|
var log$2 = Logger.scope("Messages");
|
|
3283
3997
|
/**
|
|
3284
3998
|
* Represents the collection of messages in a conversation
|
|
@@ -3287,7 +4001,7 @@ var log$2 = Logger.scope("Messages");
|
|
|
3287
4001
|
var Messages = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
3288
4002
|
_inherits__default["default"](Messages, _ReplayEventEmitter);
|
|
3289
4003
|
|
|
3290
|
-
var _super = _createSuper$
|
|
4004
|
+
var _super = _createSuper$5(Messages);
|
|
3291
4005
|
|
|
3292
4006
|
function Messages(conversation, configuration, services) {
|
|
3293
4007
|
var _this;
|
|
@@ -3304,14 +4018,15 @@ var Messages = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
3304
4018
|
}
|
|
3305
4019
|
/**
|
|
3306
4020
|
* Subscribe to the Messages Event Stream
|
|
3307
|
-
* @param
|
|
4021
|
+
* @param arg - Name of the Sync object, or the SyncList itself, that
|
|
4022
|
+
* represents the Messages resource.
|
|
3308
4023
|
*/
|
|
3309
4024
|
|
|
3310
4025
|
|
|
3311
4026
|
_createClass__default["default"](Messages, [{
|
|
3312
4027
|
key: "subscribe",
|
|
3313
4028
|
value: function () {
|
|
3314
|
-
var _subscribe = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(
|
|
4029
|
+
var _subscribe = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(arg) {
|
|
3315
4030
|
var _this2 = this;
|
|
3316
4031
|
|
|
3317
4032
|
var list;
|
|
@@ -3327,10 +4042,10 @@ var Messages = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
3327
4042
|
return _context.abrupt("return", this.messagesListPromise);
|
|
3328
4043
|
|
|
3329
4044
|
case 2:
|
|
3330
|
-
this.messagesListPromise = this.services.syncClient.list({
|
|
3331
|
-
id:
|
|
4045
|
+
this.messagesListPromise = typeof arg === "string" ? this.services.syncClient.list({
|
|
4046
|
+
id: arg,
|
|
3332
4047
|
mode: "open_existing"
|
|
3333
|
-
});
|
|
4048
|
+
}) : Promise.resolve(arg);
|
|
3334
4049
|
_context.prev = 3;
|
|
3335
4050
|
_context.next = 6;
|
|
3336
4051
|
return this.messagesListPromise;
|
|
@@ -3481,7 +4196,7 @@ var Messages = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
3481
4196
|
return request.cancel();
|
|
3482
4197
|
});
|
|
3483
4198
|
});
|
|
3484
|
-
_iterator = _createForOfIteratorHelper$
|
|
4199
|
+
_iterator = _createForOfIteratorHelper$4(message.mediaContent);
|
|
3485
4200
|
_context3.prev = 4;
|
|
3486
4201
|
|
|
3487
4202
|
_iterator.s();
|
|
@@ -3543,7 +4258,11 @@ var Messages = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
3543
4258
|
media_sids: media.map(function (m) {
|
|
3544
4259
|
return m.sid;
|
|
3545
4260
|
}),
|
|
3546
|
-
attributes: typeof message.attributes !== "undefined" ? JSON.stringify(message.attributes) : undefined
|
|
4261
|
+
attributes: typeof message.attributes !== "undefined" ? JSON.stringify(message.attributes) : undefined,
|
|
4262
|
+
content_sid: message.contentSid,
|
|
4263
|
+
content_variables: typeof message.contentVariables !== "undefined" ? JSON.stringify(message.contentVariables.reduce(function (accum, current) {
|
|
4264
|
+
return _objectSpread$3(_objectSpread$3({}, accum), {}, _defineProperty__default["default"]({}, current.name, current.value));
|
|
4265
|
+
}, {})) : undefined
|
|
3547
4266
|
});
|
|
3548
4267
|
_context3.prev = 34;
|
|
3549
4268
|
_context3.t4 = resolve;
|
|
@@ -4014,6 +4733,29 @@ var MessageBuilder = /*#__PURE__*/function () {
|
|
|
4014
4733
|
this.emailHistories.set(contentType, history);
|
|
4015
4734
|
return this;
|
|
4016
4735
|
}
|
|
4736
|
+
/**
|
|
4737
|
+
* Adds {@link ContentTemplate} SID for the message alongside optional
|
|
4738
|
+
* variables. When no variables provided, the default values will be used.
|
|
4739
|
+
*
|
|
4740
|
+
* Adding the content SID converts the message to a rich message. In this
|
|
4741
|
+
* case, other fields are ignored and the message is sent using the content
|
|
4742
|
+
* from the the {@link ContentTemplate}.
|
|
4743
|
+
*
|
|
4744
|
+
* Use {@link Client.getContentTemplates} to request all available
|
|
4745
|
+
* {@link ContentTemplate}s.
|
|
4746
|
+
*
|
|
4747
|
+
* @param contentSid SID of the {@link ContentTemplate}
|
|
4748
|
+
* @param variables Custom variables to resolve the template.
|
|
4749
|
+
*/
|
|
4750
|
+
|
|
4751
|
+
}, {
|
|
4752
|
+
key: "setContentTemplate",
|
|
4753
|
+
value: function setContentTemplate(contentSid) {
|
|
4754
|
+
var contentVariables = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
4755
|
+
this.message.contentSid = contentSid;
|
|
4756
|
+
this.message.contentVariables = contentVariables;
|
|
4757
|
+
return this;
|
|
4758
|
+
}
|
|
4017
4759
|
/**
|
|
4018
4760
|
* Adds media to the message.
|
|
4019
4761
|
* @param payload Media to add.
|
|
@@ -4088,29 +4830,34 @@ var MessageBuilder = /*#__PURE__*/function () {
|
|
|
4088
4830
|
value: function buildAndSend() {
|
|
4089
4831
|
return this.build().send();
|
|
4090
4832
|
}
|
|
4091
|
-
}, {
|
|
4092
|
-
key: "getPayloadContentType",
|
|
4093
|
-
value: function getPayloadContentType(payload) {
|
|
4094
|
-
if (typeof FormData !== "undefined" && payload instanceof FormData) {
|
|
4095
|
-
return payload.get("Content-Type");
|
|
4096
|
-
}
|
|
4097
|
-
|
|
4098
|
-
return payload.contentType;
|
|
4099
|
-
}
|
|
4100
4833
|
}]);
|
|
4101
4834
|
|
|
4102
4835
|
return MessageBuilder;
|
|
4103
4836
|
}();
|
|
4104
4837
|
|
|
4105
|
-
|
|
4838
|
+
__decorate([declarativeTypeValidator.validateTypes("string"), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", MessageBuilder)], MessageBuilder.prototype, "setBody", null);
|
|
4106
4839
|
|
|
4107
|
-
|
|
4840
|
+
__decorate([declarativeTypeValidator.validateTypes("string"), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", MessageBuilder)], MessageBuilder.prototype, "setSubject", null);
|
|
4108
4841
|
|
|
4109
|
-
|
|
4842
|
+
__decorate([declarativeTypeValidator.validateTypes(json), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", MessageBuilder)], MessageBuilder.prototype, "setAttributes", null);
|
|
4110
4843
|
|
|
4111
|
-
|
|
4844
|
+
__decorate([declarativeTypeValidator.validateTypes("string", [FormData, sendMediaOptions]), __metadata("design:type", Function), __metadata("design:paramtypes", [String, Object]), __metadata("design:returntype", MessageBuilder)], MessageBuilder.prototype, "setEmailBody", null);
|
|
4112
4845
|
|
|
4113
|
-
|
|
4846
|
+
__decorate([declarativeTypeValidator.validateTypes("string", [FormData, sendMediaOptions]), __metadata("design:type", Function), __metadata("design:paramtypes", [String, Object]), __metadata("design:returntype", MessageBuilder)], MessageBuilder.prototype, "setEmailHistory", null);
|
|
4847
|
+
|
|
4848
|
+
__decorate([declarativeTypeValidator.validateTypes("string", [declarativeTypeValidator.array("content variables", ContentTemplateVariable), "undefined"]), __metadata("design:type", Function), __metadata("design:paramtypes", [String, Array]), __metadata("design:returntype", MessageBuilder)], MessageBuilder.prototype, "setContentTemplate", null);
|
|
4849
|
+
|
|
4850
|
+
__decorate([declarativeTypeValidator.validateTypes([FormData, sendMediaOptions]), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", MessageBuilder)], MessageBuilder.prototype, "addMedia", null);
|
|
4851
|
+
|
|
4852
|
+
function _createForOfIteratorHelper$3(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$3(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
4853
|
+
|
|
4854
|
+
function _unsupportedIterableToArray$3(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$3(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$3(o, minLen); }
|
|
4855
|
+
|
|
4856
|
+
function _arrayLikeToArray$3(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
4857
|
+
|
|
4858
|
+
function _createSuper$4(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$4(); return function _createSuperInternal() { var Super = _getPrototypeOf__default["default"](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default["default"](this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default["default"](this, result); }; }
|
|
4859
|
+
|
|
4860
|
+
function _isNativeReflectConstruct$4() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
4114
4861
|
/**
|
|
4115
4862
|
* Map of the fields that will be processed with update messages.
|
|
4116
4863
|
*/
|
|
@@ -4138,7 +4885,7 @@ var fieldMappings = {
|
|
|
4138
4885
|
var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
4139
4886
|
_inherits__default["default"](Conversation, _ReplayEventEmitter);
|
|
4140
4887
|
|
|
4141
|
-
var _super = _createSuper$
|
|
4888
|
+
var _super = _createSuper$4(Conversation);
|
|
4142
4889
|
|
|
4143
4890
|
/**
|
|
4144
4891
|
* Fired when a participant has joined the conversation.
|
|
@@ -4244,24 +4991,86 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
4244
4991
|
*/
|
|
4245
4992
|
|
|
4246
4993
|
/**
|
|
4247
|
-
*
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
*
|
|
4994
|
+
* Unique system identifier of the conversation.
|
|
4995
|
+
*/
|
|
4996
|
+
|
|
4997
|
+
/**
|
|
4998
|
+
* Conversation links for REST requests.
|
|
4252
4999
|
* @internal
|
|
4253
5000
|
*/
|
|
4254
|
-
function Conversation(descriptor, sid, links, configuration, services) {
|
|
4255
|
-
var _descriptor$attribute, _descriptor$bindings;
|
|
4256
5001
|
|
|
4257
|
-
|
|
5002
|
+
/**
|
|
5003
|
+
* Configuration of the client that the conversation belongs to.
|
|
5004
|
+
*/
|
|
4258
5005
|
|
|
4259
|
-
|
|
5006
|
+
/**
|
|
5007
|
+
* Conversation service objects.
|
|
5008
|
+
*/
|
|
4260
5009
|
|
|
4261
|
-
|
|
4262
|
-
|
|
4263
|
-
|
|
4264
|
-
|
|
5010
|
+
/**
|
|
5011
|
+
* Internal state of the conversation.
|
|
5012
|
+
*/
|
|
5013
|
+
|
|
5014
|
+
/**
|
|
5015
|
+
* Name of the conversation entity document.
|
|
5016
|
+
*/
|
|
5017
|
+
|
|
5018
|
+
/**
|
|
5019
|
+
* Messages entity.
|
|
5020
|
+
*/
|
|
5021
|
+
|
|
5022
|
+
/**
|
|
5023
|
+
* Sync list containing messages.
|
|
5024
|
+
*/
|
|
5025
|
+
|
|
5026
|
+
/**
|
|
5027
|
+
* Map of participants.
|
|
5028
|
+
* @internal
|
|
5029
|
+
*/
|
|
5030
|
+
|
|
5031
|
+
/**
|
|
5032
|
+
* Participants entity.
|
|
5033
|
+
*/
|
|
5034
|
+
|
|
5035
|
+
/**
|
|
5036
|
+
* Sync map containing participants.
|
|
5037
|
+
*/
|
|
5038
|
+
|
|
5039
|
+
/**
|
|
5040
|
+
* Source of the most recent update.
|
|
5041
|
+
*/
|
|
5042
|
+
|
|
5043
|
+
/**
|
|
5044
|
+
* Promise for the conversation entity document.
|
|
5045
|
+
*/
|
|
5046
|
+
|
|
5047
|
+
/**
|
|
5048
|
+
* Promise for the messages list.
|
|
5049
|
+
*/
|
|
5050
|
+
|
|
5051
|
+
/**
|
|
5052
|
+
* Conversation entity document.
|
|
5053
|
+
*/
|
|
5054
|
+
|
|
5055
|
+
/**
|
|
5056
|
+
* @param descriptor Conversation descriptor.
|
|
5057
|
+
* @param sid Conversation SID.
|
|
5058
|
+
* @param links Conversation links for REST requests.
|
|
5059
|
+
* @param configuration Client configuration.
|
|
5060
|
+
* @param services Conversation services.
|
|
5061
|
+
* @internal
|
|
5062
|
+
*/
|
|
5063
|
+
function Conversation(descriptor, sid, links, configuration, services) {
|
|
5064
|
+
var _descriptor$attribute, _descriptor$bindings;
|
|
5065
|
+
|
|
5066
|
+
var _this;
|
|
5067
|
+
|
|
5068
|
+
_classCallCheck__default["default"](this, Conversation);
|
|
5069
|
+
|
|
5070
|
+
_this = _super.call(this);
|
|
5071
|
+
_this.sid = sid;
|
|
5072
|
+
_this._links = links;
|
|
5073
|
+
_this._configuration = configuration;
|
|
4265
5074
|
_this._services = services;
|
|
4266
5075
|
_this._entityName = descriptor.channel;
|
|
4267
5076
|
_this._internalState = {
|
|
@@ -4284,32 +5093,39 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
4284
5093
|
participants: _this._links.participants
|
|
4285
5094
|
};
|
|
4286
5095
|
_this._participants = new Map();
|
|
4287
|
-
_this._participantsEntity = new Participants(_assertThisInitialized__default["default"](_this), _this._participants,
|
|
5096
|
+
_this._participantsEntity = new Participants(_assertThisInitialized__default["default"](_this), _this._participants, // state leak
|
|
5097
|
+
participantsLinks, _this._services);
|
|
4288
5098
|
|
|
4289
|
-
_this._participantsEntity.on(
|
|
4290
|
-
return
|
|
5099
|
+
_this._participantsEntity.on(Conversation.participantJoined, function (participant) {
|
|
5100
|
+
return (// @todo update participants map here??
|
|
5101
|
+
_this.emit(Conversation.participantJoined, participant)
|
|
5102
|
+
);
|
|
4291
5103
|
});
|
|
4292
5104
|
|
|
4293
|
-
_this._participantsEntity.on(
|
|
4294
|
-
return
|
|
5105
|
+
_this._participantsEntity.on(Conversation.participantLeft, function (participant) {
|
|
5106
|
+
return (// @todo update participants map here??
|
|
5107
|
+
_this.emit(Conversation.participantLeft, participant)
|
|
5108
|
+
);
|
|
4295
5109
|
});
|
|
4296
5110
|
|
|
4297
|
-
_this._participantsEntity.on(
|
|
4298
|
-
return
|
|
5111
|
+
_this._participantsEntity.on(Conversation.participantUpdated, function (args) {
|
|
5112
|
+
return (// @todo update participants map here??
|
|
5113
|
+
_this.emit(Conversation.participantUpdated, args)
|
|
5114
|
+
);
|
|
4299
5115
|
});
|
|
4300
5116
|
|
|
4301
5117
|
_this._messagesEntity = new Messages(_assertThisInitialized__default["default"](_this), configuration, services);
|
|
4302
5118
|
|
|
4303
|
-
_this._messagesEntity.on(
|
|
5119
|
+
_this._messagesEntity.on(Conversation.messageAdded, function (message) {
|
|
4304
5120
|
return _this._onMessageAdded(message);
|
|
4305
5121
|
});
|
|
4306
5122
|
|
|
4307
|
-
_this._messagesEntity.on(
|
|
4308
|
-
return _this.emit(
|
|
5123
|
+
_this._messagesEntity.on(Conversation.messageUpdated, function (args) {
|
|
5124
|
+
return _this.emit(Conversation.messageUpdated, args);
|
|
4309
5125
|
});
|
|
4310
5126
|
|
|
4311
|
-
_this._messagesEntity.on(
|
|
4312
|
-
return _this.emit(
|
|
5127
|
+
_this._messagesEntity.on(Conversation.messageRemoved, function (message) {
|
|
5128
|
+
return _this.emit(Conversation.messageRemoved, message);
|
|
4313
5129
|
});
|
|
4314
5130
|
|
|
4315
5131
|
return _this;
|
|
@@ -4412,7 +5228,7 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
4412
5228
|
return (_this$_internalState$3 = this._internalState.notificationLevel) !== null && _this$_internalState$3 !== void 0 ? _this$_internalState$3 : "default";
|
|
4413
5229
|
}
|
|
4414
5230
|
/**
|
|
4415
|
-
* Conversation bindings.
|
|
5231
|
+
* Conversation bindings. An undocumented feature (for now).
|
|
4416
5232
|
* @internal
|
|
4417
5233
|
*/
|
|
4418
5234
|
|
|
@@ -4868,7 +5684,7 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
4868
5684
|
return getMessagesCount;
|
|
4869
5685
|
}()
|
|
4870
5686
|
/**
|
|
4871
|
-
* Get unread messages
|
|
5687
|
+
* Get count of unread messages for the user if they are a participant of this
|
|
4872
5688
|
* conversation. Rejects if the user is not a participant of the conversation.
|
|
4873
5689
|
*
|
|
4874
5690
|
* Use this method to obtain the number of unread messages together with
|
|
@@ -4876,12 +5692,19 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
4876
5692
|
* message indices which may have gaps. See {@link Message.index} for details.
|
|
4877
5693
|
*
|
|
4878
5694
|
* This method is semi-realtime. This means that this data will be eventually
|
|
4879
|
-
* correct, but will also be possibly incorrect for a few seconds. The
|
|
5695
|
+
* correct, but it will also be possibly incorrect for a few seconds. The
|
|
4880
5696
|
* Conversations system does not provide real time events for counter values
|
|
4881
5697
|
* changes.
|
|
4882
5698
|
*
|
|
4883
5699
|
* This is useful for any UI badges, but it is not recommended to build any
|
|
4884
5700
|
* core application logic based on these counters being accurate in real time.
|
|
5701
|
+
*
|
|
5702
|
+
* If the read horizon is not set, this function will return null. This could mean
|
|
5703
|
+
* that all messages in the conversation are unread, or that the read horizon system
|
|
5704
|
+
* is not being used. How to interpret this `null` value is up to the customer application.
|
|
5705
|
+
*
|
|
5706
|
+
* @return Number of unread messages based on the current read horizon set for
|
|
5707
|
+
* the user or `null` if the read horizon is not set.
|
|
4885
5708
|
*/
|
|
4886
5709
|
|
|
4887
5710
|
}, {
|
|
@@ -4986,7 +5809,7 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
4986
5809
|
}
|
|
4987
5810
|
|
|
4988
5811
|
_context14.next = 3;
|
|
4989
|
-
return this._services.commandExecutor.mutateResource("delete", "".concat(this._links.participants, "/").concat(this._configuration.userIdentity));
|
|
5812
|
+
return this._services.commandExecutor.mutateResource("delete", "".concat(this._links.participants, "/").concat(encodeURIComponent(this._configuration.userIdentity)));
|
|
4990
5813
|
|
|
4991
5814
|
case 3:
|
|
4992
5815
|
return _context14.abrupt("return", this);
|
|
@@ -5094,7 +5917,7 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
5094
5917
|
}()
|
|
5095
5918
|
/**
|
|
5096
5919
|
* New interface to prepare for sending a message.
|
|
5097
|
-
* Use this instead of {@link
|
|
5920
|
+
* Use this instead of {@link Conversation.sendMessage}.
|
|
5098
5921
|
* @return A MessageBuilder to help set all message sending options.
|
|
5099
5922
|
*/
|
|
5100
5923
|
|
|
@@ -5154,7 +5977,7 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
5154
5977
|
}()
|
|
5155
5978
|
/**
|
|
5156
5979
|
* Set all messages in the conversation unread.
|
|
5157
|
-
* @
|
|
5980
|
+
* @returns New count of unread messages after this update.
|
|
5158
5981
|
*/
|
|
5159
5982
|
|
|
5160
5983
|
}, {
|
|
@@ -5312,7 +6135,7 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
5312
6135
|
* Set the last read message index to the current read horizon.
|
|
5313
6136
|
* @param index Message index to set as last read. If null is provided, then
|
|
5314
6137
|
* the behavior is identical to {@link Conversation.setAllMessagesUnread}.
|
|
5315
|
-
* @returns
|
|
6138
|
+
* @returns New count of unread messages after this update.
|
|
5316
6139
|
*/
|
|
5317
6140
|
|
|
5318
6141
|
}, {
|
|
@@ -5385,74 +6208,107 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
5385
6208
|
|
|
5386
6209
|
return updateUniqueName;
|
|
5387
6210
|
}()
|
|
6211
|
+
/**
|
|
6212
|
+
* Get recipients of all messages in the conversation.
|
|
6213
|
+
* @param options Optional configuration, set pageSize to request a specific pagination page size. Page size specifies a number of messages to include in a single batch. Each message may include multiple recipients.
|
|
6214
|
+
*/
|
|
6215
|
+
|
|
6216
|
+
}, {
|
|
6217
|
+
key: "getMessageRecipients",
|
|
6218
|
+
value: function () {
|
|
6219
|
+
var _getMessageRecipients = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee24(options) {
|
|
6220
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee24$(_context24) {
|
|
6221
|
+
while (1) {
|
|
6222
|
+
switch (_context24.prev = _context24.next) {
|
|
6223
|
+
case 0:
|
|
6224
|
+
_context24.next = 2;
|
|
6225
|
+
return this._services.messageRecipientsClient.getRecipientsFromConversation(this.sid, options);
|
|
6226
|
+
|
|
6227
|
+
case 2:
|
|
6228
|
+
return _context24.abrupt("return", _context24.sent);
|
|
6229
|
+
|
|
6230
|
+
case 3:
|
|
6231
|
+
case "end":
|
|
6232
|
+
return _context24.stop();
|
|
6233
|
+
}
|
|
6234
|
+
}
|
|
6235
|
+
}, _callee24, this);
|
|
6236
|
+
}));
|
|
6237
|
+
|
|
6238
|
+
function getMessageRecipients(_x19) {
|
|
6239
|
+
return _getMessageRecipients.apply(this, arguments);
|
|
6240
|
+
}
|
|
6241
|
+
|
|
6242
|
+
return getMessageRecipients;
|
|
6243
|
+
}()
|
|
5388
6244
|
/**
|
|
5389
6245
|
* Load and subscribe to this conversation and do not subscribe to its
|
|
5390
6246
|
* participants and messages. This or _subscribeStreams will need to be called
|
|
5391
|
-
* before any events
|
|
6247
|
+
* before any events in the conversation will fire.
|
|
5392
6248
|
* @internal
|
|
5393
6249
|
*/
|
|
5394
6250
|
|
|
5395
6251
|
}, {
|
|
5396
6252
|
key: "_subscribe",
|
|
5397
6253
|
value: function () {
|
|
5398
|
-
var _subscribe2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function
|
|
6254
|
+
var _subscribe2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee25() {
|
|
5399
6255
|
var _this2 = this;
|
|
5400
6256
|
|
|
5401
|
-
return _regeneratorRuntime__default["default"].wrap(function
|
|
6257
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee25$(_context25) {
|
|
5402
6258
|
while (1) {
|
|
5403
|
-
switch (
|
|
6259
|
+
switch (_context25.prev = _context25.next) {
|
|
5404
6260
|
case 0:
|
|
5405
6261
|
if (!this._entityPromise) {
|
|
5406
|
-
|
|
6262
|
+
_context25.next = 2;
|
|
5407
6263
|
break;
|
|
5408
6264
|
}
|
|
5409
6265
|
|
|
5410
|
-
return
|
|
6266
|
+
return _context25.abrupt("return", this._entityPromise);
|
|
5411
6267
|
|
|
5412
6268
|
case 2:
|
|
5413
6269
|
this._entityPromise = this._services.syncClient.document({
|
|
5414
6270
|
id: this._entityName,
|
|
5415
6271
|
mode: "open_existing"
|
|
5416
6272
|
});
|
|
5417
|
-
|
|
5418
|
-
|
|
6273
|
+
_context25.prev = 3;
|
|
6274
|
+
_context25.next = 6;
|
|
5419
6275
|
return this._entityPromise;
|
|
5420
6276
|
|
|
5421
6277
|
case 6:
|
|
5422
|
-
this._entity =
|
|
6278
|
+
this._entity = _context25.sent;
|
|
5423
6279
|
|
|
5424
|
-
this._entity.on(
|
|
6280
|
+
this._entity.on(twilioSync.SyncDocument.updated, function (args) {
|
|
5425
6281
|
return _this2._update(args.data);
|
|
5426
6282
|
});
|
|
5427
6283
|
|
|
5428
|
-
this._entity.on(
|
|
5429
|
-
return _this2.emit(
|
|
6284
|
+
this._entity.on(twilioSync.SyncDocument.removed, function () {
|
|
6285
|
+
return _this2.emit(Conversation.removed, _this2);
|
|
5430
6286
|
});
|
|
5431
6287
|
|
|
5432
6288
|
this._update(this._entity.data);
|
|
5433
6289
|
|
|
5434
|
-
return
|
|
6290
|
+
return _context25.abrupt("return", this._entity);
|
|
5435
6291
|
|
|
5436
6292
|
case 13:
|
|
5437
|
-
|
|
5438
|
-
|
|
6293
|
+
_context25.prev = 13;
|
|
6294
|
+
_context25.t0 = _context25["catch"](3);
|
|
5439
6295
|
this._entity = null;
|
|
5440
6296
|
this._entityPromise = null;
|
|
5441
6297
|
|
|
5442
6298
|
if (this._services.syncClient.connectionState != "disconnected") {
|
|
5443
|
-
Conversation._logger.error("Failed to get conversation object",
|
|
6299
|
+
Conversation._logger.error("Failed to get conversation object", _context25.t0);
|
|
5444
6300
|
}
|
|
5445
6301
|
|
|
5446
|
-
Conversation._logger.debug("ERROR: Failed to get conversation object",
|
|
6302
|
+
Conversation._logger.debug("ERROR: Failed to get conversation object", _context25.t0);
|
|
5447
6303
|
|
|
5448
|
-
throw
|
|
6304
|
+
throw _context25.t0;
|
|
5449
6305
|
|
|
5450
6306
|
case 20:
|
|
5451
6307
|
case "end":
|
|
5452
|
-
return
|
|
6308
|
+
return _context25.stop();
|
|
5453
6309
|
}
|
|
5454
6310
|
}
|
|
5455
|
-
},
|
|
6311
|
+
}, _callee25, this, [[3, 13]]);
|
|
5456
6312
|
}));
|
|
5457
6313
|
|
|
5458
6314
|
function _subscribe() {
|
|
@@ -5461,6 +6317,116 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
5461
6317
|
|
|
5462
6318
|
return _subscribe;
|
|
5463
6319
|
}()
|
|
6320
|
+
/**
|
|
6321
|
+
* Fetch participants and messages of the conversation. This method needs to
|
|
6322
|
+
* be called during conversation initialization to catch broken conversations
|
|
6323
|
+
* (broken conversations are conversations that have essential Sync entities
|
|
6324
|
+
* missing, i.e. the conversation document, the messages list or the
|
|
6325
|
+
* participant map). In case of this conversation being broken, the method
|
|
6326
|
+
* will throw an exception that will be caught and handled gracefully.
|
|
6327
|
+
* @internal
|
|
6328
|
+
*/
|
|
6329
|
+
|
|
6330
|
+
}, {
|
|
6331
|
+
key: "_fetchStreams",
|
|
6332
|
+
value: function () {
|
|
6333
|
+
var _fetchStreams2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee27() {
|
|
6334
|
+
var _this3 = this;
|
|
6335
|
+
|
|
6336
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee27$(_context27) {
|
|
6337
|
+
while (1) {
|
|
6338
|
+
switch (_context27.prev = _context27.next) {
|
|
6339
|
+
case 0:
|
|
6340
|
+
if (!this._streamsPromise) {
|
|
6341
|
+
_context27.next = 2;
|
|
6342
|
+
break;
|
|
6343
|
+
}
|
|
6344
|
+
|
|
6345
|
+
return _context27.abrupt("return", this._streamsPromise);
|
|
6346
|
+
|
|
6347
|
+
case 2:
|
|
6348
|
+
this._streamsPromise = new Promise( /*#__PURE__*/function () {
|
|
6349
|
+
var _ref = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee26(resolve, reject) {
|
|
6350
|
+
var _this3$_entity, _this3$_entity2;
|
|
6351
|
+
|
|
6352
|
+
var data, messagesPromise, participantsPromise;
|
|
6353
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee26$(_context26) {
|
|
6354
|
+
while (1) {
|
|
6355
|
+
switch (_context26.prev = _context26.next) {
|
|
6356
|
+
case 0:
|
|
6357
|
+
_context26.prev = 0;
|
|
6358
|
+
_context26.next = 3;
|
|
6359
|
+
return _this3._subscribe();
|
|
6360
|
+
|
|
6361
|
+
case 3:
|
|
6362
|
+
_context26.next = 9;
|
|
6363
|
+
break;
|
|
6364
|
+
|
|
6365
|
+
case 5:
|
|
6366
|
+
_context26.prev = 5;
|
|
6367
|
+
_context26.t0 = _context26["catch"](0);
|
|
6368
|
+
|
|
6369
|
+
Conversation._logger.trace("Failed to subscribe to conversation", _context26.t0);
|
|
6370
|
+
|
|
6371
|
+
return _context26.abrupt("return", reject(_context26.t0));
|
|
6372
|
+
|
|
6373
|
+
case 9:
|
|
6374
|
+
Conversation._logger.trace("_streamsAvailable, this.entity.data=", (_this3$_entity = _this3._entity) === null || _this3$_entity === void 0 ? void 0 : _this3$_entity.data);
|
|
6375
|
+
|
|
6376
|
+
data = (_this3$_entity2 = _this3._entity) === null || _this3$_entity2 === void 0 ? void 0 : _this3$_entity2.data;
|
|
6377
|
+
messagesPromise = _this3._services.syncClient.list({
|
|
6378
|
+
id: data.messages,
|
|
6379
|
+
mode: "open_existing"
|
|
6380
|
+
}).then(function (list) {
|
|
6381
|
+
_this3._messagesList = list;
|
|
6382
|
+
return list;
|
|
6383
|
+
});
|
|
6384
|
+
participantsPromise = _this3._services.syncClient.map({
|
|
6385
|
+
id: data.roster,
|
|
6386
|
+
mode: "open_existing"
|
|
6387
|
+
}).then(function (map) {
|
|
6388
|
+
_this3._participantsMap = map;
|
|
6389
|
+
return map;
|
|
6390
|
+
});
|
|
6391
|
+
Promise.all([messagesPromise, participantsPromise]).then(function () {
|
|
6392
|
+
return resolve(true);
|
|
6393
|
+
}).catch(function (err) {
|
|
6394
|
+
Conversation._logger.trace("Failed to fetch conversation streams for conversation", _this3.sid, err);
|
|
6395
|
+
|
|
6396
|
+
reject(err);
|
|
6397
|
+
});
|
|
6398
|
+
|
|
6399
|
+
case 14:
|
|
6400
|
+
case "end":
|
|
6401
|
+
return _context26.stop();
|
|
6402
|
+
}
|
|
6403
|
+
}
|
|
6404
|
+
}, _callee26, null, [[0, 5]]);
|
|
6405
|
+
}));
|
|
6406
|
+
|
|
6407
|
+
return function (_x20, _x21) {
|
|
6408
|
+
return _ref.apply(this, arguments);
|
|
6409
|
+
};
|
|
6410
|
+
}());
|
|
6411
|
+
return _context27.abrupt("return", this._streamsPromise.catch(function (err) {
|
|
6412
|
+
_this3._streamsPromise = null;
|
|
6413
|
+
throw err;
|
|
6414
|
+
}));
|
|
6415
|
+
|
|
6416
|
+
case 4:
|
|
6417
|
+
case "end":
|
|
6418
|
+
return _context27.stop();
|
|
6419
|
+
}
|
|
6420
|
+
}
|
|
6421
|
+
}, _callee27, this);
|
|
6422
|
+
}));
|
|
6423
|
+
|
|
6424
|
+
function _fetchStreams() {
|
|
6425
|
+
return _fetchStreams2.apply(this, arguments);
|
|
6426
|
+
}
|
|
6427
|
+
|
|
6428
|
+
return _fetchStreams;
|
|
6429
|
+
}()
|
|
5464
6430
|
/**
|
|
5465
6431
|
* Load the attributes of this conversation and instantiate its participants
|
|
5466
6432
|
* and messages. This or _subscribe will need to be called before any events
|
|
@@ -5472,16 +6438,16 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
5472
6438
|
}, {
|
|
5473
6439
|
key: "_subscribeStreams",
|
|
5474
6440
|
value: function () {
|
|
5475
|
-
var _subscribeStreams2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function
|
|
5476
|
-
var _this$_entity, _this$_entity2, data, messagesObjectName, rosterObjectName;
|
|
6441
|
+
var _subscribeStreams2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee28() {
|
|
6442
|
+
var _this$_entity, _this$_entity2, _this$_messagesList, _this$_participantsMa, data, messagesObjectName, rosterObjectName;
|
|
5477
6443
|
|
|
5478
|
-
return _regeneratorRuntime__default["default"].wrap(function
|
|
6444
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee28$(_context28) {
|
|
5479
6445
|
while (1) {
|
|
5480
|
-
switch (
|
|
6446
|
+
switch (_context28.prev = _context28.next) {
|
|
5481
6447
|
case 0:
|
|
5482
|
-
|
|
5483
|
-
|
|
5484
|
-
return this.
|
|
6448
|
+
_context28.prev = 0;
|
|
6449
|
+
_context28.next = 3;
|
|
6450
|
+
return this._fetchStreams();
|
|
5485
6451
|
|
|
5486
6452
|
case 3:
|
|
5487
6453
|
Conversation._logger.trace("_subscribeStreams, this.entity.data=", (_this$_entity = this._entity) === null || _this$_entity === void 0 ? void 0 : _this$_entity.data);
|
|
@@ -5489,31 +6455,31 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
5489
6455
|
data = (_this$_entity2 = this._entity) === null || _this$_entity2 === void 0 ? void 0 : _this$_entity2.data;
|
|
5490
6456
|
messagesObjectName = data.messages;
|
|
5491
6457
|
rosterObjectName = data.roster;
|
|
5492
|
-
|
|
5493
|
-
return Promise.all([this._messagesEntity.subscribe(messagesObjectName), this._participantsEntity.subscribe(rosterObjectName)]);
|
|
6458
|
+
_context28.next = 9;
|
|
6459
|
+
return Promise.all([this._messagesEntity.subscribe((_this$_messagesList = this._messagesList) !== null && _this$_messagesList !== void 0 ? _this$_messagesList : messagesObjectName), this._participantsEntity.subscribe((_this$_participantsMa = this._participantsMap) !== null && _this$_participantsMa !== void 0 ? _this$_participantsMa : rosterObjectName)]);
|
|
5494
6460
|
|
|
5495
6461
|
case 9:
|
|
5496
|
-
|
|
6462
|
+
_context28.next = 16;
|
|
5497
6463
|
break;
|
|
5498
6464
|
|
|
5499
6465
|
case 11:
|
|
5500
|
-
|
|
5501
|
-
|
|
6466
|
+
_context28.prev = 11;
|
|
6467
|
+
_context28.t0 = _context28["catch"](0);
|
|
5502
6468
|
|
|
5503
6469
|
if (this._services.syncClient.connectionState !== "disconnected") {
|
|
5504
|
-
Conversation._logger.error("Failed to subscribe on conversation objects", this.sid,
|
|
6470
|
+
Conversation._logger.error("Failed to subscribe on conversation objects", this.sid, _context28.t0);
|
|
5505
6471
|
}
|
|
5506
6472
|
|
|
5507
|
-
Conversation._logger.debug("ERROR: Failed to subscribe on conversation objects", this.sid,
|
|
6473
|
+
Conversation._logger.debug("ERROR: Failed to subscribe on conversation objects", this.sid, _context28.t0);
|
|
5508
6474
|
|
|
5509
|
-
throw
|
|
6475
|
+
throw _context28.t0;
|
|
5510
6476
|
|
|
5511
6477
|
case 16:
|
|
5512
6478
|
case "end":
|
|
5513
|
-
return
|
|
6479
|
+
return _context28.stop();
|
|
5514
6480
|
}
|
|
5515
6481
|
}
|
|
5516
|
-
},
|
|
6482
|
+
}, _callee28, this, [[0, 11]]);
|
|
5517
6483
|
}));
|
|
5518
6484
|
|
|
5519
6485
|
function _subscribeStreams() {
|
|
@@ -5530,32 +6496,26 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
5530
6496
|
}, {
|
|
5531
6497
|
key: "_unsubscribe",
|
|
5532
6498
|
value: function () {
|
|
5533
|
-
var _unsubscribe2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function
|
|
5534
|
-
return _regeneratorRuntime__default["default"].wrap(function
|
|
6499
|
+
var _unsubscribe2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee29() {
|
|
6500
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee29$(_context29) {
|
|
5535
6501
|
while (1) {
|
|
5536
|
-
switch (
|
|
6502
|
+
switch (_context29.prev = _context29.next) {
|
|
5537
6503
|
case 0:
|
|
5538
|
-
if (
|
|
5539
|
-
|
|
5540
|
-
break;
|
|
5541
|
-
}
|
|
5542
|
-
|
|
5543
|
-
_context26.next = 3;
|
|
5544
|
-
return this._entity.close();
|
|
6504
|
+
if (this._entity) {
|
|
6505
|
+
this._entity.close();
|
|
5545
6506
|
|
|
5546
|
-
|
|
5547
|
-
|
|
5548
|
-
|
|
6507
|
+
this._entity = null;
|
|
6508
|
+
this._entityPromise = null;
|
|
6509
|
+
}
|
|
5549
6510
|
|
|
5550
|
-
|
|
5551
|
-
return _context26.abrupt("return", Promise.all([this._participantsEntity.unsubscribe(), this._messagesEntity.unsubscribe()]));
|
|
6511
|
+
return _context29.abrupt("return", Promise.all([this._participantsEntity.unsubscribe(), this._messagesEntity.unsubscribe()]));
|
|
5552
6512
|
|
|
5553
|
-
case
|
|
6513
|
+
case 2:
|
|
5554
6514
|
case "end":
|
|
5555
|
-
return
|
|
6515
|
+
return _context29.stop();
|
|
5556
6516
|
}
|
|
5557
6517
|
}
|
|
5558
|
-
},
|
|
6518
|
+
}, _callee29, this);
|
|
5559
6519
|
}));
|
|
5560
6520
|
|
|
5561
6521
|
function _unsubscribe() {
|
|
@@ -5572,7 +6532,7 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
5572
6532
|
}, {
|
|
5573
6533
|
key: "_setStatus",
|
|
5574
6534
|
value: function _setStatus(status, source) {
|
|
5575
|
-
var
|
|
6535
|
+
var _this4 = this;
|
|
5576
6536
|
|
|
5577
6537
|
this._dataSource = source;
|
|
5578
6538
|
|
|
@@ -5586,7 +6546,7 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
5586
6546
|
this._subscribeStreams().catch(function (err) {
|
|
5587
6547
|
Conversation._logger.debug("ERROR while setting conversation status " + status, err);
|
|
5588
6548
|
|
|
5589
|
-
if (
|
|
6549
|
+
if (_this4._services.syncClient.connectionState !== "disconnected") {
|
|
5590
6550
|
throw err;
|
|
5591
6551
|
}
|
|
5592
6552
|
});
|
|
@@ -5598,7 +6558,7 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
5598
6558
|
this._unsubscribe().catch(function (err) {
|
|
5599
6559
|
Conversation._logger.debug("ERROR while setting conversation status " + status, err);
|
|
5600
6560
|
|
|
5601
|
-
if (
|
|
6561
|
+
if (_this4._services.syncClient.connectionState !== "disconnected") {
|
|
5602
6562
|
throw err;
|
|
5603
6563
|
}
|
|
5604
6564
|
});
|
|
@@ -5638,7 +6598,7 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
5638
6598
|
break;
|
|
5639
6599
|
|
|
5640
6600
|
case fieldMappings.attributes:
|
|
5641
|
-
if (
|
|
6601
|
+
if (isEqual(this._internalState.attributes, update.attributes)) {
|
|
5642
6602
|
break;
|
|
5643
6603
|
}
|
|
5644
6604
|
|
|
@@ -5674,7 +6634,7 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
5674
6634
|
updateReasons.add(localKey);
|
|
5675
6635
|
}
|
|
5676
6636
|
|
|
5677
|
-
if (
|
|
6637
|
+
if (isEqual(this._internalState.lastMessage, {})) {
|
|
5678
6638
|
delete this._internalState.lastMessage;
|
|
5679
6639
|
}
|
|
5680
6640
|
|
|
@@ -5687,7 +6647,7 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
5687
6647
|
state.dateUpdated = new Date(state.dateUpdated);
|
|
5688
6648
|
}
|
|
5689
6649
|
|
|
5690
|
-
if (
|
|
6650
|
+
if (isEqual(this._internalState.state, state)) {
|
|
5691
6651
|
break;
|
|
5692
6652
|
}
|
|
5693
6653
|
|
|
@@ -5696,7 +6656,7 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
5696
6656
|
break;
|
|
5697
6657
|
|
|
5698
6658
|
case fieldMappings.bindings:
|
|
5699
|
-
if (
|
|
6659
|
+
if (isEqual(this._internalState.bindings, update.bindings)) {
|
|
5700
6660
|
break;
|
|
5701
6661
|
}
|
|
5702
6662
|
|
|
@@ -5719,7 +6679,7 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
5719
6679
|
}
|
|
5720
6680
|
|
|
5721
6681
|
if (updateReasons.size > 0) {
|
|
5722
|
-
this.emit(
|
|
6682
|
+
this.emit(Conversation.updated, {
|
|
5723
6683
|
conversation: this,
|
|
5724
6684
|
updateReasons: _toConsumableArray__default["default"](updateReasons)
|
|
5725
6685
|
});
|
|
@@ -5732,7 +6692,7 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
5732
6692
|
}, {
|
|
5733
6693
|
key: "_onMessageAdded",
|
|
5734
6694
|
value: function _onMessageAdded(message) {
|
|
5735
|
-
var _iterator = _createForOfIteratorHelper$
|
|
6695
|
+
var _iterator = _createForOfIteratorHelper$3(this._participants.values()),
|
|
5736
6696
|
_step;
|
|
5737
6697
|
|
|
5738
6698
|
try {
|
|
@@ -5751,7 +6711,7 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
5751
6711
|
_iterator.f();
|
|
5752
6712
|
}
|
|
5753
6713
|
|
|
5754
|
-
this.emit(
|
|
6714
|
+
this.emit(Conversation.messageAdded, message);
|
|
5755
6715
|
}
|
|
5756
6716
|
/**
|
|
5757
6717
|
* Set last read message index.
|
|
@@ -5761,30 +6721,30 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
5761
6721
|
}, {
|
|
5762
6722
|
key: "_setLastReadMessageIndex",
|
|
5763
6723
|
value: function () {
|
|
5764
|
-
var _setLastReadMessageIndex2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function
|
|
6724
|
+
var _setLastReadMessageIndex2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee30(index) {
|
|
5765
6725
|
var result;
|
|
5766
|
-
return _regeneratorRuntime__default["default"].wrap(function
|
|
6726
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee30$(_context30) {
|
|
5767
6727
|
while (1) {
|
|
5768
|
-
switch (
|
|
6728
|
+
switch (_context30.prev = _context30.next) {
|
|
5769
6729
|
case 0:
|
|
5770
|
-
|
|
6730
|
+
_context30.next = 2;
|
|
5771
6731
|
return this._services.commandExecutor.mutateResource("post", "".concat(this._configuration.links.myConversations, "/").concat(this.sid), {
|
|
5772
6732
|
last_read_message_index: index
|
|
5773
6733
|
});
|
|
5774
6734
|
|
|
5775
6735
|
case 2:
|
|
5776
|
-
result =
|
|
5777
|
-
return
|
|
6736
|
+
result = _context30.sent;
|
|
6737
|
+
return _context30.abrupt("return", result.unread_messages_count);
|
|
5778
6738
|
|
|
5779
6739
|
case 4:
|
|
5780
6740
|
case "end":
|
|
5781
|
-
return
|
|
6741
|
+
return _context30.stop();
|
|
5782
6742
|
}
|
|
5783
6743
|
}
|
|
5784
|
-
},
|
|
6744
|
+
}, _callee30, this);
|
|
5785
6745
|
}));
|
|
5786
6746
|
|
|
5787
|
-
function _setLastReadMessageIndex(
|
|
6747
|
+
function _setLastReadMessageIndex(_x22) {
|
|
5788
6748
|
return _setLastReadMessageIndex2.apply(this, arguments);
|
|
5789
6749
|
}
|
|
5790
6750
|
|
|
@@ -5806,7 +6766,9 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
5806
6766
|
}
|
|
5807
6767
|
|
|
5808
6768
|
try {
|
|
5809
|
-
|
|
6769
|
+
if (update.dateCreated) {
|
|
6770
|
+
update.dateCreated = new Date(update.dateCreated);
|
|
6771
|
+
}
|
|
5810
6772
|
} catch (e) {
|
|
5811
6773
|
Conversation._logger.warn("Retrieved malformed dateCreated from the server for conversation: " + conversationSid);
|
|
5812
6774
|
|
|
@@ -5814,7 +6776,9 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
5814
6776
|
}
|
|
5815
6777
|
|
|
5816
6778
|
try {
|
|
5817
|
-
|
|
6779
|
+
if (update.dateUpdated) {
|
|
6780
|
+
update.dateUpdated = new Date(update.dateUpdated);
|
|
6781
|
+
}
|
|
5818
6782
|
} catch (e) {
|
|
5819
6783
|
Conversation._logger.warn("Retrieved malformed dateUpdated from the server for conversation: " + conversationSid);
|
|
5820
6784
|
|
|
@@ -5858,9 +6822,9 @@ _defineProperty__default["default"](Conversation, "removed", "removed");
|
|
|
5858
6822
|
|
|
5859
6823
|
_defineProperty__default["default"](Conversation, "_logger", Logger.scope("Conversation"));
|
|
5860
6824
|
|
|
5861
|
-
__decorate([declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyString,
|
|
6825
|
+
__decorate([declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyString, optionalJson), __metadata("design:type", Function), __metadata("design:paramtypes", [String, Object]), __metadata("design:returntype", Promise)], Conversation.prototype, "add", null);
|
|
5862
6826
|
|
|
5863
|
-
__decorate([declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyString, declarativeTypeValidator.nonEmptyString,
|
|
6827
|
+
__decorate([declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyString, declarativeTypeValidator.nonEmptyString, optionalJson, optionalJson), __metadata("design:type", Function), __metadata("design:paramtypes", [String, String, Object, Object]), __metadata("design:returntype", Promise)], Conversation.prototype, "addNonChatParticipant", null);
|
|
5864
6828
|
|
|
5865
6829
|
__decorate([declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonNegativeInteger), __metadata("design:type", Function), __metadata("design:paramtypes", [Number]), __metadata("design:returntype", Promise)], Conversation.prototype, "advanceLastReadMessageIndex", null);
|
|
5866
6830
|
|
|
@@ -5883,13 +6847,13 @@ __decorate([declarativeTypeValidator.validateTypesAsync(["string", FormData, dec
|
|
|
5883
6847
|
|
|
5884
6848
|
return [isValid, "a non-empty string, an instance of Buffer or an instance of Blob"];
|
|
5885
6849
|
})
|
|
5886
|
-
})],
|
|
6850
|
+
})], optionalJson, ["undefined", declarativeTypeValidator.literal(null), declarativeTypeValidator.objectSchema("email attributes", {
|
|
5887
6851
|
subject: [declarativeTypeValidator.nonEmptyString, "undefined"]
|
|
5888
6852
|
})]), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object, Object]), __metadata("design:returntype", Promise)], Conversation.prototype, "sendMessage", null);
|
|
5889
6853
|
|
|
5890
6854
|
__decorate([declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.literal("default", "muted")), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", Promise)], Conversation.prototype, "setUserNotificationLevel", null);
|
|
5891
6855
|
|
|
5892
|
-
__decorate([declarativeTypeValidator.validateTypesAsync(
|
|
6856
|
+
__decorate([declarativeTypeValidator.validateTypesAsync(json), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise)], Conversation.prototype, "updateAttributes", null);
|
|
5893
6857
|
|
|
5894
6858
|
__decorate([declarativeTypeValidator.validateTypesAsync("string"), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", Promise)], Conversation.prototype, "updateFriendlyName", null);
|
|
5895
6859
|
|
|
@@ -5936,19 +6900,19 @@ var Deferred = /*#__PURE__*/function () {
|
|
|
5936
6900
|
return Deferred;
|
|
5937
6901
|
}();
|
|
5938
6902
|
|
|
5939
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
6903
|
+
function _createForOfIteratorHelper$2(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$2(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
5940
6904
|
|
|
5941
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
6905
|
+
function _unsupportedIterableToArray$2(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$2(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$2(o, minLen); }
|
|
5942
6906
|
|
|
5943
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
6907
|
+
function _arrayLikeToArray$2(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
5944
6908
|
|
|
5945
6909
|
function ownKeys$2(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
5946
6910
|
|
|
5947
6911
|
function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$2(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$2(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
5948
6912
|
|
|
5949
|
-
function _createSuper$
|
|
6913
|
+
function _createSuper$3(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$3(); return function _createSuperInternal() { var Super = _getPrototypeOf__default["default"](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default["default"](this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default["default"](this, result); }; }
|
|
5950
6914
|
|
|
5951
|
-
function _isNativeReflectConstruct$
|
|
6915
|
+
function _isNativeReflectConstruct$3() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
5952
6916
|
var log$1 = Logger.scope("Conversations");
|
|
5953
6917
|
/**
|
|
5954
6918
|
* Represents conversations collection
|
|
@@ -5958,7 +6922,7 @@ var log$1 = Logger.scope("Conversations");
|
|
|
5958
6922
|
var Conversations = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
5959
6923
|
_inherits__default["default"](Conversations, _ReplayEventEmitter);
|
|
5960
6924
|
|
|
5961
|
-
var _super = _createSuper$
|
|
6925
|
+
var _super = _createSuper$3(Conversations);
|
|
5962
6926
|
|
|
5963
6927
|
function Conversations(configuration, services) {
|
|
5964
6928
|
var _this;
|
|
@@ -5996,6 +6960,7 @@ var Conversations = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
5996
6960
|
return this.services.commandExecutor.mutateResource("post", this.configuration.links.conversations, {
|
|
5997
6961
|
friendly_name: options.friendlyName,
|
|
5998
6962
|
unique_name: options.uniqueName,
|
|
6963
|
+
access: options.access,
|
|
5999
6964
|
attributes: typeof attributes !== "undefined" ? JSON.stringify(attributes) : undefined
|
|
6000
6965
|
});
|
|
6001
6966
|
|
|
@@ -6057,7 +7022,7 @@ var Conversations = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
6057
7022
|
return addConversation;
|
|
6058
7023
|
}()
|
|
6059
7024
|
/**
|
|
6060
|
-
* Fetch conversations list and instantiate all necessary objects
|
|
7025
|
+
* Fetch conversations' list and instantiate all necessary objects
|
|
6061
7026
|
*/
|
|
6062
7027
|
|
|
6063
7028
|
}, {
|
|
@@ -6078,12 +7043,12 @@ var Conversations = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
6078
7043
|
|
|
6079
7044
|
case 3:
|
|
6080
7045
|
map = _context2.sent;
|
|
6081
|
-
map.on(
|
|
7046
|
+
map.on(twilioSync.SyncMap.itemAdded, function (args) {
|
|
6082
7047
|
log$1.debug("itemAdded: ".concat(args.item.key));
|
|
6083
7048
|
|
|
6084
7049
|
_this2._upsertConversation("sync", args.item.key, args.item.data);
|
|
6085
7050
|
});
|
|
6086
|
-
map.on(
|
|
7051
|
+
map.on(twilioSync.SyncMap.itemRemoved, function (args) {
|
|
6087
7052
|
log$1.debug("itemRemoved: ".concat(args.key));
|
|
6088
7053
|
var sid = args.key;
|
|
6089
7054
|
|
|
@@ -6109,7 +7074,7 @@ var Conversations = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
6109
7074
|
|
|
6110
7075
|
conversation.emit("removed", conversation);
|
|
6111
7076
|
});
|
|
6112
|
-
map.on(
|
|
7077
|
+
map.on(twilioSync.SyncMap.itemUpdated, function (args) {
|
|
6113
7078
|
log$1.debug("itemUpdated: ".concat(args.item.key));
|
|
6114
7079
|
|
|
6115
7080
|
_this2._upsertConversation("sync", args.item.key, args.item.data);
|
|
@@ -6120,7 +7085,7 @@ var Conversations = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
6120
7085
|
case 9:
|
|
6121
7086
|
myConversations = _context2.sent;
|
|
6122
7087
|
upserts = [];
|
|
6123
|
-
_iterator = _createForOfIteratorHelper(myConversations);
|
|
7088
|
+
_iterator = _createForOfIteratorHelper$2(myConversations);
|
|
6124
7089
|
|
|
6125
7090
|
try {
|
|
6126
7091
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
@@ -6280,6 +7245,8 @@ var Conversations = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
6280
7245
|
createdBy: body.created_by,
|
|
6281
7246
|
attributes: body.attributes,
|
|
6282
7247
|
channel: body.sync_objects.conversation,
|
|
7248
|
+
roster: body.sync_objects.participants,
|
|
7249
|
+
messages: body.sync_objects.messages,
|
|
6283
7250
|
notificationLevel: body === null || body === void 0 ? void 0 : body.notification_level,
|
|
6284
7251
|
sid: sid
|
|
6285
7252
|
};
|
|
@@ -6325,8 +7292,10 @@ var Conversations = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
6325
7292
|
uniqueName: body.unique_name,
|
|
6326
7293
|
createdBy: body.created_by,
|
|
6327
7294
|
attributes: body.attributes,
|
|
6328
|
-
channel: "".concat(sid, ".channel"),
|
|
6329
|
-
|
|
7295
|
+
channel: body.sync_objects.conversation || "".concat(sid, ".channel"),
|
|
7296
|
+
roster: body.sync_objects.participants,
|
|
7297
|
+
messages: body.sync_objects.messages,
|
|
7298
|
+
notificationLevel: body === null || body === void 0 ? void 0 : body.notification_level,
|
|
6330
7299
|
sid: sid
|
|
6331
7300
|
};
|
|
6332
7301
|
return _context6.abrupt("return", this._upsertConversation("sync", sid, data));
|
|
@@ -6393,7 +7362,9 @@ var Conversations = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
6393
7362
|
case 2:
|
|
6394
7363
|
items = _context8.sent;
|
|
6395
7364
|
return _context8.abrupt("return", {
|
|
6396
|
-
items: items
|
|
7365
|
+
items: items.filter(function (item) {
|
|
7366
|
+
return item !== null;
|
|
7367
|
+
}),
|
|
6397
7368
|
hasNextPage: page.hasNextPage,
|
|
6398
7369
|
hasPrevPage: page.hasPrevPage,
|
|
6399
7370
|
nextPage: function nextPage() {
|
|
@@ -6464,7 +7435,7 @@ var Conversations = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
6464
7435
|
updateData.lastConsumedMessageIndex = data.lastConsumedMessageIndex;
|
|
6465
7436
|
}
|
|
6466
7437
|
|
|
6467
|
-
if (!
|
|
7438
|
+
if (!isEqual(updateData, {})) {
|
|
6468
7439
|
conversation._update(updateData);
|
|
6469
7440
|
}
|
|
6470
7441
|
|
|
@@ -6555,7 +7526,7 @@ var Conversations = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
6555
7526
|
break;
|
|
6556
7527
|
}
|
|
6557
7528
|
|
|
6558
|
-
log$1.trace("upsertChannel: the
|
|
7529
|
+
log$1.trace("upsertChannel: the conversation is deleted but reappeared again from REST, ignoring", sid);
|
|
6559
7530
|
return _context10.abrupt("return", null);
|
|
6560
7531
|
|
|
6561
7532
|
case 12:
|
|
@@ -6569,10 +7540,40 @@ var Conversations = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
6569
7540
|
};
|
|
6570
7541
|
newConversation = new Conversation(data, sid, links, this.configuration, this.services);
|
|
6571
7542
|
this.conversations.set(sid, newConversation);
|
|
6572
|
-
_context10.
|
|
7543
|
+
_context10.prev = 17;
|
|
7544
|
+
_context10.next = 20;
|
|
6573
7545
|
return newConversation._subscribe();
|
|
6574
7546
|
|
|
6575
|
-
case
|
|
7547
|
+
case 20:
|
|
7548
|
+
if (!(data.status === "joined")) {
|
|
7549
|
+
_context10.next = 23;
|
|
7550
|
+
break;
|
|
7551
|
+
}
|
|
7552
|
+
|
|
7553
|
+
_context10.next = 23;
|
|
7554
|
+
return newConversation._fetchStreams();
|
|
7555
|
+
|
|
7556
|
+
case 23:
|
|
7557
|
+
_context10.next = 32;
|
|
7558
|
+
break;
|
|
7559
|
+
|
|
7560
|
+
case 25:
|
|
7561
|
+
_context10.prev = 25;
|
|
7562
|
+
_context10.t0 = _context10["catch"](17);
|
|
7563
|
+
|
|
7564
|
+
if (!(_context10.t0.name !== "SyncError")) {
|
|
7565
|
+
_context10.next = 29;
|
|
7566
|
+
break;
|
|
7567
|
+
}
|
|
7568
|
+
|
|
7569
|
+
throw _context10.t0;
|
|
7570
|
+
|
|
7571
|
+
case 29:
|
|
7572
|
+
log$1.trace("upsertChannel: the conversation is missing some Sync entity(ies), ignoring", sid, _context10.t0);
|
|
7573
|
+
this.conversations.delete(sid);
|
|
7574
|
+
return _context10.abrupt("return", null);
|
|
7575
|
+
|
|
7576
|
+
case 32:
|
|
6576
7577
|
this._registerForEvents(newConversation);
|
|
6577
7578
|
|
|
6578
7579
|
this.emit("conversationAdded", newConversation);
|
|
@@ -6585,12 +7586,12 @@ var Conversations = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
6585
7586
|
|
|
6586
7587
|
return _context10.abrupt("return", newConversation);
|
|
6587
7588
|
|
|
6588
|
-
case
|
|
7589
|
+
case 36:
|
|
6589
7590
|
case "end":
|
|
6590
7591
|
return _context10.stop();
|
|
6591
7592
|
}
|
|
6592
7593
|
}
|
|
6593
|
-
}, _callee10, this);
|
|
7594
|
+
}, _callee10, this, [[17, 25]]);
|
|
6594
7595
|
}));
|
|
6595
7596
|
|
|
6596
7597
|
function _upsertConversation(_x10, _x11, _x12) {
|
|
@@ -6631,7 +7632,7 @@ var Conversations = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
6631
7632
|
status: conversationDescriptor.status,
|
|
6632
7633
|
channel: conversationDescriptor.sync_objects.conversation,
|
|
6633
7634
|
messages: conversationDescriptor.sync_objects.messages,
|
|
6634
|
-
roster: "".concat(conversationDescriptor.conversation_sid, ".roster"),
|
|
7635
|
+
roster: conversationDescriptor.sync_objects.participants || "".concat(conversationDescriptor.conversation_sid, ".roster"),
|
|
6635
7636
|
lastConsumedMessageIndex: conversationDescriptor.last_read_message_index,
|
|
6636
7637
|
notificationLevel: conversationDescriptor.notification_level
|
|
6637
7638
|
};
|
|
@@ -6713,9 +7714,9 @@ var Conversations = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
|
6713
7714
|
return Conversations;
|
|
6714
7715
|
}(replayEventEmitter.ReplayEventEmitter);
|
|
6715
7716
|
|
|
6716
|
-
function _createSuper$
|
|
7717
|
+
function _createSuper$2(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$2(); return function _createSuperInternal() { var Super = _getPrototypeOf__default["default"](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default["default"](this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default["default"](this, result); }; }
|
|
6717
7718
|
|
|
6718
|
-
function _isNativeReflectConstruct$
|
|
7719
|
+
function _isNativeReflectConstruct$2() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
6719
7720
|
/**
|
|
6720
7721
|
* Container for known users
|
|
6721
7722
|
*/
|
|
@@ -6723,7 +7724,7 @@ function _isNativeReflectConstruct$1() { if (typeof Reflect === "undefined" || !
|
|
|
6723
7724
|
var Users = /*#__PURE__*/function (_ReplayEventEmitter) {
|
|
6724
7725
|
_inherits__default["default"](Users, _ReplayEventEmitter);
|
|
6725
7726
|
|
|
6726
|
-
var _super = _createSuper$
|
|
7727
|
+
var _super = _createSuper$2(Users);
|
|
6727
7728
|
|
|
6728
7729
|
function Users(myself, configuration, services) {
|
|
6729
7730
|
var _this;
|
|
@@ -7054,7 +8055,7 @@ var TypingIndicator = /*#__PURE__*/function () {
|
|
|
7054
8055
|
}
|
|
7055
8056
|
|
|
7056
8057
|
conversation._participants.forEach(function (participant) {
|
|
7057
|
-
if (participant.identity !== message.identity) {
|
|
8058
|
+
if (participant.identity !== message.identity && participant.type !== "apple") {
|
|
7058
8059
|
return;
|
|
7059
8060
|
}
|
|
7060
8061
|
|
|
@@ -7170,12 +8171,16 @@ function PushNotification(data) {
|
|
|
7170
8171
|
this.data = data.data || {};
|
|
7171
8172
|
});
|
|
7172
8173
|
|
|
7173
|
-
var version = "3.0.0
|
|
8174
|
+
var version = "3.0.0";
|
|
7174
8175
|
|
|
7175
8176
|
function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
7176
8177
|
|
|
7177
8178
|
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$1(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
7178
8179
|
|
|
8180
|
+
function _createSuper$1(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$1(); return function _createSuperInternal() { var Super = _getPrototypeOf__default["default"](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default["default"](this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default["default"](this, result); }; }
|
|
8181
|
+
|
|
8182
|
+
function _isNativeReflectConstruct$1() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
8183
|
+
|
|
7179
8184
|
var trimSlashes = function trimSlashes(url) {
|
|
7180
8185
|
return url.replace(/(^\/+|\/+$)/g, "");
|
|
7181
8186
|
};
|
|
@@ -7184,6 +8189,20 @@ var isMutationConflictResponse = function isMutationConflictResponse(response) {
|
|
|
7184
8189
|
return response.status.code === 202;
|
|
7185
8190
|
};
|
|
7186
8191
|
|
|
8192
|
+
var ChannelMetadataNotFoundError = /*#__PURE__*/function (_Error) {
|
|
8193
|
+
_inherits__default["default"](ChannelMetadataNotFoundError, _Error);
|
|
8194
|
+
|
|
8195
|
+
var _super = _createSuper$1(ChannelMetadataNotFoundError);
|
|
8196
|
+
|
|
8197
|
+
function ChannelMetadataNotFoundError(message) {
|
|
8198
|
+
_classCallCheck__default["default"](this, ChannelMetadataNotFoundError);
|
|
8199
|
+
|
|
8200
|
+
return _super.call(this, message);
|
|
8201
|
+
}
|
|
8202
|
+
|
|
8203
|
+
return _createClass__default["default"](ChannelMetadataNotFoundError);
|
|
8204
|
+
}( /*#__PURE__*/_wrapNativeSuper__default["default"](Error));
|
|
8205
|
+
|
|
7187
8206
|
var CommandExecutor = /*#__PURE__*/function () {
|
|
7188
8207
|
function CommandExecutor(_serviceUrl, _services, _productId) {
|
|
7189
8208
|
_classCallCheck__default["default"](this, CommandExecutor);
|
|
@@ -7233,144 +8252,998 @@ var CommandExecutor = /*#__PURE__*/function () {
|
|
|
7233
8252
|
_context.next = 9;
|
|
7234
8253
|
return this._services.transport.get(getUrl, finalHeaders, this._productId);
|
|
7235
8254
|
|
|
7236
|
-
case 9:
|
|
7237
|
-
response = _context.sent;
|
|
7238
|
-
return _context.abrupt("break", 19);
|
|
8255
|
+
case 9:
|
|
8256
|
+
response = _context.sent;
|
|
8257
|
+
return _context.abrupt("break", 19);
|
|
8258
|
+
|
|
8259
|
+
case 11:
|
|
8260
|
+
_context.next = 13;
|
|
8261
|
+
return this._services.transport.post(preProcessedUrl, finalHeaders, JSON.stringify(requestBody), this._productId);
|
|
8262
|
+
|
|
8263
|
+
case 13:
|
|
8264
|
+
response = _context.sent;
|
|
8265
|
+
return _context.abrupt("break", 19);
|
|
8266
|
+
|
|
8267
|
+
case 15:
|
|
8268
|
+
_context.next = 17;
|
|
8269
|
+
return this._services.transport.delete(preProcessedUrl, finalHeaders, {}, this._productId);
|
|
8270
|
+
|
|
8271
|
+
case 17:
|
|
8272
|
+
response = _context.sent;
|
|
8273
|
+
return _context.abrupt("break", 19);
|
|
8274
|
+
|
|
8275
|
+
case 19:
|
|
8276
|
+
if (!(response.status.code < 200 || response.status.code >= 300)) {
|
|
8277
|
+
_context.next = 21;
|
|
8278
|
+
break;
|
|
8279
|
+
}
|
|
8280
|
+
|
|
8281
|
+
throw new Error("Request responded with a non-success code ".concat(response.status.code));
|
|
8282
|
+
|
|
8283
|
+
case 21:
|
|
8284
|
+
return _context.abrupt("return", response);
|
|
8285
|
+
|
|
8286
|
+
case 22:
|
|
8287
|
+
case "end":
|
|
8288
|
+
return _context.stop();
|
|
8289
|
+
}
|
|
8290
|
+
}
|
|
8291
|
+
}, _callee, this);
|
|
8292
|
+
}));
|
|
8293
|
+
|
|
8294
|
+
function _makeRequest(_x, _x2, _x3, _x4) {
|
|
8295
|
+
return _makeRequest2.apply(this, arguments);
|
|
8296
|
+
}
|
|
8297
|
+
|
|
8298
|
+
return _makeRequest;
|
|
8299
|
+
}()
|
|
8300
|
+
}, {
|
|
8301
|
+
key: "fetchResource",
|
|
8302
|
+
value: function () {
|
|
8303
|
+
var _fetchResource = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee3(url, requestBody) {
|
|
8304
|
+
var _this = this;
|
|
8305
|
+
|
|
8306
|
+
var maxAttemptsCount, retrier, resolution;
|
|
8307
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee3$(_context3) {
|
|
8308
|
+
while (1) {
|
|
8309
|
+
switch (_context3.prev = _context3.next) {
|
|
8310
|
+
case 0:
|
|
8311
|
+
maxAttemptsCount = 6;
|
|
8312
|
+
retrier = new operationRetrier.AsyncRetrier({
|
|
8313
|
+
min: 50,
|
|
8314
|
+
max: 1600,
|
|
8315
|
+
maxAttemptsCount: maxAttemptsCount
|
|
8316
|
+
});
|
|
8317
|
+
_context3.prev = 2;
|
|
8318
|
+
_context3.next = 5;
|
|
8319
|
+
return retrier.run( /*#__PURE__*/_asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2() {
|
|
8320
|
+
var response, _e$body, _e$body2;
|
|
8321
|
+
|
|
8322
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee2$(_context2) {
|
|
8323
|
+
while (1) {
|
|
8324
|
+
switch (_context2.prev = _context2.next) {
|
|
8325
|
+
case 0:
|
|
8326
|
+
_context2.prev = 0;
|
|
8327
|
+
_context2.next = 3;
|
|
8328
|
+
return _this._makeRequest("get", url, requestBody);
|
|
8329
|
+
|
|
8330
|
+
case 3:
|
|
8331
|
+
response = _context2.sent;
|
|
8332
|
+
return _context2.abrupt("return", {
|
|
8333
|
+
type: "success",
|
|
8334
|
+
data: response.body
|
|
8335
|
+
});
|
|
8336
|
+
|
|
8337
|
+
case 7:
|
|
8338
|
+
_context2.prev = 7;
|
|
8339
|
+
_context2.t0 = _context2["catch"](0);
|
|
8340
|
+
|
|
8341
|
+
if (!((_context2.t0 === null || _context2.t0 === void 0 ? void 0 : (_e$body = _context2.t0.body) === null || _e$body === void 0 ? void 0 : _e$body.status) === 404 && (_context2.t0 === null || _context2.t0 === void 0 ? void 0 : (_e$body2 = _context2.t0.body) === null || _e$body2 === void 0 ? void 0 : _e$body2.code) === 50530)) {
|
|
8342
|
+
_context2.next = 11;
|
|
8343
|
+
break;
|
|
8344
|
+
}
|
|
8345
|
+
|
|
8346
|
+
return _context2.abrupt("return", {
|
|
8347
|
+
type: "noMetadata"
|
|
8348
|
+
});
|
|
8349
|
+
|
|
8350
|
+
case 11:
|
|
8351
|
+
throw _context2.t0;
|
|
8352
|
+
|
|
8353
|
+
case 12:
|
|
8354
|
+
case "end":
|
|
8355
|
+
return _context2.stop();
|
|
8356
|
+
}
|
|
8357
|
+
}
|
|
8358
|
+
}, _callee2, null, [[0, 7]]);
|
|
8359
|
+
})));
|
|
8360
|
+
|
|
8361
|
+
case 5:
|
|
8362
|
+
resolution = _context3.sent;
|
|
8363
|
+
_context3.next = 11;
|
|
8364
|
+
break;
|
|
8365
|
+
|
|
8366
|
+
case 8:
|
|
8367
|
+
_context3.prev = 8;
|
|
8368
|
+
_context3.t0 = _context3["catch"](2);
|
|
8369
|
+
throw new Error("Fetch resource from \"".concat(url, "\" failed."));
|
|
8370
|
+
|
|
8371
|
+
case 11:
|
|
8372
|
+
if (!(resolution.type === "noMetadata")) {
|
|
8373
|
+
_context3.next = 13;
|
|
8374
|
+
break;
|
|
8375
|
+
}
|
|
8376
|
+
|
|
8377
|
+
throw new ChannelMetadataNotFoundError("No metadata found.");
|
|
8378
|
+
|
|
8379
|
+
case 13:
|
|
8380
|
+
return _context3.abrupt("return", resolution.data);
|
|
8381
|
+
|
|
8382
|
+
case 14:
|
|
8383
|
+
case "end":
|
|
8384
|
+
return _context3.stop();
|
|
8385
|
+
}
|
|
8386
|
+
}
|
|
8387
|
+
}, _callee3, null, [[2, 8]]);
|
|
8388
|
+
}));
|
|
8389
|
+
|
|
8390
|
+
function fetchResource(_x5, _x6) {
|
|
8391
|
+
return _fetchResource.apply(this, arguments);
|
|
8392
|
+
}
|
|
8393
|
+
|
|
8394
|
+
return fetchResource;
|
|
8395
|
+
}()
|
|
8396
|
+
}, {
|
|
8397
|
+
key: "mutateResource",
|
|
8398
|
+
value: function () {
|
|
8399
|
+
var _mutateResource = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee4(method, url, requestBody) {
|
|
8400
|
+
var result;
|
|
8401
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee4$(_context4) {
|
|
8402
|
+
while (1) {
|
|
8403
|
+
switch (_context4.prev = _context4.next) {
|
|
8404
|
+
case 0:
|
|
8405
|
+
_context4.next = 2;
|
|
8406
|
+
return this._makeRequest(method, url, requestBody, {
|
|
8407
|
+
"X-Twilio-Mutation-Id": uuid.v4()
|
|
8408
|
+
});
|
|
8409
|
+
|
|
8410
|
+
case 2:
|
|
8411
|
+
result = _context4.sent;
|
|
8412
|
+
|
|
8413
|
+
if (!isMutationConflictResponse(result)) {
|
|
8414
|
+
_context4.next = 7;
|
|
8415
|
+
break;
|
|
8416
|
+
}
|
|
8417
|
+
|
|
8418
|
+
_context4.next = 6;
|
|
8419
|
+
return this.fetchResource(result.body.resource_url);
|
|
8420
|
+
|
|
8421
|
+
case 6:
|
|
8422
|
+
return _context4.abrupt("return", _context4.sent);
|
|
8423
|
+
|
|
8424
|
+
case 7:
|
|
8425
|
+
return _context4.abrupt("return", result.body);
|
|
8426
|
+
|
|
8427
|
+
case 8:
|
|
8428
|
+
case "end":
|
|
8429
|
+
return _context4.stop();
|
|
8430
|
+
}
|
|
8431
|
+
}
|
|
8432
|
+
}, _callee4, this);
|
|
8433
|
+
}));
|
|
8434
|
+
|
|
8435
|
+
function mutateResource(_x7, _x8, _x9) {
|
|
8436
|
+
return _mutateResource.apply(this, arguments);
|
|
8437
|
+
}
|
|
8438
|
+
|
|
8439
|
+
return mutateResource;
|
|
8440
|
+
}()
|
|
8441
|
+
}]);
|
|
8442
|
+
|
|
8443
|
+
return CommandExecutor;
|
|
8444
|
+
}();
|
|
8445
|
+
|
|
8446
|
+
var ContentClient = /*#__PURE__*/function () {
|
|
8447
|
+
function ContentClient(_services) {
|
|
8448
|
+
var _pageSize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 100;
|
|
8449
|
+
|
|
8450
|
+
var _cacheTtlMs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 5000;
|
|
8451
|
+
|
|
8452
|
+
_classCallCheck__default["default"](this, ContentClient);
|
|
8453
|
+
|
|
8454
|
+
_defineProperty__default["default"](this, "_cachedTemplates", null);
|
|
8455
|
+
|
|
8456
|
+
this._services = _services;
|
|
8457
|
+
this._pageSize = _pageSize;
|
|
8458
|
+
this._cacheTtlMs = _cacheTtlMs;
|
|
8459
|
+
}
|
|
8460
|
+
|
|
8461
|
+
_createClass__default["default"](ContentClient, [{
|
|
8462
|
+
key: "getContentTemplates",
|
|
8463
|
+
value: function () {
|
|
8464
|
+
var _getContentTemplates = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee() {
|
|
8465
|
+
var _this = this;
|
|
8466
|
+
|
|
8467
|
+
var _yield$this$_fetchCon, _yield$this$_fetchCon2, templatesPage, nextToken, templates, _yield$this$_fetchCon3, _yield$this$_fetchCon4;
|
|
8468
|
+
|
|
8469
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
|
|
8470
|
+
while (1) {
|
|
8471
|
+
switch (_context.prev = _context.next) {
|
|
8472
|
+
case 0:
|
|
8473
|
+
if (!(this._cachedTemplates !== null)) {
|
|
8474
|
+
_context.next = 2;
|
|
8475
|
+
break;
|
|
8476
|
+
}
|
|
8477
|
+
|
|
8478
|
+
return _context.abrupt("return", this._cachedTemplates);
|
|
8479
|
+
|
|
8480
|
+
case 2:
|
|
8481
|
+
_context.next = 4;
|
|
8482
|
+
return this._fetchContentTemplates();
|
|
8483
|
+
|
|
8484
|
+
case 4:
|
|
8485
|
+
_yield$this$_fetchCon = _context.sent;
|
|
8486
|
+
_yield$this$_fetchCon2 = _slicedToArray__default["default"](_yield$this$_fetchCon, 2);
|
|
8487
|
+
templatesPage = _yield$this$_fetchCon2[0];
|
|
8488
|
+
nextToken = _yield$this$_fetchCon2[1];
|
|
8489
|
+
templates = templatesPage;
|
|
8490
|
+
|
|
8491
|
+
case 9:
|
|
8492
|
+
if (!(nextToken !== null)) {
|
|
8493
|
+
_context.next = 19;
|
|
8494
|
+
break;
|
|
8495
|
+
}
|
|
8496
|
+
|
|
8497
|
+
_context.next = 12;
|
|
8498
|
+
return this._fetchContentTemplates(nextToken);
|
|
8499
|
+
|
|
8500
|
+
case 12:
|
|
8501
|
+
_yield$this$_fetchCon3 = _context.sent;
|
|
8502
|
+
_yield$this$_fetchCon4 = _slicedToArray__default["default"](_yield$this$_fetchCon3, 2);
|
|
8503
|
+
templatesPage = _yield$this$_fetchCon4[0];
|
|
8504
|
+
nextToken = _yield$this$_fetchCon4[1];
|
|
8505
|
+
templates = [].concat(_toConsumableArray__default["default"](templates), _toConsumableArray__default["default"](templatesPage));
|
|
8506
|
+
_context.next = 9;
|
|
8507
|
+
break;
|
|
8508
|
+
|
|
8509
|
+
case 19:
|
|
8510
|
+
this._cachedTemplates = Object.freeze(templates);
|
|
8511
|
+
setTimeout(function () {
|
|
8512
|
+
_this._cachedTemplates = null;
|
|
8513
|
+
}, this._cacheTtlMs);
|
|
8514
|
+
return _context.abrupt("return", templates);
|
|
8515
|
+
|
|
8516
|
+
case 22:
|
|
8517
|
+
case "end":
|
|
8518
|
+
return _context.stop();
|
|
8519
|
+
}
|
|
8520
|
+
}
|
|
8521
|
+
}, _callee, this);
|
|
8522
|
+
}));
|
|
8523
|
+
|
|
8524
|
+
function getContentTemplates() {
|
|
8525
|
+
return _getContentTemplates.apply(this, arguments);
|
|
8526
|
+
}
|
|
8527
|
+
|
|
8528
|
+
return getContentTemplates;
|
|
8529
|
+
}()
|
|
8530
|
+
}, {
|
|
8531
|
+
key: "_fetchContentTemplates",
|
|
8532
|
+
value: function () {
|
|
8533
|
+
var _fetchContentTemplates2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2(pageToken) {
|
|
8534
|
+
var contentTemplatesUrl, url, response;
|
|
8535
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee2$(_context2) {
|
|
8536
|
+
while (1) {
|
|
8537
|
+
switch (_context2.prev = _context2.next) {
|
|
8538
|
+
case 0:
|
|
8539
|
+
contentTemplatesUrl = "Client/v2/ContentTemplates";
|
|
8540
|
+
url = new UriBuilder(contentTemplatesUrl);
|
|
8541
|
+
url.arg("PageSize", this._pageSize);
|
|
8542
|
+
|
|
8543
|
+
if (pageToken !== undefined) {
|
|
8544
|
+
url.arg("PageToken", pageToken);
|
|
8545
|
+
}
|
|
8546
|
+
|
|
8547
|
+
_context2.next = 6;
|
|
8548
|
+
return this._services.commandExecutor.fetchResource(url.build());
|
|
8549
|
+
|
|
8550
|
+
case 6:
|
|
8551
|
+
response = _context2.sent;
|
|
8552
|
+
return _context2.abrupt("return", [response.templates.map(function (template) {
|
|
8553
|
+
return new ContentTemplate(template);
|
|
8554
|
+
}), response.meta.next_token]);
|
|
8555
|
+
|
|
8556
|
+
case 8:
|
|
8557
|
+
case "end":
|
|
8558
|
+
return _context2.stop();
|
|
8559
|
+
}
|
|
8560
|
+
}
|
|
8561
|
+
}, _callee2, this);
|
|
8562
|
+
}));
|
|
8563
|
+
|
|
8564
|
+
function _fetchContentTemplates(_x) {
|
|
8565
|
+
return _fetchContentTemplates2.apply(this, arguments);
|
|
8566
|
+
}
|
|
8567
|
+
|
|
8568
|
+
return _fetchContentTemplates;
|
|
8569
|
+
}()
|
|
8570
|
+
}]);
|
|
8571
|
+
|
|
8572
|
+
return ContentClient;
|
|
8573
|
+
}();
|
|
8574
|
+
|
|
8575
|
+
function _createForOfIteratorHelper$1(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$1(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
8576
|
+
|
|
8577
|
+
function _unsupportedIterableToArray$1(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$1(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$1(o, minLen); }
|
|
8578
|
+
|
|
8579
|
+
function _arrayLikeToArray$1(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
8580
|
+
|
|
8581
|
+
var QuickLRU = /*#__PURE__*/function (_Symbol$iterator) {
|
|
8582
|
+
function QuickLRU() {
|
|
8583
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
8584
|
+
|
|
8585
|
+
_classCallCheck__default["default"](this, QuickLRU);
|
|
8586
|
+
|
|
8587
|
+
if (!(options.maxSize && options.maxSize > 0)) {
|
|
8588
|
+
throw new TypeError('`maxSize` must be a number greater than 0');
|
|
8589
|
+
}
|
|
8590
|
+
|
|
8591
|
+
this.maxSize = options.maxSize;
|
|
8592
|
+
this.onEviction = options.onEviction;
|
|
8593
|
+
this.cache = new Map();
|
|
8594
|
+
this.oldCache = new Map();
|
|
8595
|
+
this._size = 0;
|
|
8596
|
+
}
|
|
8597
|
+
|
|
8598
|
+
_createClass__default["default"](QuickLRU, [{
|
|
8599
|
+
key: "_set",
|
|
8600
|
+
value: function _set(key, value) {
|
|
8601
|
+
this.cache.set(key, value);
|
|
8602
|
+
this._size++;
|
|
8603
|
+
|
|
8604
|
+
if (this._size >= this.maxSize) {
|
|
8605
|
+
this._size = 0;
|
|
8606
|
+
|
|
8607
|
+
if (typeof this.onEviction === 'function') {
|
|
8608
|
+
var _iterator = _createForOfIteratorHelper$1(this.oldCache.entries()),
|
|
8609
|
+
_step;
|
|
8610
|
+
|
|
8611
|
+
try {
|
|
8612
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
8613
|
+
var _step$value = _slicedToArray__default["default"](_step.value, 2),
|
|
8614
|
+
_key = _step$value[0],
|
|
8615
|
+
_value = _step$value[1];
|
|
8616
|
+
|
|
8617
|
+
this.onEviction(_key, _value);
|
|
8618
|
+
}
|
|
8619
|
+
} catch (err) {
|
|
8620
|
+
_iterator.e(err);
|
|
8621
|
+
} finally {
|
|
8622
|
+
_iterator.f();
|
|
8623
|
+
}
|
|
8624
|
+
}
|
|
8625
|
+
|
|
8626
|
+
this.oldCache = this.cache;
|
|
8627
|
+
this.cache = new Map();
|
|
8628
|
+
}
|
|
8629
|
+
}
|
|
8630
|
+
}, {
|
|
8631
|
+
key: "get",
|
|
8632
|
+
value: function get(key) {
|
|
8633
|
+
if (this.cache.has(key)) {
|
|
8634
|
+
return this.cache.get(key);
|
|
8635
|
+
}
|
|
8636
|
+
|
|
8637
|
+
if (this.oldCache.has(key)) {
|
|
8638
|
+
var value = this.oldCache.get(key);
|
|
8639
|
+
this.oldCache.delete(key);
|
|
8640
|
+
|
|
8641
|
+
this._set(key, value);
|
|
8642
|
+
|
|
8643
|
+
return value;
|
|
8644
|
+
}
|
|
8645
|
+
}
|
|
8646
|
+
}, {
|
|
8647
|
+
key: "set",
|
|
8648
|
+
value: function set(key, value) {
|
|
8649
|
+
if (this.cache.has(key)) {
|
|
8650
|
+
this.cache.set(key, value);
|
|
8651
|
+
} else {
|
|
8652
|
+
this._set(key, value);
|
|
8653
|
+
}
|
|
8654
|
+
|
|
8655
|
+
return this;
|
|
8656
|
+
}
|
|
8657
|
+
}, {
|
|
8658
|
+
key: "has",
|
|
8659
|
+
value: function has(key) {
|
|
8660
|
+
return this.cache.has(key) || this.oldCache.has(key);
|
|
8661
|
+
}
|
|
8662
|
+
}, {
|
|
8663
|
+
key: "peek",
|
|
8664
|
+
value: function peek(key) {
|
|
8665
|
+
if (this.cache.has(key)) {
|
|
8666
|
+
return this.cache.get(key);
|
|
8667
|
+
}
|
|
8668
|
+
|
|
8669
|
+
if (this.oldCache.has(key)) {
|
|
8670
|
+
return this.oldCache.get(key);
|
|
8671
|
+
}
|
|
8672
|
+
}
|
|
8673
|
+
}, {
|
|
8674
|
+
key: "delete",
|
|
8675
|
+
value: function _delete(key) {
|
|
8676
|
+
var deleted = this.cache.delete(key);
|
|
8677
|
+
|
|
8678
|
+
if (deleted) {
|
|
8679
|
+
this._size--;
|
|
8680
|
+
}
|
|
8681
|
+
|
|
8682
|
+
return this.oldCache.delete(key) || deleted;
|
|
8683
|
+
}
|
|
8684
|
+
}, {
|
|
8685
|
+
key: "clear",
|
|
8686
|
+
value: function clear() {
|
|
8687
|
+
this.cache.clear();
|
|
8688
|
+
this.oldCache.clear();
|
|
8689
|
+
this._size = 0;
|
|
8690
|
+
}
|
|
8691
|
+
}, {
|
|
8692
|
+
key: "keys",
|
|
8693
|
+
value: /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function keys() {
|
|
8694
|
+
var _iterator2, _step2, _step2$value, key;
|
|
8695
|
+
|
|
8696
|
+
return _regeneratorRuntime__default["default"].wrap(function keys$(_context) {
|
|
8697
|
+
while (1) {
|
|
8698
|
+
switch (_context.prev = _context.next) {
|
|
8699
|
+
case 0:
|
|
8700
|
+
_iterator2 = _createForOfIteratorHelper$1(this);
|
|
8701
|
+
_context.prev = 1;
|
|
8702
|
+
|
|
8703
|
+
_iterator2.s();
|
|
8704
|
+
|
|
8705
|
+
case 3:
|
|
8706
|
+
if ((_step2 = _iterator2.n()).done) {
|
|
8707
|
+
_context.next = 9;
|
|
8708
|
+
break;
|
|
8709
|
+
}
|
|
8710
|
+
|
|
8711
|
+
_step2$value = _slicedToArray__default["default"](_step2.value, 1), key = _step2$value[0];
|
|
8712
|
+
_context.next = 7;
|
|
8713
|
+
return key;
|
|
8714
|
+
|
|
8715
|
+
case 7:
|
|
8716
|
+
_context.next = 3;
|
|
8717
|
+
break;
|
|
8718
|
+
|
|
8719
|
+
case 9:
|
|
8720
|
+
_context.next = 14;
|
|
8721
|
+
break;
|
|
8722
|
+
|
|
8723
|
+
case 11:
|
|
8724
|
+
_context.prev = 11;
|
|
8725
|
+
_context.t0 = _context["catch"](1);
|
|
8726
|
+
|
|
8727
|
+
_iterator2.e(_context.t0);
|
|
8728
|
+
|
|
8729
|
+
case 14:
|
|
8730
|
+
_context.prev = 14;
|
|
8731
|
+
|
|
8732
|
+
_iterator2.f();
|
|
8733
|
+
|
|
8734
|
+
return _context.finish(14);
|
|
8735
|
+
|
|
8736
|
+
case 17:
|
|
8737
|
+
case "end":
|
|
8738
|
+
return _context.stop();
|
|
8739
|
+
}
|
|
8740
|
+
}
|
|
8741
|
+
}, keys, this, [[1, 11, 14, 17]]);
|
|
8742
|
+
})
|
|
8743
|
+
}, {
|
|
8744
|
+
key: "values",
|
|
8745
|
+
value: /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function values() {
|
|
8746
|
+
var _iterator3, _step3, _step3$value, value;
|
|
8747
|
+
|
|
8748
|
+
return _regeneratorRuntime__default["default"].wrap(function values$(_context2) {
|
|
8749
|
+
while (1) {
|
|
8750
|
+
switch (_context2.prev = _context2.next) {
|
|
8751
|
+
case 0:
|
|
8752
|
+
_iterator3 = _createForOfIteratorHelper$1(this);
|
|
8753
|
+
_context2.prev = 1;
|
|
8754
|
+
|
|
8755
|
+
_iterator3.s();
|
|
8756
|
+
|
|
8757
|
+
case 3:
|
|
8758
|
+
if ((_step3 = _iterator3.n()).done) {
|
|
8759
|
+
_context2.next = 9;
|
|
8760
|
+
break;
|
|
8761
|
+
}
|
|
8762
|
+
|
|
8763
|
+
_step3$value = _slicedToArray__default["default"](_step3.value, 2), value = _step3$value[1];
|
|
8764
|
+
_context2.next = 7;
|
|
8765
|
+
return value;
|
|
8766
|
+
|
|
8767
|
+
case 7:
|
|
8768
|
+
_context2.next = 3;
|
|
8769
|
+
break;
|
|
8770
|
+
|
|
8771
|
+
case 9:
|
|
8772
|
+
_context2.next = 14;
|
|
8773
|
+
break;
|
|
8774
|
+
|
|
8775
|
+
case 11:
|
|
8776
|
+
_context2.prev = 11;
|
|
8777
|
+
_context2.t0 = _context2["catch"](1);
|
|
8778
|
+
|
|
8779
|
+
_iterator3.e(_context2.t0);
|
|
8780
|
+
|
|
8781
|
+
case 14:
|
|
8782
|
+
_context2.prev = 14;
|
|
8783
|
+
|
|
8784
|
+
_iterator3.f();
|
|
8785
|
+
|
|
8786
|
+
return _context2.finish(14);
|
|
8787
|
+
|
|
8788
|
+
case 17:
|
|
8789
|
+
case "end":
|
|
8790
|
+
return _context2.stop();
|
|
8791
|
+
}
|
|
8792
|
+
}
|
|
8793
|
+
}, values, this, [[1, 11, 14, 17]]);
|
|
8794
|
+
})
|
|
8795
|
+
}, {
|
|
8796
|
+
key: _Symbol$iterator,
|
|
8797
|
+
value: /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function value() {
|
|
8798
|
+
var _iterator4, _step4, item, _iterator5, _step5, _item, _item2, key;
|
|
8799
|
+
|
|
8800
|
+
return _regeneratorRuntime__default["default"].wrap(function value$(_context3) {
|
|
8801
|
+
while (1) {
|
|
8802
|
+
switch (_context3.prev = _context3.next) {
|
|
8803
|
+
case 0:
|
|
8804
|
+
_iterator4 = _createForOfIteratorHelper$1(this.cache);
|
|
8805
|
+
_context3.prev = 1;
|
|
8806
|
+
|
|
8807
|
+
_iterator4.s();
|
|
8808
|
+
|
|
8809
|
+
case 3:
|
|
8810
|
+
if ((_step4 = _iterator4.n()).done) {
|
|
8811
|
+
_context3.next = 9;
|
|
8812
|
+
break;
|
|
8813
|
+
}
|
|
8814
|
+
|
|
8815
|
+
item = _step4.value;
|
|
8816
|
+
_context3.next = 7;
|
|
8817
|
+
return item;
|
|
8818
|
+
|
|
8819
|
+
case 7:
|
|
8820
|
+
_context3.next = 3;
|
|
8821
|
+
break;
|
|
8822
|
+
|
|
8823
|
+
case 9:
|
|
8824
|
+
_context3.next = 14;
|
|
8825
|
+
break;
|
|
8826
|
+
|
|
8827
|
+
case 11:
|
|
8828
|
+
_context3.prev = 11;
|
|
8829
|
+
_context3.t0 = _context3["catch"](1);
|
|
8830
|
+
|
|
8831
|
+
_iterator4.e(_context3.t0);
|
|
8832
|
+
|
|
8833
|
+
case 14:
|
|
8834
|
+
_context3.prev = 14;
|
|
8835
|
+
|
|
8836
|
+
_iterator4.f();
|
|
8837
|
+
|
|
8838
|
+
return _context3.finish(14);
|
|
8839
|
+
|
|
8840
|
+
case 17:
|
|
8841
|
+
_iterator5 = _createForOfIteratorHelper$1(this.oldCache);
|
|
8842
|
+
_context3.prev = 18;
|
|
8843
|
+
|
|
8844
|
+
_iterator5.s();
|
|
8845
|
+
|
|
8846
|
+
case 20:
|
|
8847
|
+
if ((_step5 = _iterator5.n()).done) {
|
|
8848
|
+
_context3.next = 28;
|
|
8849
|
+
break;
|
|
8850
|
+
}
|
|
8851
|
+
|
|
8852
|
+
_item = _step5.value;
|
|
8853
|
+
_item2 = _slicedToArray__default["default"](_item, 1), key = _item2[0];
|
|
8854
|
+
|
|
8855
|
+
if (this.cache.has(key)) {
|
|
8856
|
+
_context3.next = 26;
|
|
8857
|
+
break;
|
|
8858
|
+
}
|
|
8859
|
+
|
|
8860
|
+
_context3.next = 26;
|
|
8861
|
+
return _item;
|
|
8862
|
+
|
|
8863
|
+
case 26:
|
|
8864
|
+
_context3.next = 20;
|
|
8865
|
+
break;
|
|
8866
|
+
|
|
8867
|
+
case 28:
|
|
8868
|
+
_context3.next = 33;
|
|
8869
|
+
break;
|
|
8870
|
+
|
|
8871
|
+
case 30:
|
|
8872
|
+
_context3.prev = 30;
|
|
8873
|
+
_context3.t1 = _context3["catch"](18);
|
|
8874
|
+
|
|
8875
|
+
_iterator5.e(_context3.t1);
|
|
8876
|
+
|
|
8877
|
+
case 33:
|
|
8878
|
+
_context3.prev = 33;
|
|
8879
|
+
|
|
8880
|
+
_iterator5.f();
|
|
8881
|
+
|
|
8882
|
+
return _context3.finish(33);
|
|
8883
|
+
|
|
8884
|
+
case 36:
|
|
8885
|
+
case "end":
|
|
8886
|
+
return _context3.stop();
|
|
8887
|
+
}
|
|
8888
|
+
}
|
|
8889
|
+
}, value, this, [[1, 11, 14, 17], [18, 30, 33, 36]]);
|
|
8890
|
+
})
|
|
8891
|
+
}, {
|
|
8892
|
+
key: "size",
|
|
8893
|
+
get: function get() {
|
|
8894
|
+
var oldCacheSize = 0;
|
|
8895
|
+
|
|
8896
|
+
var _iterator6 = _createForOfIteratorHelper$1(this.oldCache.keys()),
|
|
8897
|
+
_step6;
|
|
8898
|
+
|
|
8899
|
+
try {
|
|
8900
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
8901
|
+
var key = _step6.value;
|
|
8902
|
+
|
|
8903
|
+
if (!this.cache.has(key)) {
|
|
8904
|
+
oldCacheSize++;
|
|
8905
|
+
}
|
|
8906
|
+
}
|
|
8907
|
+
} catch (err) {
|
|
8908
|
+
_iterator6.e(err);
|
|
8909
|
+
} finally {
|
|
8910
|
+
_iterator6.f();
|
|
8911
|
+
}
|
|
8912
|
+
|
|
8913
|
+
return Math.min(this._size + oldCacheSize, this.maxSize);
|
|
8914
|
+
}
|
|
8915
|
+
}]);
|
|
8916
|
+
|
|
8917
|
+
return QuickLRU;
|
|
8918
|
+
}(Symbol.iterator);
|
|
8919
|
+
|
|
8920
|
+
var quickLru = QuickLRU;
|
|
8921
|
+
|
|
8922
|
+
/**
|
|
8923
|
+
* Represents channel metadata.
|
|
8924
|
+
*/
|
|
8925
|
+
|
|
8926
|
+
var ChannelMetadata = /*#__PURE__*/_createClass__default["default"](
|
|
8927
|
+
/**
|
|
8928
|
+
* Communication channel type.
|
|
8929
|
+
*/
|
|
8930
|
+
|
|
8931
|
+
/**
|
|
8932
|
+
* The actual metadata.
|
|
8933
|
+
*/
|
|
8934
|
+
|
|
8935
|
+
/**
|
|
8936
|
+
* @internal
|
|
8937
|
+
*/
|
|
8938
|
+
function ChannelMetadata(type, data) {
|
|
8939
|
+
_classCallCheck__default["default"](this, ChannelMetadata);
|
|
8940
|
+
|
|
8941
|
+
this.type = type;
|
|
8942
|
+
this.data = data;
|
|
8943
|
+
Object.freeze(data);
|
|
8944
|
+
});
|
|
8945
|
+
|
|
8946
|
+
var ChannelMetadataClient = /*#__PURE__*/function () {
|
|
8947
|
+
function ChannelMetadataClient(services, configuration) {
|
|
8948
|
+
_classCallCheck__default["default"](this, ChannelMetadataClient);
|
|
8949
|
+
|
|
8950
|
+
this._services = services;
|
|
8951
|
+
this._configuration = configuration;
|
|
8952
|
+
this._cache = new quickLru({
|
|
8953
|
+
maxSize: configuration.channelMetadataCacheCapacity
|
|
8954
|
+
});
|
|
8955
|
+
}
|
|
8956
|
+
|
|
8957
|
+
_createClass__default["default"](ChannelMetadataClient, [{
|
|
8958
|
+
key: "getChannelMetadata",
|
|
8959
|
+
value: function () {
|
|
8960
|
+
var _getChannelMetadata = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(conversationSid, messageSid) {
|
|
8961
|
+
var key, cachedItem, url, metadataResponse, metadata;
|
|
8962
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
|
|
8963
|
+
while (1) {
|
|
8964
|
+
switch (_context.prev = _context.next) {
|
|
8965
|
+
case 0:
|
|
8966
|
+
key = "".concat(conversationSid, ",").concat(messageSid);
|
|
8967
|
+
cachedItem = this._cache.get(key);
|
|
8968
|
+
|
|
8969
|
+
if (!cachedItem) {
|
|
8970
|
+
_context.next = 4;
|
|
8971
|
+
break;
|
|
8972
|
+
}
|
|
8973
|
+
|
|
8974
|
+
return _context.abrupt("return", cachedItem.item);
|
|
8975
|
+
|
|
8976
|
+
case 4:
|
|
8977
|
+
url = "".concat(this._configuration.links.conversations, "/").concat(conversationSid, "/Messages/").concat(messageSid, "/ChannelMetadata");
|
|
8978
|
+
_context.prev = 5;
|
|
8979
|
+
_context.next = 8;
|
|
8980
|
+
return this._services.commandExecutor.fetchResource(url);
|
|
8981
|
+
|
|
8982
|
+
case 8:
|
|
8983
|
+
metadataResponse = _context.sent;
|
|
8984
|
+
_context.next = 17;
|
|
8985
|
+
break;
|
|
8986
|
+
|
|
8987
|
+
case 11:
|
|
8988
|
+
_context.prev = 11;
|
|
8989
|
+
_context.t0 = _context["catch"](5);
|
|
8990
|
+
|
|
8991
|
+
if (!(_context.t0 instanceof ChannelMetadataNotFoundError)) {
|
|
8992
|
+
_context.next = 16;
|
|
8993
|
+
break;
|
|
8994
|
+
}
|
|
8995
|
+
|
|
8996
|
+
this._cache.set(key, {
|
|
8997
|
+
item: null
|
|
8998
|
+
});
|
|
8999
|
+
|
|
9000
|
+
return _context.abrupt("return", null);
|
|
9001
|
+
|
|
9002
|
+
case 16:
|
|
9003
|
+
throw new Error(_context.t0);
|
|
9004
|
+
|
|
9005
|
+
case 17:
|
|
9006
|
+
metadata = new ChannelMetadata(metadataResponse.type, metadataResponse.data);
|
|
9007
|
+
|
|
9008
|
+
this._cache.set(key, {
|
|
9009
|
+
item: metadata
|
|
9010
|
+
});
|
|
9011
|
+
|
|
9012
|
+
return _context.abrupt("return", metadata);
|
|
9013
|
+
|
|
9014
|
+
case 20:
|
|
9015
|
+
case "end":
|
|
9016
|
+
return _context.stop();
|
|
9017
|
+
}
|
|
9018
|
+
}
|
|
9019
|
+
}, _callee, this, [[5, 11]]);
|
|
9020
|
+
}));
|
|
9021
|
+
|
|
9022
|
+
function getChannelMetadata(_x, _x2) {
|
|
9023
|
+
return _getChannelMetadata.apply(this, arguments);
|
|
9024
|
+
}
|
|
9025
|
+
|
|
9026
|
+
return getChannelMetadata;
|
|
9027
|
+
}()
|
|
9028
|
+
}]);
|
|
9029
|
+
|
|
9030
|
+
return ChannelMetadataClient;
|
|
9031
|
+
}();
|
|
9032
|
+
|
|
9033
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
9034
|
+
|
|
9035
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
9036
|
+
|
|
9037
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
9038
|
+
/**
|
|
9039
|
+
* Email recipient descriptor.
|
|
9040
|
+
*/
|
|
9041
|
+
|
|
9042
|
+
var EmailRecipientDescriptor = /*#__PURE__*/_createClass__default["default"](
|
|
9043
|
+
/**
|
|
9044
|
+
* Type of recipient.
|
|
9045
|
+
*/
|
|
9046
|
+
|
|
9047
|
+
/**
|
|
9048
|
+
* Sid of the message that this recipient belongs to.
|
|
9049
|
+
*/
|
|
9050
|
+
|
|
9051
|
+
/**
|
|
9052
|
+
* Email recipient level.
|
|
9053
|
+
*/
|
|
9054
|
+
|
|
9055
|
+
/**
|
|
9056
|
+
* Name of the recipient.
|
|
9057
|
+
*/
|
|
9058
|
+
|
|
9059
|
+
/**
|
|
9060
|
+
* Address of the recipient.
|
|
9061
|
+
*/
|
|
9062
|
+
|
|
9063
|
+
/**
|
|
9064
|
+
* @internal
|
|
9065
|
+
*/
|
|
9066
|
+
function EmailRecipientDescriptor(recipient) {
|
|
9067
|
+
_classCallCheck__default["default"](this, EmailRecipientDescriptor);
|
|
7239
9068
|
|
|
7240
|
-
|
|
7241
|
-
_context.next = 13;
|
|
7242
|
-
return this._services.transport.post(preProcessedUrl, finalHeaders, JSON.stringify(requestBody), this._productId);
|
|
9069
|
+
_defineProperty__default["default"](this, "type", "email");
|
|
7243
9070
|
|
|
7244
|
-
|
|
7245
|
-
|
|
7246
|
-
|
|
9071
|
+
this.messageSid = recipient.message_sid;
|
|
9072
|
+
this.level = recipient.level;
|
|
9073
|
+
this.name = recipient.name;
|
|
9074
|
+
this.address = recipient.address;
|
|
9075
|
+
});
|
|
9076
|
+
/**
|
|
9077
|
+
* Unknown recipient descriptor. Used to be able to handle recipient types that
|
|
9078
|
+
* are not supported by the current version of the SDK.
|
|
9079
|
+
*/
|
|
7247
9080
|
|
|
7248
|
-
case 15:
|
|
7249
|
-
_context.next = 17;
|
|
7250
|
-
return this._services.transport.delete(preProcessedUrl, finalHeaders, {}, this._productId);
|
|
7251
9081
|
|
|
7252
|
-
|
|
7253
|
-
|
|
7254
|
-
|
|
9082
|
+
var UnknownRecipientDescriptor = /*#__PURE__*/_createClass__default["default"](
|
|
9083
|
+
/**
|
|
9084
|
+
* Type of recipient.
|
|
9085
|
+
*/
|
|
7255
9086
|
|
|
7256
|
-
|
|
7257
|
-
|
|
7258
|
-
|
|
7259
|
-
break;
|
|
7260
|
-
}
|
|
9087
|
+
/**
|
|
9088
|
+
* Sid of the message that this recipient belongs to.
|
|
9089
|
+
*/
|
|
7261
9090
|
|
|
7262
|
-
|
|
9091
|
+
/**
|
|
9092
|
+
* Recipient data as a JSON string.
|
|
9093
|
+
*/
|
|
7263
9094
|
|
|
7264
|
-
|
|
7265
|
-
|
|
9095
|
+
/**
|
|
9096
|
+
* @internal
|
|
9097
|
+
*/
|
|
9098
|
+
function UnknownRecipientDescriptor(recipient) {
|
|
9099
|
+
_classCallCheck__default["default"](this, UnknownRecipientDescriptor);
|
|
7266
9100
|
|
|
7267
|
-
|
|
7268
|
-
|
|
7269
|
-
|
|
7270
|
-
|
|
7271
|
-
}
|
|
7272
|
-
}, _callee, this);
|
|
7273
|
-
}));
|
|
9101
|
+
this.type = recipient.type;
|
|
9102
|
+
this.messageSid = recipient.message_sid;
|
|
9103
|
+
this.rawData = JSON.stringify(recipient);
|
|
9104
|
+
});
|
|
7274
9105
|
|
|
7275
|
-
|
|
7276
|
-
|
|
7277
|
-
|
|
9106
|
+
var MessageRecipientsClient = /*#__PURE__*/function () {
|
|
9107
|
+
function MessageRecipientsClient(services, configuration) {
|
|
9108
|
+
_classCallCheck__default["default"](this, MessageRecipientsClient);
|
|
7278
9109
|
|
|
7279
|
-
|
|
7280
|
-
|
|
7281
|
-
|
|
7282
|
-
|
|
9110
|
+
this._services = services;
|
|
9111
|
+
this._configuration = configuration;
|
|
9112
|
+
this._cache = new quickLru({
|
|
9113
|
+
maxSize: configuration.messageRecipientsCacheCapacity
|
|
9114
|
+
});
|
|
9115
|
+
}
|
|
9116
|
+
|
|
9117
|
+
_createClass__default["default"](MessageRecipientsClient, [{
|
|
9118
|
+
key: "getRecipientsFromMessage",
|
|
7283
9119
|
value: function () {
|
|
7284
|
-
var
|
|
9120
|
+
var _getRecipientsFromMessage = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(conversationSid, messageSid) {
|
|
7285
9121
|
var _this = this;
|
|
7286
9122
|
|
|
7287
|
-
var
|
|
7288
|
-
return _regeneratorRuntime__default["default"].wrap(function
|
|
9123
|
+
var key, cachedItem, url, recipientsResponse, recipients;
|
|
9124
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
|
|
7289
9125
|
while (1) {
|
|
7290
|
-
switch (
|
|
9126
|
+
switch (_context.prev = _context.next) {
|
|
7291
9127
|
case 0:
|
|
7292
|
-
|
|
7293
|
-
|
|
7294
|
-
|
|
7295
|
-
|
|
7296
|
-
|
|
7297
|
-
|
|
7298
|
-
|
|
7299
|
-
|
|
7300
|
-
|
|
7301
|
-
});
|
|
9128
|
+
key = "".concat(conversationSid, ",").concat(messageSid);
|
|
9129
|
+
cachedItem = this._cache.get(key);
|
|
9130
|
+
|
|
9131
|
+
if (!cachedItem) {
|
|
9132
|
+
_context.next = 4;
|
|
9133
|
+
break;
|
|
9134
|
+
}
|
|
9135
|
+
|
|
9136
|
+
return _context.abrupt("return", cachedItem.item);
|
|
7302
9137
|
|
|
7303
9138
|
case 4:
|
|
7304
|
-
|
|
7305
|
-
|
|
9139
|
+
url = new UriBuilder(this._configuration.links.conversations).path(conversationSid).path("MessageRecipients").arg("MessageSid", messageSid).build();
|
|
9140
|
+
_context.next = 7;
|
|
9141
|
+
return this._services.commandExecutor.fetchResource(url);
|
|
7306
9142
|
|
|
7307
|
-
case
|
|
7308
|
-
|
|
7309
|
-
|
|
7310
|
-
|
|
9143
|
+
case 7:
|
|
9144
|
+
recipientsResponse = _context.sent;
|
|
9145
|
+
recipients = recipientsResponse.message_recipients.map(function (recipient) {
|
|
9146
|
+
return _this._wrapResponse(recipient);
|
|
9147
|
+
});
|
|
9148
|
+
|
|
9149
|
+
if (recipients.length > 0) {
|
|
9150
|
+
this._cache.set(key, {
|
|
9151
|
+
item: recipients
|
|
9152
|
+
});
|
|
9153
|
+
}
|
|
9154
|
+
|
|
9155
|
+
return _context.abrupt("return", recipients);
|
|
7311
9156
|
|
|
7312
9157
|
case 11:
|
|
7313
9158
|
case "end":
|
|
7314
|
-
return
|
|
9159
|
+
return _context.stop();
|
|
7315
9160
|
}
|
|
7316
9161
|
}
|
|
7317
|
-
},
|
|
9162
|
+
}, _callee, this);
|
|
7318
9163
|
}));
|
|
7319
9164
|
|
|
7320
|
-
function
|
|
7321
|
-
return
|
|
9165
|
+
function getRecipientsFromMessage(_x, _x2) {
|
|
9166
|
+
return _getRecipientsFromMessage.apply(this, arguments);
|
|
7322
9167
|
}
|
|
7323
9168
|
|
|
7324
|
-
return
|
|
9169
|
+
return getRecipientsFromMessage;
|
|
7325
9170
|
}()
|
|
7326
9171
|
}, {
|
|
7327
|
-
key: "
|
|
9172
|
+
key: "getRecipientsFromConversation",
|
|
7328
9173
|
value: function () {
|
|
7329
|
-
var
|
|
7330
|
-
var
|
|
7331
|
-
|
|
9174
|
+
var _getRecipientsFromConversation = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2(conversationSid, paginatorOptions) {
|
|
9175
|
+
var _paginatorOptions$pag,
|
|
9176
|
+
_paginatorOptions$pag2,
|
|
9177
|
+
_this2 = this;
|
|
9178
|
+
|
|
9179
|
+
var url, recipientsResponse, allRecipients, _iterator, _step, _this$_cache$get$item, _this$_cache$get, recipient, key, existingMessageRecipients;
|
|
9180
|
+
|
|
9181
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee2$(_context2) {
|
|
7332
9182
|
while (1) {
|
|
7333
|
-
switch (
|
|
9183
|
+
switch (_context2.prev = _context2.next) {
|
|
7334
9184
|
case 0:
|
|
7335
|
-
|
|
7336
|
-
|
|
7337
|
-
|
|
9185
|
+
url = new UriBuilder(this._configuration.links.conversations).path(conversationSid).path("MessageRecipients").arg("PageToken", (_paginatorOptions$pag = paginatorOptions === null || paginatorOptions === void 0 ? void 0 : paginatorOptions.pageToken) !== null && _paginatorOptions$pag !== void 0 ? _paginatorOptions$pag : undefined).arg("PageSize", (_paginatorOptions$pag2 = paginatorOptions === null || paginatorOptions === void 0 ? void 0 : paginatorOptions.pageSize) !== null && _paginatorOptions$pag2 !== void 0 ? _paginatorOptions$pag2 : undefined).build();
|
|
9186
|
+
_context2.next = 3;
|
|
9187
|
+
return this._services.commandExecutor.fetchResource(url);
|
|
9188
|
+
|
|
9189
|
+
case 3:
|
|
9190
|
+
recipientsResponse = _context2.sent;
|
|
9191
|
+
allRecipients = recipientsResponse.message_recipients.map(function (recipient) {
|
|
9192
|
+
return _this2._wrapResponse(recipient);
|
|
7338
9193
|
});
|
|
9194
|
+
_iterator = _createForOfIteratorHelper(allRecipients);
|
|
7339
9195
|
|
|
7340
|
-
|
|
7341
|
-
|
|
9196
|
+
try {
|
|
9197
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
9198
|
+
recipient = _step.value;
|
|
9199
|
+
key = "".concat(conversationSid, ",").concat(recipient.messageSid);
|
|
9200
|
+
existingMessageRecipients = (_this$_cache$get$item = (_this$_cache$get = this._cache.get(key)) === null || _this$_cache$get === void 0 ? void 0 : _this$_cache$get.item) !== null && _this$_cache$get$item !== void 0 ? _this$_cache$get$item : [];
|
|
7342
9201
|
|
|
7343
|
-
|
|
7344
|
-
|
|
7345
|
-
|
|
9202
|
+
this._cache.set(key, {
|
|
9203
|
+
item: [].concat(_toConsumableArray__default["default"](existingMessageRecipients), [recipient])
|
|
9204
|
+
});
|
|
9205
|
+
}
|
|
9206
|
+
} catch (err) {
|
|
9207
|
+
_iterator.e(err);
|
|
9208
|
+
} finally {
|
|
9209
|
+
_iterator.f();
|
|
7346
9210
|
}
|
|
7347
9211
|
|
|
7348
|
-
|
|
7349
|
-
|
|
7350
|
-
|
|
7351
|
-
|
|
7352
|
-
|
|
7353
|
-
|
|
7354
|
-
case 7:
|
|
7355
|
-
return _context3.abrupt("return", result.body);
|
|
9212
|
+
return _context2.abrupt("return", new RestPaginator(allRecipients, function (pageToken, pageSize) {
|
|
9213
|
+
return _this2.getRecipientsFromConversation(conversationSid, {
|
|
9214
|
+
pageToken: pageToken,
|
|
9215
|
+
pageSize: pageSize
|
|
9216
|
+
});
|
|
9217
|
+
}, recipientsResponse.meta.previous_token, recipientsResponse.meta.next_token));
|
|
7356
9218
|
|
|
7357
9219
|
case 8:
|
|
7358
9220
|
case "end":
|
|
7359
|
-
return
|
|
9221
|
+
return _context2.stop();
|
|
7360
9222
|
}
|
|
7361
9223
|
}
|
|
7362
|
-
},
|
|
9224
|
+
}, _callee2, this);
|
|
7363
9225
|
}));
|
|
7364
9226
|
|
|
7365
|
-
function
|
|
7366
|
-
return
|
|
9227
|
+
function getRecipientsFromConversation(_x3, _x4) {
|
|
9228
|
+
return _getRecipientsFromConversation.apply(this, arguments);
|
|
7367
9229
|
}
|
|
7368
9230
|
|
|
7369
|
-
return
|
|
9231
|
+
return getRecipientsFromConversation;
|
|
7370
9232
|
}()
|
|
9233
|
+
}, {
|
|
9234
|
+
key: "_wrapResponse",
|
|
9235
|
+
value: function _wrapResponse(recipient) {
|
|
9236
|
+
switch (recipient.type) {
|
|
9237
|
+
case "email":
|
|
9238
|
+
return new EmailRecipientDescriptor(recipient);
|
|
9239
|
+
|
|
9240
|
+
default:
|
|
9241
|
+
return new UnknownRecipientDescriptor(recipient);
|
|
9242
|
+
}
|
|
9243
|
+
}
|
|
7371
9244
|
}]);
|
|
7372
9245
|
|
|
7373
|
-
return
|
|
9246
|
+
return MessageRecipientsClient;
|
|
7374
9247
|
}();
|
|
7375
9248
|
|
|
7376
9249
|
var _class;
|
|
@@ -7572,12 +9445,25 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
|
|
|
7572
9445
|
*/
|
|
7573
9446
|
|
|
7574
9447
|
/**
|
|
9448
|
+
* @deprecated Use initialized or initFailed events instead
|
|
7575
9449
|
* Fired when the state of the client has been changed.
|
|
7576
9450
|
*
|
|
7577
9451
|
* Parameters:
|
|
9452
|
+
* 1. {@link State} `state` - the new client state
|
|
9453
|
+
* @event
|
|
9454
|
+
*/
|
|
9455
|
+
|
|
9456
|
+
/**
|
|
9457
|
+
* Fired when the client has completed initialization successfully.
|
|
9458
|
+
* @event
|
|
9459
|
+
*/
|
|
9460
|
+
|
|
9461
|
+
/**
|
|
9462
|
+
* Fired when the client initialization failed.
|
|
9463
|
+
*
|
|
9464
|
+
* Parameters:
|
|
7578
9465
|
* 1. object `data` - info object provided with the event. It has the
|
|
7579
|
-
* following
|
|
7580
|
-
* * {@link State} `state` - the new client state
|
|
9466
|
+
* following property:
|
|
7581
9467
|
* * Error? `error` - the initialization error if present
|
|
7582
9468
|
* @event
|
|
7583
9469
|
*/
|
|
@@ -7628,7 +9514,47 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
|
|
|
7628
9514
|
*/
|
|
7629
9515
|
|
|
7630
9516
|
/**
|
|
7631
|
-
*
|
|
9517
|
+
* Promise that resolves on successful initialization.
|
|
9518
|
+
*/
|
|
9519
|
+
|
|
9520
|
+
/**
|
|
9521
|
+
* Options passed to the client.
|
|
9522
|
+
*/
|
|
9523
|
+
|
|
9524
|
+
/**
|
|
9525
|
+
* Client service objects.
|
|
9526
|
+
*/
|
|
9527
|
+
|
|
9528
|
+
/**
|
|
9529
|
+
* The user of the client.
|
|
9530
|
+
*/
|
|
9531
|
+
|
|
9532
|
+
/**
|
|
9533
|
+
* Resolves the {@link Client._ensureReady} promise.
|
|
9534
|
+
*/
|
|
9535
|
+
|
|
9536
|
+
/**
|
|
9537
|
+
* Rejects the {@link Client._ensureReady} promise.
|
|
9538
|
+
*/
|
|
9539
|
+
|
|
9540
|
+
/**
|
|
9541
|
+
* The current token of the client.
|
|
9542
|
+
*/
|
|
9543
|
+
|
|
9544
|
+
/**
|
|
9545
|
+
* The constructed configuration object.
|
|
9546
|
+
*/
|
|
9547
|
+
|
|
9548
|
+
/**
|
|
9549
|
+
* The Conversations entity.
|
|
9550
|
+
*/
|
|
9551
|
+
|
|
9552
|
+
/**
|
|
9553
|
+
* Promise that resolves when initial conversations are fetched.
|
|
9554
|
+
*/
|
|
9555
|
+
|
|
9556
|
+
/**
|
|
9557
|
+
* Returned Conversations Client instance is not yet fully initialized. Calling any
|
|
7632
9558
|
* operations will block until it is. Use connection events to monitor when
|
|
7633
9559
|
* client becomes fully available (connectionStateChanged with state
|
|
7634
9560
|
* 'connected') or not available (connectionStateChange with state 'denied',
|
|
@@ -7718,16 +9644,16 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
|
|
|
7718
9644
|
|
|
7719
9645
|
_this._services.twilsockClient = _this._options.twilsockClient = (_this$_options$twilso = _this._options.twilsockClient) !== null && _this$_options$twilso !== void 0 ? _this$_options$twilso : new twilsock.TwilsockClient(fpaToken, productId, _this._options);
|
|
7720
9646
|
|
|
7721
|
-
_this._services.twilsockClient.on(
|
|
7722
|
-
return _this.emit(
|
|
9647
|
+
_this._services.twilsockClient.on(Client_1.tokenAboutToExpire, function () {
|
|
9648
|
+
return _this.emit(Client_1.tokenAboutToExpire);
|
|
7723
9649
|
});
|
|
7724
9650
|
|
|
7725
|
-
_this._services.twilsockClient.on(
|
|
7726
|
-
return _this.emit(
|
|
9651
|
+
_this._services.twilsockClient.on(Client_1.tokenExpired, function () {
|
|
9652
|
+
return _this.emit(Client_1.tokenExpired);
|
|
7727
9653
|
});
|
|
7728
9654
|
|
|
7729
|
-
_this._services.twilsockClient.on(
|
|
7730
|
-
return _this.emit(
|
|
9655
|
+
_this._services.twilsockClient.on(Client_1.connectionError, function (error) {
|
|
9656
|
+
return _this.emit(Client_1.connectionError, error);
|
|
7731
9657
|
});
|
|
7732
9658
|
|
|
7733
9659
|
_this._services.twilsockClient.on("stateChanged", function (state) {
|
|
@@ -7736,7 +9662,7 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
|
|
|
7736
9662
|
if (state !== _this.connectionState) {
|
|
7737
9663
|
_this.connectionState = state;
|
|
7738
9664
|
|
|
7739
|
-
_this.emit(
|
|
9665
|
+
_this.emit(Client_1.connectionStateChanged, _this.connectionState);
|
|
7740
9666
|
}
|
|
7741
9667
|
});
|
|
7742
9668
|
|
|
@@ -7749,12 +9675,14 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
|
|
|
7749
9675
|
_this._services.commandExecutor = new CommandExecutor(baseUrl, {
|
|
7750
9676
|
transport: _this._options.transport
|
|
7751
9677
|
}, productId);
|
|
9678
|
+
_this._services.contentClient = new ContentClient(_this._services);
|
|
7752
9679
|
|
|
7753
9680
|
var emitFailed = function emitFailed(error) {
|
|
7754
9681
|
_this._rejectEnsureReady(error);
|
|
7755
9682
|
|
|
7756
|
-
_this.emit(
|
|
7757
|
-
|
|
9683
|
+
_this.emit(Client_1.stateChanged, "failed");
|
|
9684
|
+
|
|
9685
|
+
_this.emit(Client_1.initFailed, {
|
|
7758
9686
|
error: error
|
|
7759
9687
|
});
|
|
7760
9688
|
};
|
|
@@ -7764,13 +9692,15 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
|
|
|
7764
9692
|
terminal: true,
|
|
7765
9693
|
message: "Twilsock has disconnected."
|
|
7766
9694
|
});
|
|
9695
|
+
|
|
9696
|
+
_this._initializeEnsureReady((options === null || options === void 0 ? void 0 : options.throwErrorsAlways) || false);
|
|
7767
9697
|
};
|
|
7768
9698
|
|
|
7769
|
-
_this._services.twilsockClient.
|
|
9699
|
+
_this._services.twilsockClient.once("connectionError", emitFailed);
|
|
7770
9700
|
|
|
7771
|
-
_this._services.twilsockClient.
|
|
9701
|
+
_this._services.twilsockClient.once("disconnected", emitDisconnected);
|
|
7772
9702
|
|
|
7773
|
-
_this._services.twilsockClient.
|
|
9703
|
+
_this._services.twilsockClient.once("connected", /*#__PURE__*/_asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee() {
|
|
7774
9704
|
var startupEvent, connectionError;
|
|
7775
9705
|
return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
|
|
7776
9706
|
while (1) {
|
|
@@ -7793,7 +9723,7 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
|
|
|
7793
9723
|
case 8:
|
|
7794
9724
|
_this._services.twilsockClient.addPartialTelemetryEvent(new twilsock.TelemetryEventDescription("", "", new Date()), startupEvent, twilsock.TelemetryPoint.End);
|
|
7795
9725
|
|
|
7796
|
-
_context.next =
|
|
9726
|
+
_context.next = 17;
|
|
7797
9727
|
break;
|
|
7798
9728
|
|
|
7799
9729
|
case 11:
|
|
@@ -7807,12 +9737,13 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
|
|
|
7807
9737
|
|
|
7808
9738
|
_this._rejectEnsureReady(connectionError);
|
|
7809
9739
|
|
|
7810
|
-
_this.emit(
|
|
7811
|
-
|
|
9740
|
+
_this.emit(Client_1.stateChanged, "failed");
|
|
9741
|
+
|
|
9742
|
+
_this.emit(Client_1.initFailed, {
|
|
7812
9743
|
error: connectionError
|
|
7813
9744
|
});
|
|
7814
9745
|
|
|
7815
|
-
case
|
|
9746
|
+
case 17:
|
|
7816
9747
|
case "end":
|
|
7817
9748
|
return _context.stop();
|
|
7818
9749
|
}
|
|
@@ -7820,12 +9751,7 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
|
|
|
7820
9751
|
}, _callee, null, [[3, 11]]);
|
|
7821
9752
|
})));
|
|
7822
9753
|
|
|
7823
|
-
_this.
|
|
7824
|
-
_this._resolveEnsureReady = resolve;
|
|
7825
|
-
_this._rejectEnsureReady = reject;
|
|
7826
|
-
}).catch(function () {
|
|
7827
|
-
return void 0;
|
|
7828
|
-
}); // @todo How to process unhandled rejection here?
|
|
9754
|
+
_this._initializeEnsureReady((options === null || options === void 0 ? void 0 : options.throwErrorsAlways) || false);
|
|
7829
9755
|
|
|
7830
9756
|
if (startTwilsock) {
|
|
7831
9757
|
_this._services.twilsockClient.connect();
|
|
@@ -7859,6 +9785,17 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
|
|
|
7859
9785
|
|
|
7860
9786
|
return this._configuration.reachabilityEnabled;
|
|
7861
9787
|
}
|
|
9788
|
+
/**
|
|
9789
|
+
* @deprecated
|
|
9790
|
+
* Current token.
|
|
9791
|
+
* @internal
|
|
9792
|
+
*/
|
|
9793
|
+
|
|
9794
|
+
}, {
|
|
9795
|
+
key: "token",
|
|
9796
|
+
get: function get() {
|
|
9797
|
+
return this._fpaToken;
|
|
9798
|
+
}
|
|
7862
9799
|
/**
|
|
7863
9800
|
* @deprecated Call constructor directly.
|
|
7864
9801
|
*
|
|
@@ -7997,16 +9934,32 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
|
|
|
7997
9934
|
conversation = _context4.sent;
|
|
7998
9935
|
|
|
7999
9936
|
if (conversation) {
|
|
8000
|
-
_context4.next =
|
|
9937
|
+
_context4.next = 12;
|
|
9938
|
+
break;
|
|
9939
|
+
}
|
|
9940
|
+
|
|
9941
|
+
_context4.next = 10;
|
|
9942
|
+
return this.peekConversationBySid(conversationSid);
|
|
9943
|
+
|
|
9944
|
+
case 10:
|
|
9945
|
+
conversation = _context4.sent;
|
|
9946
|
+
|
|
9947
|
+
if (conversation) {
|
|
9948
|
+
deprecationDecorator.deprecationWarning("The method getConversationBySid is deprecated to retrieve conversations you're not part of. Use peekConversationBySid instead.");
|
|
9949
|
+
}
|
|
9950
|
+
|
|
9951
|
+
case 12:
|
|
9952
|
+
if (conversation) {
|
|
9953
|
+
_context4.next = 14;
|
|
8001
9954
|
break;
|
|
8002
9955
|
}
|
|
8003
9956
|
|
|
8004
9957
|
throw new Error("Conversation with SID ".concat(conversationSid, " was not found."));
|
|
8005
9958
|
|
|
8006
|
-
case
|
|
9959
|
+
case 14:
|
|
8007
9960
|
return _context4.abrupt("return", conversation);
|
|
8008
9961
|
|
|
8009
|
-
case
|
|
9962
|
+
case 15:
|
|
8010
9963
|
case "end":
|
|
8011
9964
|
return _context4.stop();
|
|
8012
9965
|
}
|
|
@@ -8023,7 +9976,6 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
|
|
|
8023
9976
|
/**
|
|
8024
9977
|
* Peek a conversation by its SID.
|
|
8025
9978
|
* @param conversationSid Conversation sid
|
|
8026
|
-
* @internal
|
|
8027
9979
|
*/
|
|
8028
9980
|
|
|
8029
9981
|
}, {
|
|
@@ -8309,7 +10261,7 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
|
|
|
8309
10261
|
return removePushRegistrations;
|
|
8310
10262
|
}()
|
|
8311
10263
|
/**
|
|
8312
|
-
*
|
|
10264
|
+
* Parse a push notification payload.
|
|
8313
10265
|
*/
|
|
8314
10266
|
|
|
8315
10267
|
}, {
|
|
@@ -8492,6 +10444,43 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
|
|
|
8492
10444
|
});
|
|
8493
10445
|
return this.getTemporaryContentUrlsForMediaSids(sids);
|
|
8494
10446
|
}
|
|
10447
|
+
/**
|
|
10448
|
+
* Returns rich content templates belonging to the account. Rich content
|
|
10449
|
+
* templates can be created via the Twilio console or the REST API.
|
|
10450
|
+
*/
|
|
10451
|
+
|
|
10452
|
+
}, {
|
|
10453
|
+
key: "getContentTemplates",
|
|
10454
|
+
value: function () {
|
|
10455
|
+
var _getContentTemplates = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee16() {
|
|
10456
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee16$(_context16) {
|
|
10457
|
+
while (1) {
|
|
10458
|
+
switch (_context16.prev = _context16.next) {
|
|
10459
|
+
case 0:
|
|
10460
|
+
_context16.next = 2;
|
|
10461
|
+
return this._ensureReady;
|
|
10462
|
+
|
|
10463
|
+
case 2:
|
|
10464
|
+
_context16.next = 4;
|
|
10465
|
+
return this._services.contentClient.getContentTemplates();
|
|
10466
|
+
|
|
10467
|
+
case 4:
|
|
10468
|
+
return _context16.abrupt("return", _context16.sent);
|
|
10469
|
+
|
|
10470
|
+
case 5:
|
|
10471
|
+
case "end":
|
|
10472
|
+
return _context16.stop();
|
|
10473
|
+
}
|
|
10474
|
+
}
|
|
10475
|
+
}, _callee16, this);
|
|
10476
|
+
}));
|
|
10477
|
+
|
|
10478
|
+
function getContentTemplates() {
|
|
10479
|
+
return _getContentTemplates.apply(this, arguments);
|
|
10480
|
+
}
|
|
10481
|
+
|
|
10482
|
+
return getContentTemplates;
|
|
10483
|
+
}()
|
|
8495
10484
|
/**
|
|
8496
10485
|
* Initialize the client.
|
|
8497
10486
|
*/
|
|
@@ -8499,20 +10488,22 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
|
|
|
8499
10488
|
}, {
|
|
8500
10489
|
key: "_initialize",
|
|
8501
10490
|
value: function () {
|
|
8502
|
-
var _initialize2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function
|
|
10491
|
+
var _initialize2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee17() {
|
|
8503
10492
|
var _this3 = this;
|
|
8504
10493
|
|
|
8505
10494
|
var configurationResponse;
|
|
8506
|
-
return _regeneratorRuntime__default["default"].wrap(function
|
|
10495
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee17$(_context17) {
|
|
8507
10496
|
while (1) {
|
|
8508
|
-
switch (
|
|
10497
|
+
switch (_context17.prev = _context17.next) {
|
|
8509
10498
|
case 0:
|
|
8510
|
-
|
|
10499
|
+
_context17.next = 2;
|
|
8511
10500
|
return this._services.commandExecutor.fetchResource("Client/v2/Configuration");
|
|
8512
10501
|
|
|
8513
10502
|
case 2:
|
|
8514
|
-
configurationResponse =
|
|
10503
|
+
configurationResponse = _context17.sent;
|
|
8515
10504
|
this._configuration = new Configuration(this._options, configurationResponse, Client_1._logger);
|
|
10505
|
+
this._services.channelMetadataClient = new ChannelMetadataClient(this._services, this._configuration);
|
|
10506
|
+
this._services.messageRecipientsClient = new MessageRecipientsClient(this._services, this._configuration);
|
|
8516
10507
|
|
|
8517
10508
|
this._myself._resolveInitialization(this._configuration, this._configuration.userIdentity, this._configuration.userInfo, true);
|
|
8518
10509
|
|
|
@@ -8589,12 +10580,13 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
|
|
|
8589
10580
|
this._conversationsPromise = this._conversationsEntity.fetchConversations().then(function () {
|
|
8590
10581
|
return _this3._conversationsEntity;
|
|
8591
10582
|
}).catch(function (error) {
|
|
10583
|
+
console.error("Failed to fetch conversations _conversationsPromise -> client.ts", error);
|
|
8592
10584
|
throw error;
|
|
8593
10585
|
});
|
|
8594
|
-
|
|
10586
|
+
_context17.next = 30;
|
|
8595
10587
|
return this._services.users.myself._ensureFetched();
|
|
8596
10588
|
|
|
8597
|
-
case
|
|
10589
|
+
case 30:
|
|
8598
10590
|
Client_1._supportedPushChannels.forEach(function (channelType) {
|
|
8599
10591
|
return _this3._subscribeToPushNotifications(channelType);
|
|
8600
10592
|
});
|
|
@@ -8607,16 +10599,15 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
|
|
|
8607
10599
|
|
|
8608
10600
|
this._resolveEnsureReady();
|
|
8609
10601
|
|
|
8610
|
-
this.emit(
|
|
8611
|
-
|
|
8612
|
-
});
|
|
10602
|
+
this.emit(Client_1.stateChanged, "initialized");
|
|
10603
|
+
this.emit(Client_1.initialized);
|
|
8613
10604
|
|
|
8614
|
-
case
|
|
10605
|
+
case 36:
|
|
8615
10606
|
case "end":
|
|
8616
|
-
return
|
|
10607
|
+
return _context17.stop();
|
|
8617
10608
|
}
|
|
8618
10609
|
}
|
|
8619
|
-
},
|
|
10610
|
+
}, _callee17, this);
|
|
8620
10611
|
}));
|
|
8621
10612
|
|
|
8622
10613
|
function _initialize() {
|
|
@@ -8653,17 +10644,37 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
|
|
|
8653
10644
|
_this5._services.notificationClient.unsubscribe(channelType, messageType);
|
|
8654
10645
|
});
|
|
8655
10646
|
}
|
|
10647
|
+
/**
|
|
10648
|
+
* Initialize the ensureReady promise.
|
|
10649
|
+
*/
|
|
10650
|
+
|
|
10651
|
+
}, {
|
|
10652
|
+
key: "_initializeEnsureReady",
|
|
10653
|
+
value: function _initializeEnsureReady(throwErrorsAlways) {
|
|
10654
|
+
var _this6 = this;
|
|
10655
|
+
|
|
10656
|
+
this._ensureReady = new Promise(function (resolve, reject) {
|
|
10657
|
+
_this6._resolveEnsureReady = resolve;
|
|
10658
|
+
_this6._rejectEnsureReady = reject;
|
|
10659
|
+
}).catch(function (error) {
|
|
10660
|
+
if (throwErrorsAlways) {
|
|
10661
|
+
throw error;
|
|
10662
|
+
} else {
|
|
10663
|
+
return void 0;
|
|
10664
|
+
}
|
|
10665
|
+
});
|
|
10666
|
+
}
|
|
8656
10667
|
}], [{
|
|
8657
10668
|
key: "create",
|
|
8658
10669
|
value: function () {
|
|
8659
|
-
var _create = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function
|
|
10670
|
+
var _create = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee18(token, options) {
|
|
8660
10671
|
var client;
|
|
8661
|
-
return _regeneratorRuntime__default["default"].wrap(function
|
|
10672
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee18$(_context18) {
|
|
8662
10673
|
while (1) {
|
|
8663
|
-
switch (
|
|
10674
|
+
switch (_context18.prev = _context18.next) {
|
|
8664
10675
|
case 0:
|
|
8665
10676
|
if (!(options !== null && options !== void 0 && options.twilsockClient)) {
|
|
8666
|
-
|
|
10677
|
+
_context18.next = 2;
|
|
8667
10678
|
break;
|
|
8668
10679
|
}
|
|
8669
10680
|
|
|
@@ -8671,18 +10682,18 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
|
|
|
8671
10682
|
|
|
8672
10683
|
case 2:
|
|
8673
10684
|
client = new Client_1(token, options);
|
|
8674
|
-
|
|
10685
|
+
_context18.next = 5;
|
|
8675
10686
|
return client._ensureReady;
|
|
8676
10687
|
|
|
8677
10688
|
case 5:
|
|
8678
|
-
return
|
|
10689
|
+
return _context18.abrupt("return", client);
|
|
8679
10690
|
|
|
8680
10691
|
case 6:
|
|
8681
10692
|
case "end":
|
|
8682
|
-
return
|
|
10693
|
+
return _context18.stop();
|
|
8683
10694
|
}
|
|
8684
10695
|
}
|
|
8685
|
-
},
|
|
10696
|
+
}, _callee18);
|
|
8686
10697
|
}));
|
|
8687
10698
|
|
|
8688
10699
|
function create(_x16, _x17) {
|
|
@@ -8815,7 +10826,7 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
|
|
|
8815
10826
|
}]);
|
|
8816
10827
|
|
|
8817
10828
|
return Client;
|
|
8818
|
-
}(replayEventEmitter.ReplayEventEmitter), _defineProperty__default["default"](_class, "conversationAdded", "conversationAdded"), _defineProperty__default["default"](_class, "conversationJoined", "conversationJoined"), _defineProperty__default["default"](_class, "conversationLeft", "conversationLeft"), _defineProperty__default["default"](_class, "conversationRemoved", "conversationRemoved"), _defineProperty__default["default"](_class, "conversationUpdated", "conversationUpdated"), _defineProperty__default["default"](_class, "participantJoined", "participantJoined"), _defineProperty__default["default"](_class, "participantLeft", "participantLeft"), _defineProperty__default["default"](_class, "participantUpdated", "participantUpdated"), _defineProperty__default["default"](_class, "messageAdded", "messageAdded"), _defineProperty__default["default"](_class, "messageRemoved", "messageRemoved"), _defineProperty__default["default"](_class, "messageUpdated", "messageUpdated"), _defineProperty__default["default"](_class, "tokenAboutToExpire", "tokenAboutToExpire"), _defineProperty__default["default"](_class, "tokenExpired", "tokenExpired"), _defineProperty__default["default"](_class, "typingEnded", "typingEnded"), _defineProperty__default["default"](_class, "typingStarted", "typingStarted"), _defineProperty__default["default"](_class, "pushNotification", "pushNotification"), _defineProperty__default["default"](_class, "userSubscribed", "userSubscribed"), _defineProperty__default["default"](_class, "userUnsubscribed", "userUnsubscribed"), _defineProperty__default["default"](_class, "userUpdated", "userUpdated"), _defineProperty__default["default"](_class, "stateChanged", "stateChanged"), _defineProperty__default["default"](_class, "connectionStateChanged", "connectionStateChanged"), _defineProperty__default["default"](_class, "connectionError", "connectionError"), _defineProperty__default["default"](_class, "version", version), _defineProperty__default["default"](_class, "_logger", Logger.scope("Client")), _defineProperty__default["default"](_class, "_supportedPushChannels", ["fcm", "apn"]), _defineProperty__default["default"](_class, "_supportedPushDataFields", {
|
|
10829
|
+
}(replayEventEmitter.ReplayEventEmitter), _defineProperty__default["default"](_class, "conversationAdded", "conversationAdded"), _defineProperty__default["default"](_class, "conversationJoined", "conversationJoined"), _defineProperty__default["default"](_class, "conversationLeft", "conversationLeft"), _defineProperty__default["default"](_class, "conversationRemoved", "conversationRemoved"), _defineProperty__default["default"](_class, "conversationUpdated", "conversationUpdated"), _defineProperty__default["default"](_class, "participantJoined", "participantJoined"), _defineProperty__default["default"](_class, "participantLeft", "participantLeft"), _defineProperty__default["default"](_class, "participantUpdated", "participantUpdated"), _defineProperty__default["default"](_class, "messageAdded", "messageAdded"), _defineProperty__default["default"](_class, "messageRemoved", "messageRemoved"), _defineProperty__default["default"](_class, "messageUpdated", "messageUpdated"), _defineProperty__default["default"](_class, "tokenAboutToExpire", "tokenAboutToExpire"), _defineProperty__default["default"](_class, "tokenExpired", "tokenExpired"), _defineProperty__default["default"](_class, "typingEnded", "typingEnded"), _defineProperty__default["default"](_class, "typingStarted", "typingStarted"), _defineProperty__default["default"](_class, "pushNotification", "pushNotification"), _defineProperty__default["default"](_class, "userSubscribed", "userSubscribed"), _defineProperty__default["default"](_class, "userUnsubscribed", "userUnsubscribed"), _defineProperty__default["default"](_class, "userUpdated", "userUpdated"), _defineProperty__default["default"](_class, "stateChanged", "stateChanged"), _defineProperty__default["default"](_class, "initialized", "initialized"), _defineProperty__default["default"](_class, "initFailed", "initFailed"), _defineProperty__default["default"](_class, "connectionStateChanged", "connectionStateChanged"), _defineProperty__default["default"](_class, "connectionError", "connectionError"), _defineProperty__default["default"](_class, "version", version), _defineProperty__default["default"](_class, "_logger", Logger.scope("Client")), _defineProperty__default["default"](_class, "_supportedPushChannels", ["fcm", "apn"]), _defineProperty__default["default"](_class, "_supportedPushDataFields", {
|
|
8819
10830
|
conversation_sid: "conversationSid",
|
|
8820
10831
|
conversation_title: "conversationTitle",
|
|
8821
10832
|
message_sid: "messageSid",
|
|
@@ -8825,6 +10836,8 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
|
|
|
8825
10836
|
|
|
8826
10837
|
}), _class);
|
|
8827
10838
|
|
|
10839
|
+
__decorate([deprecationDecorator.deprecated("token"), __metadata("design:type", String), __metadata("design:paramtypes", [])], exports.Client.prototype, "token", null);
|
|
10840
|
+
|
|
8828
10841
|
__decorate([declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyString), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", Promise)], exports.Client.prototype, "updateToken", null);
|
|
8829
10842
|
|
|
8830
10843
|
__decorate([declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyString), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", Promise)], exports.Client.prototype, "getConversationBySid", null);
|
|
@@ -8853,7 +10866,7 @@ __decorate([declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator
|
|
|
8853
10866
|
|
|
8854
10867
|
__decorate([declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyArray("media", Media)), __metadata("design:type", Function), __metadata("design:paramtypes", [Array]), __metadata("design:returntype", mcsClient.CancellablePromise)], exports.Client.prototype, "getTemporaryContentUrlsForMedia", null);
|
|
8855
10868
|
|
|
8856
|
-
__decorate([declarativeTypeValidator.validateTypesAsync("string", ["undefined", declarativeTypeValidator.pureObject]), __metadata("design:type", Function), __metadata("design:paramtypes", [String, Object]), __metadata("design:returntype", Promise)], exports.Client, "create", null);
|
|
10869
|
+
__decorate([deprecationDecorator.deprecated("Client.create()", "new Client()"), declarativeTypeValidator.validateTypesAsync("string", ["undefined", declarativeTypeValidator.pureObject]), __metadata("design:type", Function), __metadata("design:paramtypes", [String, Object]), __metadata("design:returntype", Promise)], exports.Client, "create", null);
|
|
8857
10870
|
|
|
8858
10871
|
__decorate([declarativeTypeValidator.validateTypes(declarativeTypeValidator.pureObject), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", PushNotification)], exports.Client, "parsePushNotification", null);
|
|
8859
10872
|
|
|
@@ -8864,8 +10877,12 @@ Object.defineProperty(exports, 'CancellablePromise', {
|
|
|
8864
10877
|
get: function () { return mcsClient.CancellablePromise; }
|
|
8865
10878
|
});
|
|
8866
10879
|
exports.AggregatedDeliveryReceipt = AggregatedDeliveryReceipt;
|
|
10880
|
+
exports.ChannelMetadata = ChannelMetadata;
|
|
10881
|
+
exports.ContentTemplate = ContentTemplate;
|
|
10882
|
+
exports.ContentTemplateVariable = ContentTemplateVariable;
|
|
8867
10883
|
exports.Conversation = Conversation;
|
|
8868
10884
|
exports.DetailedDeliveryReceipt = DetailedDeliveryReceipt;
|
|
10885
|
+
exports.EmailRecipientDescriptor = EmailRecipientDescriptor;
|
|
8869
10886
|
exports.Media = Media;
|
|
8870
10887
|
exports.Message = Message;
|
|
8871
10888
|
exports.MessageBuilder = MessageBuilder;
|
|
@@ -8873,6 +10890,7 @@ exports.NotificationTypes = NotificationTypes;
|
|
|
8873
10890
|
exports.Participant = Participant;
|
|
8874
10891
|
exports.PushNotification = PushNotification;
|
|
8875
10892
|
exports.RestPaginator = RestPaginator;
|
|
10893
|
+
exports.UnknownRecipientDescriptor = UnknownRecipientDescriptor;
|
|
8876
10894
|
exports.UnsentMessage = UnsentMessage;
|
|
8877
10895
|
exports.User = User;
|
|
8878
10896
|
//# sourceMappingURL=lib.js.map
|