@twilio/conversations 3.0.0-rc.9 → 3.0.1-rc.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 +10846 -0
- package/builds/browser.esm.js.map +1 -0
- package/builds/browser.js +2505 -479
- 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 +10845 -0
- package/builds/lib.js +2505 -479
- package/builds/lib.js.map +1 -1
- package/builds/twilio-conversations.js +25853 -24412
- 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 +53 -15
- 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/rules.js +160 -0
- 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/dist/{interfaces/attributes.js → utils/uuid.js} +17 -19
- package/dist/utils/uuid.js.map +1 -0
- package/package.json +21 -20
- package/CHANGELOG.md +0 -509
- package/dist/interfaces/attributes.js.map +0 -1
- package/docs/assets/css/main.css +0 -2660
- package/docs/assets/images/icons.png +0 -0
- package/docs/assets/images/icons@2x.png +0 -0
- package/docs/assets/images/widgets.png +0 -0
- package/docs/assets/images/widgets@2x.png +0 -0
- package/docs/assets/js/main.js +0 -248
- package/docs/assets/js/search.js +0 -1
- package/docs/classes/AggregatedDeliveryReceipt.html +0 -3184
- package/docs/classes/CancellablePromise.html +0 -3213
- package/docs/classes/Client.html +0 -4239
- package/docs/classes/Conversation.html +0 -4354
- package/docs/classes/DetailedDeliveryReceipt.html +0 -3163
- package/docs/classes/Media.html +0 -3167
- package/docs/classes/Message.html +0 -3732
- package/docs/classes/MessageBuilder.html +0 -3277
- package/docs/classes/Participant.html +0 -3444
- package/docs/classes/PushNotification.html +0 -3130
- package/docs/classes/RestPaginator.html +0 -3160
- package/docs/classes/UnsentMessage.html +0 -3042
- package/docs/classes/User.html +0 -3349
- package/docs/index.html +0 -3509
- package/docs/interfaces/ClientOptions.html +0 -3034
- package/docs/interfaces/ConversationBindings.html +0 -3001
- package/docs/interfaces/ConversationEmailBinding.html +0 -3001
- package/docs/interfaces/ConversationLimits.html +0 -3098
- package/docs/interfaces/ConversationState.html +0 -3050
- package/docs/interfaces/ConversationUpdatedEventArgs.html +0 -3001
- package/docs/interfaces/CreateConversationOptions.html +0 -3066
- package/docs/interfaces/LastMessage.html +0 -3050
- package/docs/interfaces/Paginator.html +0 -3141
- package/docs/interfaces/ParticipantBindings.html +0 -3001
- package/docs/interfaces/ParticipantEmailBinding.html +0 -3001
- package/docs/interfaces/PushNotificationData.html +0 -3114
- package/docs/interfaces/SendEmailOptions.html +0 -3034
- package/docs/interfaces/SendMediaOptions.html +0 -3068
- package/docs/modules.html +0 -3510
package/dist/message.js
CHANGED
|
@@ -126,68 +126,70 @@ This software includes platform.js under the following license.
|
|
|
126
126
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
127
127
|
|
|
128
128
|
*/
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
129
|
+
var global =
|
|
130
|
+
typeof global !== "undefined"
|
|
131
|
+
? global
|
|
132
|
+
: typeof self !== "undefined"
|
|
133
|
+
? self
|
|
134
|
+
: typeof window !== "undefined"
|
|
135
|
+
? window
|
|
136
|
+
: {};
|
|
137
|
+
|
|
138
|
+
import { __decorate, __metadata, __classPrivateFieldGet } from './node_modules/tslib/tslib.es6.js';
|
|
139
|
+
import { parseAttributes, isEqual, UriBuilder } from './util/index.js';
|
|
140
|
+
import { Logger } from './logger.js';
|
|
141
|
+
import { CancellablePromise } from '@twilio/mcs-client';
|
|
142
|
+
import { Media } from './media.js';
|
|
143
|
+
import { AggregatedDeliveryReceipt } from './aggregated-delivery-receipt.js';
|
|
144
|
+
import { validateTypes, nonEmptyString, validateTypesAsync, nonEmptyArray } from '@twilio/declarative-type-validator';
|
|
145
|
+
import { json } from './interfaces/rules.js';
|
|
146
|
+
import { RestPaginator } from './rest-paginator.js';
|
|
147
|
+
import { DetailedDeliveryReceipt } from './detailed-delivery-receipt.js';
|
|
148
|
+
import { ReplayEventEmitter } from '@twilio/replay-event-emitter';
|
|
149
|
+
import { deprecated } from '@twilio/deprecation-decorator';
|
|
150
|
+
import { parseVariant } from './content-template.js';
|
|
151
|
+
|
|
152
|
+
var _Message_instances, _Message_wrapMedia, _Message_assignMedias;
|
|
153
|
+
const log = Logger.scope("Message");
|
|
154
|
+
const XHR =
|
|
155
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
156
|
+
global["XMLHttpRequest"] || {};
|
|
151
157
|
/**
|
|
152
158
|
* A message in a conversation.
|
|
153
159
|
*/
|
|
154
|
-
class Message extends
|
|
160
|
+
class Message extends ReplayEventEmitter {
|
|
155
161
|
/**
|
|
156
162
|
* @internal
|
|
157
163
|
*/
|
|
158
|
-
constructor(index
|
|
159
|
-
var _a, _b, _c, _d;
|
|
164
|
+
constructor(index, data, conversation, links, configuration, services) {
|
|
165
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
160
166
|
super();
|
|
167
|
+
_Message_instances.add(this);
|
|
161
168
|
this.conversation = conversation;
|
|
162
169
|
this.links = links;
|
|
163
170
|
this.configuration = configuration;
|
|
164
171
|
this.services = services;
|
|
165
172
|
this.state = {
|
|
166
173
|
sid: data.sid,
|
|
167
|
-
index: index
|
|
174
|
+
index: index,
|
|
168
175
|
author: data.author,
|
|
169
176
|
subject: data.subject,
|
|
177
|
+
contentSid: data.contentSid,
|
|
170
178
|
body: (_a = data.text) !== null && _a !== void 0 ? _a : null,
|
|
171
179
|
timestamp: data.timestamp ? new Date(data.timestamp) : null,
|
|
172
180
|
dateUpdated: data.dateUpdated ? new Date(data.dateUpdated) : null,
|
|
173
181
|
lastUpdatedBy: (_b = data.lastUpdatedBy) !== null && _b !== void 0 ? _b : null,
|
|
174
|
-
attributes:
|
|
182
|
+
attributes: parseAttributes(data.attributes, `Got malformed attributes for the message ${data.sid}`, log),
|
|
175
183
|
type: (_c = data.type) !== null && _c !== void 0 ? _c : "text",
|
|
176
|
-
media:
|
|
177
|
-
|
|
178
|
-
: null,
|
|
179
|
-
medias: data.type === "media" && data.medias
|
|
180
|
-
? data.medias.map((m) => new media.Media(m, this.services))
|
|
181
|
-
: data.type === "media" && data.media && !data.medias
|
|
182
|
-
? [
|
|
183
|
-
new media.Media(Object.assign(Object.assign({}, data.media), { category: "media" }), this.services),
|
|
184
|
-
]
|
|
185
|
-
: null,
|
|
184
|
+
media: null,
|
|
185
|
+
medias: null,
|
|
186
186
|
participantSid: (_d = data.memberSid) !== null && _d !== void 0 ? _d : null,
|
|
187
187
|
aggregatedDeliveryReceipt: data.delivery
|
|
188
|
-
? new
|
|
188
|
+
? new AggregatedDeliveryReceipt(data.delivery)
|
|
189
189
|
: null,
|
|
190
|
+
hasChannelMetadata: (_e = data.channelMetadata) !== null && _e !== void 0 ? _e : false,
|
|
190
191
|
};
|
|
192
|
+
__classPrivateFieldGet(this, _Message_instances, "m", _Message_assignMedias).call(this, (_f = data.medias) !== null && _f !== void 0 ? _f : null, (_g = data.media) !== null && _g !== void 0 ? _g : null);
|
|
191
193
|
}
|
|
192
194
|
/**
|
|
193
195
|
* The server-assigned unique identifier for the message.
|
|
@@ -207,6 +209,12 @@ class Message extends replayEventEmitter.ReplayEventEmitter {
|
|
|
207
209
|
get subject() {
|
|
208
210
|
return this.state.subject;
|
|
209
211
|
}
|
|
212
|
+
/**
|
|
213
|
+
* Unique identifier of {@link ContentTemplate} for this message.
|
|
214
|
+
*/
|
|
215
|
+
get contentSid() {
|
|
216
|
+
return this.state.contentSid;
|
|
217
|
+
}
|
|
210
218
|
/**
|
|
211
219
|
* Body of the message.
|
|
212
220
|
*/
|
|
@@ -220,14 +228,15 @@ class Message extends replayEventEmitter.ReplayEventEmitter {
|
|
|
220
228
|
return this.state.dateUpdated;
|
|
221
229
|
}
|
|
222
230
|
/**
|
|
223
|
-
* Index of
|
|
224
|
-
*
|
|
231
|
+
* Index of this message in the conversation's list of messages.
|
|
232
|
+
*
|
|
233
|
+
* By design, the message indices may have arbitrary gaps between them,
|
|
225
234
|
* that does not necessarily mean they were deleted or otherwise modified - just that
|
|
226
235
|
* messages may have some non-contiguous indices even if they are being sent immediately one after another.
|
|
227
236
|
*
|
|
228
237
|
* Trying to use indices for some calculations is going to be unreliable.
|
|
229
238
|
*
|
|
230
|
-
* To calculate the number of unread messages it is better to use the
|
|
239
|
+
* To calculate the number of unread messages, it is better to use the Read Horizon API.
|
|
231
240
|
* See {@link Conversation.getUnreadMessagesCount} for details.
|
|
232
241
|
*/
|
|
233
242
|
get index() {
|
|
@@ -282,6 +291,16 @@ class Message extends replayEventEmitter.ReplayEventEmitter {
|
|
|
282
291
|
get aggregatedDeliveryReceipt() {
|
|
283
292
|
return this.state.aggregatedDeliveryReceipt;
|
|
284
293
|
}
|
|
294
|
+
/**
|
|
295
|
+
* @deprecated
|
|
296
|
+
* Return a (possibly empty) array of media matching a specific set of categories.
|
|
297
|
+
* Allowed category is so far only 'media'.
|
|
298
|
+
* @param categories Array of categories to match.
|
|
299
|
+
* @returns Array of media descriptors matching given categories.
|
|
300
|
+
*/
|
|
301
|
+
getMediaByCategory(categories) {
|
|
302
|
+
return this.getMediaByCategories(categories);
|
|
303
|
+
}
|
|
285
304
|
/**
|
|
286
305
|
* Return a (possibly empty) array of media matching a specific set of categories.
|
|
287
306
|
* Allowed category is so far only 'media'.
|
|
@@ -311,6 +330,7 @@ class Message extends replayEventEmitter.ReplayEventEmitter {
|
|
|
311
330
|
return ((_b = (_a = this.getMediaByCategories(["history"])) === null || _a === void 0 ? void 0 : _a.filter((m) => m.contentType == type).shift()) !== null && _b !== void 0 ? _b : null);
|
|
312
331
|
}
|
|
313
332
|
_update(data) {
|
|
333
|
+
var _a, _b, _c, _d, _e, _f;
|
|
314
334
|
const updateReasons = [];
|
|
315
335
|
if ((data.text || typeof data.text === "string") &&
|
|
316
336
|
data.text !== this.state.body) {
|
|
@@ -341,8 +361,8 @@ class Message extends replayEventEmitter.ReplayEventEmitter {
|
|
|
341
361
|
this.state.timestamp = new Date(data.timestamp);
|
|
342
362
|
updateReasons.push("dateCreated");
|
|
343
363
|
}
|
|
344
|
-
const updatedAttributes =
|
|
345
|
-
if (!
|
|
364
|
+
const updatedAttributes = parseAttributes(data.attributes, `Got malformed attributes for the message ${this.sid}`, log);
|
|
365
|
+
if (!isEqual(this.state.attributes, updatedAttributes)) {
|
|
346
366
|
this.state.attributes = updatedAttributes;
|
|
347
367
|
updateReasons.push("attributes");
|
|
348
368
|
}
|
|
@@ -357,7 +377,7 @@ class Message extends replayEventEmitter.ReplayEventEmitter {
|
|
|
357
377
|
!!updatedAggregatedDelivery.undelivered;
|
|
358
378
|
if (isUpdatedAggregateDeliveryValid) {
|
|
359
379
|
if (!currentAggregatedDelivery) {
|
|
360
|
-
this.state.aggregatedDeliveryReceipt = new
|
|
380
|
+
this.state.aggregatedDeliveryReceipt = new AggregatedDeliveryReceipt(updatedAggregatedDelivery);
|
|
361
381
|
updateReasons.push("deliveryReceipt");
|
|
362
382
|
}
|
|
363
383
|
else if (!currentAggregatedDelivery._isEquals(updatedAggregatedDelivery)) {
|
|
@@ -365,6 +385,19 @@ class Message extends replayEventEmitter.ReplayEventEmitter {
|
|
|
365
385
|
updateReasons.push("deliveryReceipt");
|
|
366
386
|
}
|
|
367
387
|
}
|
|
388
|
+
// @fixme: This is a fairly heavy check.
|
|
389
|
+
// Map data back and forth to perform a necessary field massage.
|
|
390
|
+
const input = ((_a = data.medias) !== null && _a !== void 0 ? _a : [])
|
|
391
|
+
.map((value) => { var _a; return (_a = __classPrivateFieldGet(this, _Message_instances, "m", _Message_wrapMedia).call(this, value)) === null || _a === void 0 ? void 0 : _a._state(); })
|
|
392
|
+
.filter((el) => !(el === null));
|
|
393
|
+
const current = ((_b = this.state.medias) !== null && _b !== void 0 ? _b : [])
|
|
394
|
+
.map((value) => value._state())
|
|
395
|
+
.filter((el) => !(el === null));
|
|
396
|
+
if (!isEqual(input, current) ||
|
|
397
|
+
!isEqual((_c = __classPrivateFieldGet(this, _Message_instances, "m", _Message_wrapMedia).call(this, data.media)) === null || _c === void 0 ? void 0 : _c._state(), (_d = this.state.media) === null || _d === void 0 ? void 0 : _d._state())) {
|
|
398
|
+
__classPrivateFieldGet(this, _Message_instances, "m", _Message_assignMedias).call(this, (_e = data.medias) !== null && _e !== void 0 ? _e : null, (_f = data.media) !== null && _f !== void 0 ? _f : null);
|
|
399
|
+
updateReasons.push("media");
|
|
400
|
+
}
|
|
368
401
|
if (updateReasons.length > 0) {
|
|
369
402
|
this.emit("updated", { message: this, updateReasons: updateReasons });
|
|
370
403
|
}
|
|
@@ -393,37 +426,34 @@ class Message extends replayEventEmitter.ReplayEventEmitter {
|
|
|
393
426
|
if (participant) {
|
|
394
427
|
return participant;
|
|
395
428
|
}
|
|
396
|
-
let
|
|
429
|
+
let errorMessage = "Participant with ";
|
|
397
430
|
if (this.state.participantSid) {
|
|
398
|
-
|
|
431
|
+
errorMessage += "SID '" + this.state.participantSid + "' ";
|
|
399
432
|
}
|
|
400
433
|
if (this.state.author) {
|
|
401
434
|
if (this.state.participantSid) {
|
|
402
|
-
|
|
435
|
+
errorMessage += "or ";
|
|
403
436
|
}
|
|
404
|
-
|
|
437
|
+
errorMessage += "identity '" + this.state.author + "' ";
|
|
405
438
|
}
|
|
406
|
-
if (
|
|
407
|
-
|
|
439
|
+
if (errorMessage === "Participant with ") {
|
|
440
|
+
errorMessage = "Participant ";
|
|
408
441
|
}
|
|
409
|
-
|
|
410
|
-
throw new Error(
|
|
442
|
+
errorMessage += "was not found";
|
|
443
|
+
throw new Error(errorMessage);
|
|
411
444
|
}
|
|
412
445
|
/**
|
|
413
446
|
* Get the delivery receipts of the message.
|
|
414
447
|
*/
|
|
415
448
|
async getDetailedDeliveryReceipts() {
|
|
416
449
|
let paginator = await this._getDetailedDeliveryReceiptsPaginator();
|
|
417
|
-
let detailedDeliveryReceipts =
|
|
418
|
-
while (
|
|
450
|
+
let detailedDeliveryReceipts = paginator.items;
|
|
451
|
+
while (paginator.hasNextPage) {
|
|
452
|
+
paginator = await paginator.nextPage();
|
|
419
453
|
detailedDeliveryReceipts = [
|
|
420
454
|
...detailedDeliveryReceipts,
|
|
421
455
|
...paginator.items,
|
|
422
456
|
];
|
|
423
|
-
if (!paginator.hasNextPage) {
|
|
424
|
-
break;
|
|
425
|
-
}
|
|
426
|
-
paginator = await paginator.nextPage();
|
|
427
457
|
}
|
|
428
458
|
return detailedDeliveryReceipts;
|
|
429
459
|
}
|
|
@@ -456,6 +486,24 @@ class Message extends replayEventEmitter.ReplayEventEmitter {
|
|
|
456
486
|
});
|
|
457
487
|
return this;
|
|
458
488
|
}
|
|
489
|
+
/**
|
|
490
|
+
* @deprecated
|
|
491
|
+
* Get content URLs for all media attachments in the given set using a single operation.
|
|
492
|
+
* @param contentSet Set of media attachments to query content URLs.
|
|
493
|
+
*/
|
|
494
|
+
async attachTemporaryUrlsFor(contentSet) {
|
|
495
|
+
// We ignore existing mcsMedia members of each of the media entries.
|
|
496
|
+
// Instead we just collect their sids and pull new descriptors from a mediaSet GET endpoint.
|
|
497
|
+
const sids = contentSet === null || contentSet === void 0 ? void 0 : contentSet.map((m) => m.sid);
|
|
498
|
+
if (this.services.mcsClient && sids) {
|
|
499
|
+
return (await this.services.mcsClient.mediaSetGet(sids)).map((item) => {
|
|
500
|
+
return new Media(item, this.services);
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
else {
|
|
504
|
+
throw new Error("Media Content Service is unavailable");
|
|
505
|
+
}
|
|
506
|
+
}
|
|
459
507
|
/**
|
|
460
508
|
* Get content URLs for all media attachments in the given set using a single operation.
|
|
461
509
|
* @param contentSet Set of media attachments to query content URLs.
|
|
@@ -471,7 +519,7 @@ class Message extends replayEventEmitter.ReplayEventEmitter {
|
|
|
471
519
|
* @param mediaSids Set of media sids to query for the content URL.
|
|
472
520
|
*/
|
|
473
521
|
getTemporaryContentUrlsForMediaSids(mediaSids) {
|
|
474
|
-
return new
|
|
522
|
+
return new CancellablePromise(async (resolve, reject, onCancel) => {
|
|
475
523
|
const mediaGetRequest = this.services.mcsClient.mediaSetGetContentUrls(mediaSids !== null && mediaSids !== void 0 ? mediaSids : []);
|
|
476
524
|
if (!this.services.mcsClient || !mediaSids) {
|
|
477
525
|
reject(new Error("Media Content Service is unavailable"));
|
|
@@ -502,14 +550,120 @@ class Message extends replayEventEmitter.ReplayEventEmitter {
|
|
|
502
550
|
const messagesReceiptsUrl = this.configuration.links.messagesReceipts
|
|
503
551
|
.replace("%s", this.conversation.sid)
|
|
504
552
|
.replace("%s", this.sid);
|
|
505
|
-
const url = new
|
|
553
|
+
const url = new UriBuilder(messagesReceiptsUrl)
|
|
506
554
|
.arg("PageToken", options === null || options === void 0 ? void 0 : options.pageToken)
|
|
507
555
|
.arg("PageSize", options === null || options === void 0 ? void 0 : options.pageSize)
|
|
508
556
|
.build();
|
|
509
557
|
const response = await this.services.network.get(url);
|
|
510
|
-
return new
|
|
558
|
+
return new RestPaginator(response.body.delivery_receipts.map((x) => new DetailedDeliveryReceipt(x)), (pageToken, pageSize) => this._getDetailedDeliveryReceiptsPaginator({ pageToken, pageSize }), response.body.meta.previous_token, response.body.meta.next_token);
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* Get the {@link ContentData} for this message. Resolves to `null` when
|
|
562
|
+
* {@link Message.contentSid} is null.
|
|
563
|
+
*/
|
|
564
|
+
getContentData() {
|
|
565
|
+
return new CancellablePromise(async (resolve, reject, onCancel) => {
|
|
566
|
+
if (this.state.contentSid === null) {
|
|
567
|
+
resolve(null);
|
|
568
|
+
return;
|
|
569
|
+
}
|
|
570
|
+
const bodies = this.getMediaByCategories(["body"]);
|
|
571
|
+
if (bodies === null) {
|
|
572
|
+
resolve(null);
|
|
573
|
+
return;
|
|
574
|
+
}
|
|
575
|
+
const twilioPrefix = "application/x-vnd.com.twilio.rich.";
|
|
576
|
+
const filteredMedias = bodies.filter((media) => media.contentType.startsWith(twilioPrefix));
|
|
577
|
+
if (filteredMedias.length === 0) {
|
|
578
|
+
resolve(null);
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
581
|
+
const contentMedia = filteredMedias[0];
|
|
582
|
+
const urlPromise = contentMedia.getContentTemporaryUrl();
|
|
583
|
+
onCancel(() => {
|
|
584
|
+
urlPromise.cancel();
|
|
585
|
+
});
|
|
586
|
+
let url;
|
|
587
|
+
try {
|
|
588
|
+
url = await urlPromise;
|
|
589
|
+
}
|
|
590
|
+
catch (e) {
|
|
591
|
+
reject(e);
|
|
592
|
+
return;
|
|
593
|
+
}
|
|
594
|
+
if (url === null) {
|
|
595
|
+
resolve(null);
|
|
596
|
+
return;
|
|
597
|
+
}
|
|
598
|
+
const jsonStringPromise = new Promise((resolve, reject) => {
|
|
599
|
+
let isCancelled = false;
|
|
600
|
+
const xhr = new XHR();
|
|
601
|
+
xhr.open("GET", url !== null && url !== void 0 ? url : "", true);
|
|
602
|
+
xhr.responseType = "text";
|
|
603
|
+
xhr.onreadystatechange = () => {
|
|
604
|
+
if (xhr.readyState !== 4 || isCancelled) {
|
|
605
|
+
return;
|
|
606
|
+
}
|
|
607
|
+
resolve(xhr.responseText);
|
|
608
|
+
};
|
|
609
|
+
xhr.onerror = () => {
|
|
610
|
+
reject(xhr.statusText);
|
|
611
|
+
};
|
|
612
|
+
onCancel(() => {
|
|
613
|
+
isCancelled = true;
|
|
614
|
+
xhr.abort();
|
|
615
|
+
reject(new Error("XHR has been aborted"));
|
|
616
|
+
});
|
|
617
|
+
xhr.send();
|
|
618
|
+
});
|
|
619
|
+
let json;
|
|
620
|
+
try {
|
|
621
|
+
const jsonString = await jsonStringPromise;
|
|
622
|
+
json = JSON.parse(jsonString);
|
|
623
|
+
}
|
|
624
|
+
catch (e) {
|
|
625
|
+
reject(e);
|
|
626
|
+
return;
|
|
627
|
+
}
|
|
628
|
+
const dataType = contentMedia.contentType
|
|
629
|
+
.replace(twilioPrefix, "")
|
|
630
|
+
.replace(".", "/");
|
|
631
|
+
resolve(parseVariant(dataType, json.data));
|
|
632
|
+
});
|
|
633
|
+
}
|
|
634
|
+
/**
|
|
635
|
+
* Get the {@link ChannelMetadata} for this message. Resolves to `null` if
|
|
636
|
+
* the message doesn't have any channel metadata.
|
|
637
|
+
*/
|
|
638
|
+
async getChannelMetadata() {
|
|
639
|
+
if (!this.state.hasChannelMetadata) {
|
|
640
|
+
return null;
|
|
641
|
+
}
|
|
642
|
+
return await this.services.channelMetadataClient.getChannelMetadata(this.conversation.sid, this.sid);
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
645
|
+
* Get recipients of the message.
|
|
646
|
+
*/
|
|
647
|
+
async getMessageRecipients() {
|
|
648
|
+
return await this.services.messageRecipientsClient.getRecipientsFromMessage(this.conversation.sid, this.sid);
|
|
511
649
|
}
|
|
512
650
|
}
|
|
651
|
+
_Message_instances = new WeakSet(), _Message_wrapMedia = function _Message_wrapMedia(media, category = null) {
|
|
652
|
+
return media
|
|
653
|
+
? category
|
|
654
|
+
? new Media(Object.assign(Object.assign({}, media), { category }), this.services)
|
|
655
|
+
: new Media(media, this.services)
|
|
656
|
+
: null;
|
|
657
|
+
}, _Message_assignMedias = function _Message_assignMedias(medias, media) {
|
|
658
|
+
this.state.media = __classPrivateFieldGet(this, _Message_instances, "m", _Message_wrapMedia).call(this, media);
|
|
659
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
660
|
+
// @ts-ignore
|
|
661
|
+
this.state.medias = medias
|
|
662
|
+
? medias.map((m) => __classPrivateFieldGet(this, _Message_instances, "m", _Message_wrapMedia).call(this, m)).filter((el) => el !== null)
|
|
663
|
+
: media && !medias
|
|
664
|
+
? [__classPrivateFieldGet(this, _Message_instances, "m", _Message_wrapMedia).call(this, media, "media")].filter((el) => el !== null)
|
|
665
|
+
: null;
|
|
666
|
+
};
|
|
513
667
|
/**
|
|
514
668
|
* Fired when the properties or the body of the message has been updated.
|
|
515
669
|
*
|
|
@@ -519,42 +673,54 @@ class Message extends replayEventEmitter.ReplayEventEmitter {
|
|
|
519
673
|
* * {@link MessageUpdateReason}[] updateReasons - array of reasons for the update
|
|
520
674
|
*/
|
|
521
675
|
Message.updated = "updated";
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
676
|
+
__decorate([
|
|
677
|
+
deprecated("getMediaByCategory", "getMediaByCategories"),
|
|
678
|
+
__metadata("design:type", Function),
|
|
679
|
+
__metadata("design:paramtypes", [Array]),
|
|
680
|
+
__metadata("design:returntype", Array)
|
|
681
|
+
], Message.prototype, "getMediaByCategory", null);
|
|
682
|
+
__decorate([
|
|
683
|
+
validateTypes([nonEmptyString, "undefined"]),
|
|
684
|
+
__metadata("design:type", Function),
|
|
685
|
+
__metadata("design:paramtypes", [Object]),
|
|
686
|
+
__metadata("design:returntype", Media)
|
|
527
687
|
], Message.prototype, "getEmailBody", null);
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
688
|
+
__decorate([
|
|
689
|
+
validateTypes([nonEmptyString, "undefined"]),
|
|
690
|
+
__metadata("design:type", Function),
|
|
691
|
+
__metadata("design:paramtypes", [Object]),
|
|
692
|
+
__metadata("design:returntype", Media)
|
|
533
693
|
], Message.prototype, "getEmailHistory", null);
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
694
|
+
__decorate([
|
|
695
|
+
validateTypesAsync("string"),
|
|
696
|
+
__metadata("design:type", Function),
|
|
697
|
+
__metadata("design:paramtypes", [String]),
|
|
698
|
+
__metadata("design:returntype", Promise)
|
|
539
699
|
], Message.prototype, "updateBody", null);
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
700
|
+
__decorate([
|
|
701
|
+
validateTypesAsync(json),
|
|
702
|
+
__metadata("design:type", Function),
|
|
703
|
+
__metadata("design:paramtypes", [Object]),
|
|
704
|
+
__metadata("design:returntype", Promise)
|
|
545
705
|
], Message.prototype, "updateAttributes", null);
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
706
|
+
__decorate([
|
|
707
|
+
deprecated("attachTemporaryUrlsFor", "getTemporaryContentUrlsForMedia"),
|
|
708
|
+
__metadata("design:type", Function),
|
|
709
|
+
__metadata("design:paramtypes", [Array]),
|
|
710
|
+
__metadata("design:returntype", Promise)
|
|
711
|
+
], Message.prototype, "attachTemporaryUrlsFor", null);
|
|
712
|
+
__decorate([
|
|
713
|
+
validateTypesAsync(nonEmptyArray("media", Media)),
|
|
714
|
+
__metadata("design:type", Function),
|
|
715
|
+
__metadata("design:paramtypes", [Array]),
|
|
716
|
+
__metadata("design:returntype", CancellablePromise)
|
|
551
717
|
], Message.prototype, "getTemporaryContentUrlsForMedia", null);
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
718
|
+
__decorate([
|
|
719
|
+
validateTypesAsync(nonEmptyArray("strings", "string")),
|
|
720
|
+
__metadata("design:type", Function),
|
|
721
|
+
__metadata("design:paramtypes", [Array]),
|
|
722
|
+
__metadata("design:returntype", CancellablePromise)
|
|
557
723
|
], Message.prototype, "getTemporaryContentUrlsForMediaSids", null);
|
|
558
724
|
|
|
559
|
-
|
|
725
|
+
export { Message };
|
|
560
726
|
//# sourceMappingURL=message.js.map
|