@twilio/conversations 2.5.0-rc.8 → 2.6.0-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 +2 -2
- package/builds/browser.esm.js +10713 -0
- package/builds/browser.esm.js.map +1 -0
- package/builds/browser.js +241 -81
- package/builds/browser.js.map +1 -1
- package/builds/lib.d.ts +10 -9
- package/builds/lib.esm.d.ts +3166 -0
- package/builds/lib.esm.js +10712 -0
- package/builds/lib.js +250 -81
- package/builds/lib.js.map +1 -1
- package/builds/twilio-conversations.js +11231 -11244
- package/builds/twilio-conversations.min.js +1 -1
- package/dist/aggregated-delivery-receipt.js +3 -5
- package/dist/aggregated-delivery-receipt.js.map +1 -1
- package/dist/channel-metadata-client.js +7 -9
- package/dist/channel-metadata-client.js.map +1 -1
- package/dist/client.js +201 -166
- package/dist/client.js.map +1 -1
- package/dist/command-executor.js +8 -8
- package/dist/command-executor.js.map +1 -1
- package/dist/configuration.js +12 -9
- package/dist/configuration.js.map +1 -1
- package/dist/content-client.js +11 -8
- package/dist/content-client.js.map +1 -1
- package/dist/content-template.js +3 -5
- package/dist/content-template.js.map +1 -1
- package/dist/conversation.js +130 -96
- package/dist/conversation.js.map +1 -1
- package/dist/data/conversations.js +36 -43
- package/dist/data/conversations.js.map +1 -1
- package/dist/data/messages.js +23 -21
- package/dist/data/messages.js.map +1 -1
- package/dist/data/participants.js +27 -24
- package/dist/data/participants.js.map +1 -1
- package/dist/data/users.js +15 -13
- package/dist/data/users.js.map +1 -1
- package/dist/detailed-delivery-receipt.js +3 -5
- package/dist/detailed-delivery-receipt.js.map +1 -1
- package/dist/index.js +17 -49
- package/dist/index.js.map +1 -1
- package/dist/interfaces/notification-types.js +1 -5
- package/dist/interfaces/notification-types.js.map +1 -1
- package/dist/interfaces/rules.js +13 -10
- package/dist/interfaces/rules.js.map +1 -1
- package/dist/logger.js +25 -26
- package/dist/logger.js.map +1 -1
- package/dist/media.js +11 -8
- package/dist/media.js.map +1 -1
- package/dist/message-builder.js +48 -40
- package/dist/message-builder.js.map +1 -1
- package/dist/message-recipients-client.js +11 -13
- package/dist/message-recipients-client.js.map +1 -1
- package/dist/message.js +96 -83
- package/dist/message.js.map +1 -1
- package/dist/node_modules/quick-lru/index.js +1 -5
- package/dist/node_modules/quick-lru/index.js.map +1 -1
- package/dist/node_modules/tslib/tslib.es6.js +1 -7
- package/dist/node_modules/tslib/tslib.es6.js.map +1 -1
- package/dist/packages/conversations/package.json.js +2 -6
- package/dist/packages/conversations/package.json.js.map +1 -1
- package/dist/participant.js +40 -31
- package/dist/participant.js.map +1 -1
- package/dist/push-notification.js +5 -4
- package/dist/push-notification.js.map +1 -1
- package/dist/rest-paginator.js +9 -8
- package/dist/rest-paginator.js.map +1 -1
- package/dist/services/network.js +3 -7
- package/dist/services/network.js.map +1 -1
- package/dist/services/typing-indicator.js +11 -8
- package/dist/services/typing-indicator.js.map +1 -1
- package/dist/unsent-message.js +9 -8
- package/dist/unsent-message.js.map +1 -1
- package/dist/user.js +27 -24
- package/dist/user.js.map +1 -1
- package/dist/util/deferred.js +6 -4
- package/dist/util/deferred.js.map +1 -1
- package/dist/util/index.js +1 -9
- package/dist/util/index.js.map +1 -1
- package/docs/classes/Client.html +2 -2
- package/docs/index.html +3 -3
- package/docs/modules.html +2 -2
- package/package.json +10 -10
package/dist/message-builder.js
CHANGED
@@ -126,8 +126,6 @@ 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
|
-
'use strict';
|
130
|
-
|
131
129
|
var global =
|
132
130
|
typeof global !== "undefined"
|
133
131
|
? global
|
@@ -137,13 +135,11 @@ var global =
|
|
137
135
|
? window
|
138
136
|
: {};
|
139
137
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
var declarativeTypeValidator = require('@twilio/declarative-type-validator');
|
146
|
-
var rules = require('./interfaces/rules.js');
|
138
|
+
import { __decorate, __metadata } from './node_modules/tslib/tslib.es6.js';
|
139
|
+
import { UnsentMessage } from './unsent-message.js';
|
140
|
+
import { ContentTemplateVariable } from './content-template.js';
|
141
|
+
import { validateTypes, array } from '@twilio/declarative-type-validator';
|
142
|
+
import { json, sendMediaOptions } from './interfaces/rules.js';
|
147
143
|
|
148
144
|
/**
|
149
145
|
* Message builder. Allows the message to be built and sent via method chaining.
|
@@ -166,7 +162,7 @@ class MessageBuilder {
|
|
166
162
|
*/
|
167
163
|
constructor(limits, messagesEntity) {
|
168
164
|
this.limits = limits;
|
169
|
-
this.message = new
|
165
|
+
this.message = new UnsentMessage(messagesEntity);
|
170
166
|
this.emailBodies = new Map();
|
171
167
|
this.emailHistories = new Map();
|
172
168
|
}
|
@@ -289,43 +285,55 @@ class MessageBuilder {
|
|
289
285
|
return this.build().send();
|
290
286
|
}
|
291
287
|
}
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
288
|
+
__decorate([
|
289
|
+
validateTypes("string"),
|
290
|
+
__metadata("design:type", Function),
|
291
|
+
__metadata("design:paramtypes", [String]),
|
292
|
+
__metadata("design:returntype", MessageBuilder)
|
297
293
|
], MessageBuilder.prototype, "setBody", null);
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
294
|
+
__decorate([
|
295
|
+
validateTypes("string"),
|
296
|
+
__metadata("design:type", Function),
|
297
|
+
__metadata("design:paramtypes", [String]),
|
298
|
+
__metadata("design:returntype", MessageBuilder)
|
303
299
|
], MessageBuilder.prototype, "setSubject", null);
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
300
|
+
__decorate([
|
301
|
+
validateTypes(json),
|
302
|
+
__metadata("design:type", Function),
|
303
|
+
__metadata("design:paramtypes", [Object]),
|
304
|
+
__metadata("design:returntype", MessageBuilder)
|
309
305
|
], MessageBuilder.prototype, "setAttributes", null);
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
306
|
+
__decorate([
|
307
|
+
validateTypes("string", [FormData, sendMediaOptions]),
|
308
|
+
__metadata("design:type", Function),
|
309
|
+
__metadata("design:paramtypes", [String, Object]),
|
310
|
+
__metadata("design:returntype", MessageBuilder)
|
315
311
|
], MessageBuilder.prototype, "setEmailBody", null);
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
312
|
+
__decorate([
|
313
|
+
validateTypes("string", [FormData, sendMediaOptions]),
|
314
|
+
__metadata("design:type", Function),
|
315
|
+
__metadata("design:paramtypes", [String, Object]),
|
316
|
+
__metadata("design:returntype", MessageBuilder)
|
321
317
|
], MessageBuilder.prototype, "setEmailHistory", null);
|
322
|
-
|
323
|
-
|
324
|
-
|
318
|
+
__decorate([
|
319
|
+
validateTypes("string", [
|
320
|
+
array("content variables", ContentTemplateVariable),
|
325
321
|
"undefined",
|
326
322
|
]),
|
327
|
-
|
328
|
-
|
323
|
+
__metadata("design:type", Function),
|
324
|
+
__metadata("design:paramtypes", [String, Array]),
|
325
|
+
__metadata("design:returntype", MessageBuilder)
|
326
|
+
], MessageBuilder.prototype, "setContentTemplate", null);
|
327
|
+
__decorate([
|
328
|
+
validateTypes([FormData, sendMediaOptions]),
|
329
|
+
__metadata("design:type", Function),
|
330
|
+
__metadata("design:paramtypes", [Object]),
|
331
|
+
__metadata("design:returntype", MessageBuilder)
|
332
|
+
], MessageBuilder.prototype, "addMedia", null);
|
333
|
+
|
334
|
+
export { MessageBuilder };
|
335
|
+
//# sourceMappingURL=message-builder.js.map
|
336
|
+
tslib_es6.__metadata("design:paramtypes", [String, Array]),
|
329
337
|
tslib_es6.__metadata("design:returntype", MessageBuilder)
|
330
338
|
], MessageBuilder.prototype, "setContentTemplate", null);
|
331
339
|
tslib_es6.__decorate([
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"message-builder.js","sources":["../src/message-builder.ts"],"sourcesContent":["import { CancellablePromise } from \"@twilio/mcs-client\";\nimport { ConversationLimits } from \"./interfaces/conversation-limits\";\nimport { SendMediaOptions } from \"./conversation\";\nimport { UnsentMessage } from \"./unsent-message\";\nimport { JSONValue } from \"./types\";\nimport { Messages } from \"./data/messages\";\nimport { ContentTemplateVariable } from \"./content-template\";\nimport { array, validateTypes } from \"@twilio/declarative-type-validator\";\nimport { json, sendMediaOptions } from \"./interfaces/rules\";\n\n/**\n * Message builder. Allows the message to be built and sent via method chaining.\n *\n * Example:\n *\n * ```ts\n * await testConversation.prepareMessage()\n * .setBody('Hello!')\n * .setAttributes({foo: 'bar'})\n * .addMedia(media1)\n * .addMedia(media2)\n * .build()\n * .send();\n * ```\n */\nclass MessageBuilder {\n private readonly message: UnsentMessage;\n private emailBodies: Map<string, FormData | SendMediaOptions>;\n private emailHistories: Map<string, FormData | SendMediaOptions>;\n\n /**\n * @internal\n */\n constructor(\n private readonly limits: ConversationLimits,\n messagesEntity: Messages\n ) {\n this.message = new UnsentMessage(messagesEntity);\n this.emailBodies = new Map<string, FormData | SendMediaOptions>();\n this.emailHistories = new Map<string, FormData | SendMediaOptions>();\n }\n\n /**\n * Sets the message body.\n * @param text Contents of the body.\n */\n @validateTypes(\"string\")\n setBody(text: string): MessageBuilder {\n this.message.text = text;\n return this;\n }\n\n /**\n * Sets the message subject.\n * @param subject Contents of the subject.\n */\n @validateTypes(\"string\")\n setSubject(subject: string): MessageBuilder {\n this.message.emailOptions.subject = subject;\n return this;\n }\n\n /**\n * Sets the message attributes.\n * @param attributes Message attributes.\n */\n @validateTypes(json)\n setAttributes(attributes: JSONValue): MessageBuilder {\n this.message.attributes = attributes;\n return this;\n }\n\n /**\n * Set the email body with a given content type.\n * @param contentType Format of the body to set (text/plain or text/html).\n * @param body Body payload in the selected format.\n */\n @validateTypes(\"string\", [FormData, sendMediaOptions])\n setEmailBody(\n contentType: string,\n body: FormData | SendMediaOptions\n ): MessageBuilder {\n this.emailBodies.set(contentType, body);\n return this;\n }\n\n /**\n * Set the email history with a given content type.\n * @param contentType Format of the history to set (text/plain or text/html).\n * @param history History payload in the selected format.\n */\n @validateTypes(\"string\", [FormData, sendMediaOptions])\n setEmailHistory(\n contentType: string,\n history: FormData | SendMediaOptions\n ): MessageBuilder {\n this.emailHistories.set(contentType, history);\n return this;\n }\n\n /**\n * Adds {@link ContentTemplate} SID for the message alongside optional\n * variables. When no variables provided, the default values will be used.\n *\n * Adding the content SID converts the message to a rich message. In this\n * case, other fields are ignored and the message is sent using the content\n * from the the {@link ContentTemplate}.\n *\n * Use {@link Client.getContentTemplates} to request all available\n * {@link ContentTemplate}s.\n *\n * @param contentSid SID of the {@link ContentTemplate}\n * @param variables Custom variables to resolve the template.\n */\n @validateTypes(\"string\", [\n array(\"content variables\", ContentTemplateVariable),\n \"undefined\",\n ])\n setContentTemplate(\n contentSid: string,\n contentVariables: ContentTemplateVariable[] = []\n ): MessageBuilder {\n this.message.contentSid = contentSid;\n this.message.contentVariables = contentVariables;\n return this;\n }\n\n /**\n * Adds media to the message.\n * @param payload Media to add.\n */\n @validateTypes([FormData, sendMediaOptions])\n addMedia(payload: FormData | SendMediaOptions): MessageBuilder {\n if (typeof FormData === \"undefined\" && payload instanceof FormData) {\n throw new Error(\"Could not add FormData content whilst not in a browser\");\n }\n if (!(payload instanceof FormData)) {\n const mediaOptions = payload as SendMediaOptions;\n if (!mediaOptions.contentType || !mediaOptions.media) {\n throw new Error(\n \"Media content in SendMediaOptions must contain non-empty contentType and media\"\n );\n }\n }\n this.message.mediaContent.push([\"media\", payload]);\n return this;\n }\n\n /**\n * Builds the message, making it ready to be sent.\n */\n build(): UnsentMessage {\n this.emailBodies.forEach((_, key) => {\n if (!this.limits.emailBodiesAllowedContentTypes.includes(key)) {\n throw new Error(`Unsupported email body content type ${key}`);\n }\n });\n this.emailHistories.forEach((_, key) => {\n if (!this.limits.emailHistoriesAllowedContentTypes.includes(key)) {\n throw new Error(`Unsupported email history content type ${key}`);\n }\n });\n if (\n this.emailBodies.size > this.limits.emailBodiesAllowedContentTypes.length\n ) {\n throw new Error(\n `Too many email bodies attached to the message (${this.emailBodies.size} > ${this.limits.emailBodiesAllowedContentTypes.length})`\n );\n }\n if (\n this.emailHistories.size >\n this.limits.emailHistoriesAllowedContentTypes.length\n ) {\n throw new Error(\n `Too many email histories attached to the message (${this.emailHistories.size} > ${this.limits.emailHistoriesAllowedContentTypes.length})`\n );\n }\n\n if (\n this.message.mediaContent.length > this.limits.mediaAttachmentsCountLimit\n ) {\n throw new Error(\n `Too many media attachments in the message (${this.message.mediaContent.length} > ${this.limits.mediaAttachmentsCountLimit})`\n );\n }\n\n // @todo we don't know the sizes of the attachments in FormData\n // @todo insertion below makes build() method non-repeatable - probably move to UnsentMessage.send() or even sendV2()?\n\n this.emailBodies.forEach((body) => {\n this.message.mediaContent.push([\"body\", body]);\n });\n\n this.emailHistories.forEach((history) => {\n this.message.mediaContent.push([\"history\", history]);\n });\n\n return this.message;\n }\n\n /**\n * Prepares a message and sends it to the conversation.\n */\n buildAndSend(): CancellablePromise<number | null> {\n return this.build().send();\n }\n}\n\nexport { MessageBuilder };\n"],"names":["UnsentMessage","__decorate","validateTypes","json","sendMediaOptions","array","ContentTemplateVariable"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA;;;;;;;;;;;;;;AAcG;AACH,MAAM,cAAc,CAAA;AAKlB;;AAEG;IACH,WACmB,CAAA,MAA0B,EAC3C,cAAwB,EAAA;QADP,IAAM,CAAA,MAAA,GAAN,MAAM,CAAoB;QAG3C,IAAI,CAAC,OAAO,GAAG,IAAIA,2BAAa,CAAC,cAAc,CAAC,CAAC;AACjD,QAAA,IAAI,CAAC,WAAW,GAAG,IAAI,GAAG,EAAuC,CAAC;AAClE,QAAA,IAAI,CAAC,cAA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CAAA;AAODD,oBAAA,CAAA;IADCC,sCAAa,CAAC,QAAQ,CAAC;;;8CACK,cAAc,CAAA;AAG1C,CAAA,EAAA,cAAA,CAAA,SAAA,EAAA,YAAA,EAAA,IAAA,CAAA,CAAA;AAODD,oBAAA,CAAA;IADCC,sCAAa,CAACC,UAAI,CAAC;;;8CACkB,cAAc,CAAA;AAGnD,CAAA,EAAA,cAAA,CAAA,SAAA,EAAA,eAAA,EAAA,IAAA,CAAA,CAAA;AAQDF,oBAAA,CAAA;IADCC,sCAAa,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAEE,sBAAgB,CAAC,CAAC;;;8CAInD,cAAc,CAAA;AAGhB,CAAA,EAAA,cAAA,CAAA,SAAA,EAAA,cAAA,EAAA,IAAA,CAAA,CAAA;AAQDH,oBAAA,CAAA;IADCC,sCAAa,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAEE,sBAAgB,CAAC,CAAC;;;8CAInD,cAAc,CAAA;AAGhB,CAAA,EAAA,cAAA,CAAA,SAAA,EAAA,iBAAA,EAAA,IAAA,CAAA,CAAA;AAoBDH,oBAAA,CAAA;IAJCC,sCAAa,CAAC,QAAQ,EAAE;AACvB,QAAAG,8BAAK,CAAC,mBAAmB,EAAEC,uCAAuB,CAAC;QACnD,WAAW;KACZ,CAAC;;;8CAIC,cAAc,CAAA;AAIhB,CAAA,EAAA,cAAA,CAAA,SAAA,EAAA,oBAAA,EAAA,IAAA,CAAA,CAAA;AAODL,oBAAA,CAAA;AADC,IAAAC,sCAAa,CAAC,CAAC,QAAQ,EAAEE,sBAAgB,CAAC,CAAC;;;8CACI,cAAc,CAAA;AAc7D,CAAA,EAAA,cAAA,CAAA,SAAA,EAAA,UAAA,EAAA,IAAA,CAAA;;;;"}
|
1
|
+
{"version":3,"file":"message-builder.js","sources":["../src/message-builder.ts"],"sourcesContent":["import { CancellablePromise } from \"@twilio/mcs-client\";\nimport { ConversationLimits } from \"./interfaces/conversation-limits\";\nimport { SendMediaOptions } from \"./conversation\";\nimport { UnsentMessage } from \"./unsent-message\";\nimport { JSONValue } from \"./types\";\nimport { Messages } from \"./data/messages\";\nimport { ContentTemplateVariable } from \"./content-template\";\nimport { array, validateTypes } from \"@twilio/declarative-type-validator\";\nimport { json, sendMediaOptions } from \"./interfaces/rules\";\n\n/**\n * Message builder. Allows the message to be built and sent via method chaining.\n *\n * Example:\n *\n * ```ts\n * await testConversation.prepareMessage()\n * .setBody('Hello!')\n * .setAttributes({foo: 'bar'})\n * .addMedia(media1)\n * .addMedia(media2)\n * .build()\n * .send();\n * ```\n */\nclass MessageBuilder {\n private readonly message: UnsentMessage;\n private emailBodies: Map<string, FormData | SendMediaOptions>;\n private emailHistories: Map<string, FormData | SendMediaOptions>;\n\n /**\n * @internal\n */\n constructor(\n private readonly limits: ConversationLimits,\n messagesEntity: Messages\n ) {\n this.message = new UnsentMessage(messagesEntity);\n this.emailBodies = new Map<string, FormData | SendMediaOptions>();\n this.emailHistories = new Map<string, FormData | SendMediaOptions>();\n }\n\n /**\n * Sets the message body.\n * @param text Contents of the body.\n */\n @validateTypes(\"string\")\n setBody(text: string): MessageBuilder {\n this.message.text = text;\n return this;\n }\n\n /**\n * Sets the message subject.\n * @param subject Contents of the subject.\n */\n @validateTypes(\"string\")\n setSubject(subject: string): MessageBuilder {\n this.message.emailOptions.subject = subject;\n return this;\n }\n\n /**\n * Sets the message attributes.\n * @param attributes Message attributes.\n */\n @validateTypes(json)\n setAttributes(attributes: JSONValue): MessageBuilder {\n this.message.attributes = attributes;\n return this;\n }\n\n /**\n * Set the email body with a given content type.\n * @param contentType Format of the body to set (text/plain or text/html).\n * @param body Body payload in the selected format.\n */\n @validateTypes(\"string\", [FormData, sendMediaOptions])\n setEmailBody(\n contentType: string,\n body: FormData | SendMediaOptions\n ): MessageBuilder {\n this.emailBodies.set(contentType, body);\n return this;\n }\n\n /**\n * Set the email history with a given content type.\n * @param contentType Format of the history to set (text/plain or text/html).\n * @param history History payload in the selected format.\n */\n @validateTypes(\"string\", [FormData, sendMediaOptions])\n setEmailHistory(\n contentType: string,\n history: FormData | SendMediaOptions\n ): MessageBuilder {\n this.emailHistories.set(contentType, history);\n return this;\n }\n\n /**\n * Adds {@link ContentTemplate} SID for the message alongside optional\n * variables. When no variables provided, the default values will be used.\n *\n * Adding the content SID converts the message to a rich message. In this\n * case, other fields are ignored and the message is sent using the content\n * from the the {@link ContentTemplate}.\n *\n * Use {@link Client.getContentTemplates} to request all available\n * {@link ContentTemplate}s.\n *\n * @param contentSid SID of the {@link ContentTemplate}\n * @param variables Custom variables to resolve the template.\n */\n @validateTypes(\"string\", [\n array(\"content variables\", ContentTemplateVariable),\n \"undefined\",\n ])\n setContentTemplate(\n contentSid: string,\n contentVariables: ContentTemplateVariable[] = []\n ): MessageBuilder {\n this.message.contentSid = contentSid;\n this.message.contentVariables = contentVariables;\n return this;\n }\n\n /**\n * Adds media to the message.\n * @param payload Media to add.\n */\n @validateTypes([FormData, sendMediaOptions])\n addMedia(payload: FormData | SendMediaOptions): MessageBuilder {\n if (typeof FormData === \"undefined\" && payload instanceof FormData) {\n throw new Error(\"Could not add FormData content whilst not in a browser\");\n }\n if (!(payload instanceof FormData)) {\n const mediaOptions = payload as SendMediaOptions;\n if (!mediaOptions.contentType || !mediaOptions.media) {\n throw new Error(\n \"Media content in SendMediaOptions must contain non-empty contentType and media\"\n );\n }\n }\n this.message.mediaContent.push([\"media\", payload]);\n return this;\n }\n\n /**\n * Builds the message, making it ready to be sent.\n */\n build(): UnsentMessage {\n this.emailBodies.forEach((_, key) => {\n if (!this.limits.emailBodiesAllowedContentTypes.includes(key)) {\n throw new Error(`Unsupported email body content type ${key}`);\n }\n });\n this.emailHistories.forEach((_, key) => {\n if (!this.limits.emailHistoriesAllowedContentTypes.includes(key)) {\n throw new Error(`Unsupported email history content type ${key}`);\n }\n });\n if (\n this.emailBodies.size > this.limits.emailBodiesAllowedContentTypes.length\n ) {\n throw new Error(\n `Too many email bodies attached to the message (${this.emailBodies.size} > ${this.limits.emailBodiesAllowedContentTypes.length})`\n );\n }\n if (\n this.emailHistories.size >\n this.limits.emailHistoriesAllowedContentTypes.length\n ) {\n throw new Error(\n `Too many email histories attached to the message (${this.emailHistories.size} > ${this.limits.emailHistoriesAllowedContentTypes.length})`\n );\n }\n\n if (\n this.message.mediaContent.length > this.limits.mediaAttachmentsCountLimit\n ) {\n throw new Error(\n `Too many media attachments in the message (${this.message.mediaContent.length} > ${this.limits.mediaAttachmentsCountLimit})`\n );\n }\n\n // @todo we don't know the sizes of the attachments in FormData\n // @todo insertion below makes build() method non-repeatable - probably move to UnsentMessage.send() or even sendV2()?\n\n this.emailBodies.forEach((body) => {\n this.message.mediaContent.push([\"body\", body]);\n });\n\n this.emailHistories.forEach((history) => {\n this.message.mediaContent.push([\"history\", history]);\n });\n\n return this.message;\n }\n\n /**\n * Prepares a message and sends it to the conversation.\n */\n buildAndSend(): CancellablePromise<number | null> {\n return this.build().send();\n }\n}\n\nexport { MessageBuilder };\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA;;;;;;;;;;;;;;AAcG;AACH,MAAM,cAAc,CAAA;AAKlB;;AAEG;IACH,WACmB,CAAA,MAA0B,EAC3C,cAAwB,EAAA;QADP,IAAM,CAAA,MAAA,GAAN,MAAM,CAAoB;QAG3C,IAAI,CAAC,OAAO,GAAG,IAAI,aAAa,CAAC,cAAc,CAAC,CAAC;AACjD,QAAA,IAAI,CAAC,WAAW,GAAG,IAAI,GAAG,EAAuC,CAAC;AAClE,QAAA,IAAI,CAAC,cAAc,GAAG,IAAI,GAAG,EAAuC,CAAC;KACtE;AAED;;;AAGG;AAEH,IAAA,OAAO,CAAC,IAAY,EAAA;AAClB,QAAA,IAAI,CAAC,OAAO,CAAC,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-
'use strict';
|
130
|
-
|
131
129
|
var global =
|
132
130
|
typeof global !== "undefined"
|
133
131
|
? global
|
@@ -137,11 +135,9 @@ var global =
|
|
137
135
|
? window
|
138
136
|
: {};
|
139
137
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
var index$1 = require('./util/index.js');
|
144
|
-
var restPaginator = require('./rest-paginator.js');
|
138
|
+
import quickLru from './node_modules/quick-lru/index.js';
|
139
|
+
import { UriBuilder } from './util/index.js';
|
140
|
+
import { RestPaginator } from './rest-paginator.js';
|
145
141
|
|
146
142
|
/**
|
147
143
|
* Email recipient descriptor.
|
@@ -179,7 +175,7 @@ class MessageRecipientsClient {
|
|
179
175
|
constructor(services, configuration) {
|
180
176
|
this._services = services;
|
181
177
|
this._configuration = configuration;
|
182
|
-
this._cache = new
|
178
|
+
this._cache = new quickLru({
|
183
179
|
maxSize: configuration.messageRecipientsCacheCapacity,
|
184
180
|
});
|
185
181
|
}
|
@@ -189,7 +185,7 @@ class MessageRecipientsClient {
|
|
189
185
|
if (cachedItem) {
|
190
186
|
return cachedItem.item;
|
191
187
|
}
|
192
|
-
const url = new
|
188
|
+
const url = new UriBuilder(this._configuration.links.conversations)
|
193
189
|
.path(conversationSid)
|
194
190
|
.path("MessageRecipients")
|
195
191
|
.arg("MessageSid", messageSid)
|
@@ -203,7 +199,7 @@ class MessageRecipientsClient {
|
|
203
199
|
}
|
204
200
|
async getRecipientsFromConversation(conversationSid, paginatorOptions) {
|
205
201
|
var _a, _b, _c, _d;
|
206
|
-
const url = new
|
202
|
+
const url = new UriBuilder(this._configuration.links.conversations)
|
207
203
|
.path(conversationSid)
|
208
204
|
.path("MessageRecipients")
|
209
205
|
.arg("PageToken", (_a = paginatorOptions === null || paginatorOptions === void 0 ? void 0 : paginatorOptions.pageToken) !== null && _a !== void 0 ? _a : undefined)
|
@@ -216,10 +212,10 @@ class MessageRecipientsClient {
|
|
216
212
|
const existingMessageRecipients = (_d = (_c = this._cache.get(key)) === null || _c === void 0 ? void 0 : _c.item) !== null && _d !== void 0 ? _d : [];
|
217
213
|
this._cache.set(key, { item: [...existingMessageRecipients, recipient] });
|
218
214
|
}
|
219
|
-
return new
|
215
|
+
return new RestPaginator(allRecipients, (pageToken, pageSize) => this.getRecipientsFromConversation(conversationSid, {
|
220
216
|
pageToken,
|
221
217
|
pageSize,
|
222
|
-
}), recipientsResponse.meta.previous_token, recipientsResponse.meta.next_token
|
218
|
+
}), recipientsResponse.meta.previous_token, recipientsResponse.meta.next_token);
|
223
219
|
}
|
224
220
|
_wrapResponse(recipient) {
|
225
221
|
switch (recipient.type) {
|
@@ -231,7 +227,9 @@ class MessageRecipientsClient {
|
|
231
227
|
}
|
232
228
|
}
|
233
229
|
|
234
|
-
|
230
|
+
export { EmailRecipientDescriptor, MessageRecipientsClient, UnknownRecipientDescriptor };
|
231
|
+
//# sourceMappingURL=message-recipients-client.js.map
|
232
|
+
= EmailRecipientDescriptor;
|
235
233
|
exports.MessageRecipientsClient = MessageRecipientsClient;
|
236
234
|
exports.UnknownRecipientDescriptor = UnknownRecipientDescriptor;
|
237
235
|
//# sourceMappingURL=message-recipients-client.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"message-recipients-client.js","sources":["../src/message-recipients-client.ts"],"sourcesContent":["import { CommandExecutor } from \"./command-executor\";\nimport { Configuration } from \"./configuration\";\nimport QuickLRU from \"quick-lru\";\nimport {\n MessageRecipient,\n MessageRecipientsResponse,\n} from \"./interfaces/commands/message-recipients-response\";\nimport { Paginator } from \"./interfaces/paginator\";\nimport { UriBuilder } from \"./util\";\nimport { ResponseMeta } from \"./interfaces/commands/response-meta\";\nimport { RestPaginator } from \"./rest-paginator\";\n\ntype MessageRecipientsClientServices = {\n commandExecutor: CommandExecutor;\n};\n\ntype MessageRecipientsCacheEntry = {\n item: RecipientDescriptor[];\n};\n\n/**\n * Message recipient descriptor.\n */\ntype RecipientDescriptor =\n | EmailRecipientDescriptor\n | UnknownRecipientDescriptor;\n\n/**\n * Email recipient level.\n */\ntype EmailRecipientLevel = \"to\" | \"from\" | \"cc\";\n\n/**\n * Email recipient descriptor.\n */\nclass EmailRecipientDescriptor {\n /**\n * Type of recipient.\n */\n public readonly type = \"email\";\n\n /**\n * Sid of the message that this recipient belongs to.\n */\n public readonly messageSid: string;\n\n /**\n * Email recipient level.\n */\n public readonly level: EmailRecipientLevel;\n\n /**\n * Name of the recipient.\n */\n public readonly name: string;\n\n /**\n * Address of the recipient.\n */\n public readonly address: string;\n\n /**\n * @internal\n */\n public constructor(recipient: MessageRecipient) {\n this.messageSid = recipient.message_sid;\n this.level = recipient.level;\n this.name = recipient.name;\n this.address = recipient.address;\n }\n}\n\n/**\n * Unknown recipient descriptor. Used to be able to handle recipient types that\n * are not supported by the current version of the SDK.\n */\nclass UnknownRecipientDescriptor {\n /**\n * Type of recipient.\n */\n public readonly type: string;\n\n /**\n * Sid of the message that this recipient belongs to.\n */\n public readonly messageSid: string;\n\n /**\n * Recipient data as a JSON string.\n */\n public readonly rawData: string;\n\n /**\n * @internal\n */\n public constructor(recipient: MessageRecipient) {\n this.type = recipient.type;\n this.messageSid = recipient.message_sid;\n this.rawData = JSON.stringify(recipient);\n }\n}\n\nclass MessageRecipientsClient {\n private readonly _services: MessageRecipientsClientServices;\n private readonly _configuration: Configuration;\n private readonly _cache: QuickLRU<string, MessageRecipientsCacheEntry>;\n\n public constructor(\n services: MessageRecipientsClientServices,\n configuration: Configuration\n ) {\n this._services = services;\n this._configuration = configuration;\n this._cache = new QuickLRU({\n maxSize: configuration.messageRecipientsCacheCapacity,\n });\n }\n\n public async getRecipientsFromMessage(\n conversationSid: string,\n messageSid: string\n ): Promise<RecipientDescriptor[]> {\n const key = `${conversationSid},${messageSid}`;\n const cachedItem = this._cache.get(key);\n\n if (cachedItem) {\n return cachedItem.item;\n }\n\n const url = new UriBuilder(this._configuration.links.conversations)\n .path(conversationSid)\n .path(\"MessageRecipients\")\n .arg(\"MessageSid\", messageSid)\n .build();\n const recipientsResponse =\n await this._services.commandExecutor.fetchResource<\n void,\n MessageRecipientsResponse\n >(url);\n const recipients: RecipientDescriptor[] =\n recipientsResponse.message_recipients.map((recipient) =>\n this._wrapResponse(recipient)\n );\n\n if (recipients.length > 0) {\n this._cache.set(key, { item: recipients });\n }\n\n return recipients;\n }\n\n public async getRecipientsFromConversation(\n conversationSid: string,\n paginatorOptions?: {\n pageToken?: string;\n pageSize?: number;\n }\n ): Promise<Paginator<RecipientDescriptor>> {\n const url = new UriBuilder(this._configuration.links.conversations)\n .path(conversationSid)\n .path(\"MessageRecipients\")\n .arg(\"PageToken\", paginatorOptions?.pageToken ?? undefined)\n .arg(\"PageSize\", paginatorOptions?.pageSize ?? undefined)\n .build();\n const recipientsResponse =\n await this._services.commandExecutor.fetchResource<\n void,\n { message_recipients: MessageRecipient[] } & ResponseMeta\n >(url);\n const allRecipients = recipientsResponse.message_recipients.map(\n (recipient) => this._wrapResponse(recipient)\n );\n\n for (const recipient of allRecipients) {\n const key = `${conversationSid},${recipient.messageSid}`;\n const existingMessageRecipients = this._cache.get(key)?.item ?? [];\n this._cache.set(key, { item: [...existingMessageRecipients, recipient] });\n }\n\n return new RestPaginator<RecipientDescriptor>(\n allRecipients,\n (pageToken, pageSize) =>\n this.getRecipientsFromConversation(conversationSid, {\n pageToken,\n pageSize,\n }),\n recipientsResponse.meta.previous_token,\n recipientsResponse.meta.next_token
|
1
|
+
{"version":3,"file":"message-recipients-client.js","sources":["../src/message-recipients-client.ts"],"sourcesContent":["import { CommandExecutor } from \"./command-executor\";\nimport { Configuration } from \"./configuration\";\nimport QuickLRU from \"quick-lru\";\nimport {\n MessageRecipient,\n MessageRecipientsResponse,\n} from \"./interfaces/commands/message-recipients-response\";\nimport { Paginator } from \"./interfaces/paginator\";\nimport { UriBuilder } from \"./util\";\nimport { ResponseMeta } from \"./interfaces/commands/response-meta\";\nimport { RestPaginator } from \"./rest-paginator\";\n\ntype MessageRecipientsClientServices = {\n commandExecutor: CommandExecutor;\n};\n\ntype MessageRecipientsCacheEntry = {\n item: RecipientDescriptor[];\n};\n\n/**\n * Message recipient descriptor.\n */\ntype RecipientDescriptor =\n | EmailRecipientDescriptor\n | UnknownRecipientDescriptor;\n\n/**\n * Email recipient level.\n */\ntype EmailRecipientLevel = \"to\" | \"from\" | \"cc\";\n\n/**\n * Email recipient descriptor.\n */\nclass EmailRecipientDescriptor {\n /**\n * Type of recipient.\n */\n public readonly type = \"email\";\n\n /**\n * Sid of the message that this recipient belongs to.\n */\n public readonly messageSid: string;\n\n /**\n * Email recipient level.\n */\n public readonly level: EmailRecipientLevel;\n\n /**\n * Name of the recipient.\n */\n public readonly name: string;\n\n /**\n * Address of the recipient.\n */\n public readonly address: string;\n\n /**\n * @internal\n */\n public constructor(recipient: MessageRecipient) {\n this.messageSid = recipient.message_sid;\n this.level = recipient.level;\n this.name = recipient.name;\n this.address = recipient.address;\n }\n}\n\n/**\n * Unknown recipient descriptor. Used to be able to handle recipient types that\n * are not supported by the current version of the SDK.\n */\nclass UnknownRecipientDescriptor {\n /**\n * Type of recipient.\n */\n public readonly type: string;\n\n /**\n * Sid of the message that this recipient belongs to.\n */\n public readonly messageSid: string;\n\n /**\n * Recipient data as a JSON string.\n */\n public readonly rawData: string;\n\n /**\n * @internal\n */\n public constructor(recipient: MessageRecipient) {\n this.type = recipient.type;\n this.messageSid = recipient.message_sid;\n this.rawData = JSON.stringify(recipient);\n }\n}\n\nclass MessageRecipientsClient {\n private readonly _services: MessageRecipientsClientServices;\n private readonly _configuration: Configuration;\n private readonly _cache: QuickLRU<string, MessageRecipientsCacheEntry>;\n\n public constructor(\n services: MessageRecipientsClientServices,\n configuration: Configuration\n ) {\n this._services = services;\n this._configuration = configuration;\n this._cache = new QuickLRU({\n maxSize: configuration.messageRecipientsCacheCapacity,\n });\n }\n\n public async getRecipientsFromMessage(\n conversationSid: string,\n messageSid: string\n ): Promise<RecipientDescriptor[]> {\n const key = `${conversationSid},${messageSid}`;\n const cachedItem = this._cache.get(key);\n\n if (cachedItem) {\n return cachedItem.item;\n }\n\n const url = new UriBuilder(this._configuration.links.conversations)\n .path(conversationSid)\n .path(\"MessageRecipients\")\n .arg(\"MessageSid\", messageSid)\n .build();\n const recipientsResponse =\n await this._services.commandExecutor.fetchResource<\n void,\n MessageRecipientsResponse\n >(url);\n const recipients: RecipientDescriptor[] =\n recipientsResponse.message_recipients.map((recipient) =>\n this._wrapResponse(recipient)\n );\n\n if (recipients.length > 0) {\n this._cache.set(key, { item: recipients });\n }\n\n return recipients;\n }\n\n public async getRecipientsFromConversation(\n conversationSid: string,\n paginatorOptions?: {\n pageToken?: string;\n pageSize?: number;\n }\n ): Promise<Paginator<RecipientDescriptor>> {\n const url = new UriBuilder(this._configuration.links.conversations)\n .path(conversationSid)\n .path(\"MessageRecipients\")\n .arg(\"PageToken\", paginatorOptions?.pageToken ?? undefined)\n .arg(\"PageSize\", paginatorOptions?.pageSize ?? undefined)\n .build();\n const recipientsResponse =\n await this._services.commandExecutor.fetchResource<\n void,\n { message_recipients: MessageRecipient[] } & ResponseMeta\n >(url);\n const allRecipients = recipientsResponse.message_recipients.map(\n (recipient) => this._wrapResponse(recipient)\n );\n\n for (const recipient of allRecipients) {\n const key = `${conversationSid},${recipient.messageSid}`;\n const existingMessageRecipients = this._cache.get(key)?.item ?? [];\n this._cache.set(key, { item: [...existingMessageRecipients, recipient] });\n }\n\n return new RestPaginator<RecipientDescriptor>(\n allRecipients,\n (pageToken, pageSize) =>\n this.getRecipientsFromConversation(conversationSid, {\n pageToken,\n pageSize,\n }),\n recipientsResponse.meta.previous_token,\n recipientsResponse.meta.next_token\n );\n }\n\n private _wrapResponse(recipient: MessageRecipient): RecipientDescriptor {\n switch (recipient.type) {\n case \"email\":\n return new EmailRecipientDescriptor(recipient);\n default:\n return new UnknownRecipientDescriptor(recipient);\n }\n }\n}\n\nexport {\n MessageRecipientsClient,\n EmailRecipientDescriptor,\n UnknownRecipientDescriptor,\n RecipientDescriptor,\n EmailRecipientLevel,\n};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I,aAAa,CACtB,aAAa,EACb,CAAC,SAAS,EAAE,QAAQ,KAClB,IAAI,CAAC,6BAA6B,CAAC,eAAe,EAAE;YAClD,SAAS;YACT,QAAQ;AACT,SAAA,CAAC,EACJ,kBAAkB,CAAC,IAAI,CAAC,cAAc,EACtC,kBAAkB,CAAC,IAAI,CAAC,UAAU,CACnC,CAAC;KACH;AAEO,IAAA,aAAa,CAAC,SAA2B,EAAA;QAC/C,QAAQ,SAAS,CAAC,IAAI;AACpB,YAAA,KAAK,OAAO;AACV,gBAAA,OAAO,IAAI,wBAAwB,CAAC,SAAS,CAAC,CAAC;AACjD,YAAA;AACE,gBAAA,OAAO,IAAI,0BAA0B,CAAC,SAAS,CAAC,CAAC;AACpD,SAAA;KACF;AACF;;;;"}AAS,CAAC,CAAC;AACpD,SAAA;KACF;AACF;;;;;;"}
|
package/dist/message.js
CHANGED
@@ -126,8 +126,6 @@ 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
|
-
'use strict';
|
130
|
-
|
131
129
|
var global =
|
132
130
|
typeof global !== "undefined"
|
133
131
|
? global
|
@@ -137,40 +135,34 @@ var global =
|
|
137
135
|
? window
|
138
136
|
: {};
|
139
137
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
var deprecationDecorator = require('@twilio/deprecation-decorator');
|
155
|
-
var contentTemplate = require('./content-template.js');
|
156
|
-
|
157
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
158
|
-
|
159
|
-
var isEqual__default = /*#__PURE__*/_interopDefaultLegacy(isEqual);
|
138
|
+
import { __decorate, __metadata, __classPrivateFieldGet } from './node_modules/tslib/tslib.es6.js';
|
139
|
+
import { parseAttributes, 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 isEqual from 'lodash.isequal';
|
150
|
+
import { deprecated } from '@twilio/deprecation-decorator';
|
151
|
+
import { parseVariant } from './content-template.js';
|
160
152
|
|
161
153
|
var _Message_instances, _Message_wrapMedia, _Message_assignMedias;
|
162
|
-
const log =
|
154
|
+
const log = Logger.scope("Message");
|
163
155
|
const XHR =
|
164
156
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
165
157
|
global["XMLHttpRequest"] || {};
|
166
158
|
/**
|
167
159
|
* A message in a conversation.
|
168
160
|
*/
|
169
|
-
class Message extends
|
161
|
+
class Message extends ReplayEventEmitter {
|
170
162
|
/**
|
171
163
|
* @internal
|
172
164
|
*/
|
173
|
-
constructor(index
|
165
|
+
constructor(index, data, conversation, links, configuration, services) {
|
174
166
|
var _a, _b, _c, _d, _e, _f, _g;
|
175
167
|
super();
|
176
168
|
_Message_instances.add(this);
|
@@ -180,7 +172,7 @@ class Message extends replayEventEmitter.ReplayEventEmitter {
|
|
180
172
|
this.services = services;
|
181
173
|
this.state = {
|
182
174
|
sid: data.sid,
|
183
|
-
index: index
|
175
|
+
index: index,
|
184
176
|
author: data.author,
|
185
177
|
subject: data.subject,
|
186
178
|
contentSid: data.contentSid,
|
@@ -188,17 +180,17 @@ class Message extends replayEventEmitter.ReplayEventEmitter {
|
|
188
180
|
timestamp: data.timestamp ? new Date(data.timestamp) : null,
|
189
181
|
dateUpdated: data.dateUpdated ? new Date(data.dateUpdated) : null,
|
190
182
|
lastUpdatedBy: (_b = data.lastUpdatedBy) !== null && _b !== void 0 ? _b : null,
|
191
|
-
attributes:
|
183
|
+
attributes: parseAttributes(data.attributes, `Got malformed attributes for the message ${data.sid}`, log),
|
192
184
|
type: (_c = data.type) !== null && _c !== void 0 ? _c : "text",
|
193
185
|
media: null,
|
194
186
|
medias: null,
|
195
187
|
participantSid: (_d = data.memberSid) !== null && _d !== void 0 ? _d : null,
|
196
188
|
aggregatedDeliveryReceipt: data.delivery
|
197
|
-
? new
|
189
|
+
? new AggregatedDeliveryReceipt(data.delivery)
|
198
190
|
: null,
|
199
191
|
hasChannelMetadata: (_e = data.channelMetadata) !== null && _e !== void 0 ? _e : false,
|
200
192
|
};
|
201
|
-
|
193
|
+
__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);
|
202
194
|
}
|
203
195
|
/**
|
204
196
|
* The server-assigned unique identifier for the message.
|
@@ -370,8 +362,8 @@ class Message extends replayEventEmitter.ReplayEventEmitter {
|
|
370
362
|
this.state.timestamp = new Date(data.timestamp);
|
371
363
|
updateReasons.push("dateCreated");
|
372
364
|
}
|
373
|
-
const updatedAttributes =
|
374
|
-
if (!
|
365
|
+
const updatedAttributes = parseAttributes(data.attributes, `Got malformed attributes for the message ${this.sid}`, log);
|
366
|
+
if (!isEqual(this.state.attributes, updatedAttributes)) {
|
375
367
|
this.state.attributes = updatedAttributes;
|
376
368
|
updateReasons.push("attributes");
|
377
369
|
}
|
@@ -386,7 +378,7 @@ class Message extends replayEventEmitter.ReplayEventEmitter {
|
|
386
378
|
!!updatedAggregatedDelivery.undelivered;
|
387
379
|
if (isUpdatedAggregateDeliveryValid) {
|
388
380
|
if (!currentAggregatedDelivery) {
|
389
|
-
this.state.aggregatedDeliveryReceipt = new
|
381
|
+
this.state.aggregatedDeliveryReceipt = new AggregatedDeliveryReceipt(updatedAggregatedDelivery);
|
390
382
|
updateReasons.push("deliveryReceipt");
|
391
383
|
}
|
392
384
|
else if (!currentAggregatedDelivery._isEquals(updatedAggregatedDelivery)) {
|
@@ -397,14 +389,14 @@ class Message extends replayEventEmitter.ReplayEventEmitter {
|
|
397
389
|
// @fixme: This is a fairly heavy check.
|
398
390
|
// Map data back and forth to perform a necessary field massage.
|
399
391
|
const input = ((_a = data.medias) !== null && _a !== void 0 ? _a : [])
|
400
|
-
.map((value) => { var _a; return (_a =
|
392
|
+
.map((value) => { var _a; return (_a = __classPrivateFieldGet(this, _Message_instances, "m", _Message_wrapMedia).call(this, value)) === null || _a === void 0 ? void 0 : _a._state(); })
|
401
393
|
.filter((el) => !(el === null));
|
402
394
|
const current = ((_b = this.state.medias) !== null && _b !== void 0 ? _b : [])
|
403
395
|
.map((value) => value._state())
|
404
396
|
.filter((el) => !(el === null));
|
405
|
-
if (!
|
406
|
-
!
|
407
|
-
|
397
|
+
if (!isEqual(input, current) ||
|
398
|
+
!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())) {
|
399
|
+
__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);
|
408
400
|
updateReasons.push("media");
|
409
401
|
}
|
410
402
|
if (updateReasons.length > 0) {
|
@@ -435,21 +427,21 @@ class Message extends replayEventEmitter.ReplayEventEmitter {
|
|
435
427
|
if (participant) {
|
436
428
|
return participant;
|
437
429
|
}
|
438
|
-
let
|
430
|
+
let errorMessage = "Participant with ";
|
439
431
|
if (this.state.participantSid) {
|
440
|
-
|
432
|
+
errorMessage += "SID '" + this.state.participantSid + "' ";
|
441
433
|
}
|
442
434
|
if (this.state.author) {
|
443
435
|
if (this.state.participantSid) {
|
444
|
-
|
436
|
+
errorMessage += "or ";
|
445
437
|
}
|
446
|
-
|
438
|
+
errorMessage += "identity '" + this.state.author + "' ";
|
447
439
|
}
|
448
|
-
if (
|
449
|
-
|
440
|
+
if (errorMessage === "Participant with ") {
|
441
|
+
errorMessage = "Participant ";
|
450
442
|
}
|
451
|
-
|
452
|
-
throw new Error(
|
443
|
+
errorMessage += "was not found";
|
444
|
+
throw new Error(errorMessage);
|
453
445
|
}
|
454
446
|
/**
|
455
447
|
* Get the delivery receipts of the message.
|
@@ -506,7 +498,7 @@ class Message extends replayEventEmitter.ReplayEventEmitter {
|
|
506
498
|
const sids = contentSet === null || contentSet === void 0 ? void 0 : contentSet.map((m) => m.sid);
|
507
499
|
if (this.services.mcsClient && sids) {
|
508
500
|
return (await this.services.mcsClient.mediaSetGet(sids)).map((item) => {
|
509
|
-
return new
|
501
|
+
return new Media(item, this.services);
|
510
502
|
});
|
511
503
|
}
|
512
504
|
else {
|
@@ -528,7 +520,7 @@ class Message extends replayEventEmitter.ReplayEventEmitter {
|
|
528
520
|
* @param mediaSids Set of media sids to query for the content URL.
|
529
521
|
*/
|
530
522
|
getTemporaryContentUrlsForMediaSids(mediaSids) {
|
531
|
-
return new
|
523
|
+
return new CancellablePromise(async (resolve, reject, onCancel) => {
|
532
524
|
const mediaGetRequest = this.services.mcsClient.mediaSetGetContentUrls(mediaSids !== null && mediaSids !== void 0 ? mediaSids : []);
|
533
525
|
if (!this.services.mcsClient || !mediaSids) {
|
534
526
|
reject(new Error("Media Content Service is unavailable"));
|
@@ -559,19 +551,19 @@ class Message extends replayEventEmitter.ReplayEventEmitter {
|
|
559
551
|
const messagesReceiptsUrl = this.configuration.links.messagesReceipts
|
560
552
|
.replace("%s", this.conversation.sid)
|
561
553
|
.replace("%s", this.sid);
|
562
|
-
const url = new
|
554
|
+
const url = new UriBuilder(messagesReceiptsUrl)
|
563
555
|
.arg("PageToken", options === null || options === void 0 ? void 0 : options.pageToken)
|
564
556
|
.arg("PageSize", options === null || options === void 0 ? void 0 : options.pageSize)
|
565
557
|
.build();
|
566
558
|
const response = await this.services.network.get(url);
|
567
|
-
return new
|
559
|
+
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);
|
568
560
|
}
|
569
561
|
/**
|
570
562
|
* Get the {@link ContentData} for this message. Resolves to `null` when
|
571
563
|
* {@link Message.contentSid} is null.
|
572
564
|
*/
|
573
565
|
getContentData() {
|
574
|
-
return new
|
566
|
+
return new CancellablePromise(async (resolve, reject, onCancel) => {
|
575
567
|
if (this.state.contentSid === null) {
|
576
568
|
resolve(null);
|
577
569
|
return;
|
@@ -637,7 +629,7 @@ class Message extends replayEventEmitter.ReplayEventEmitter {
|
|
637
629
|
const dataType = contentMedia.contentType
|
638
630
|
.replace(twilioPrefix, "")
|
639
631
|
.replace(".", "/");
|
640
|
-
resolve(
|
632
|
+
resolve(parseVariant(dataType, json.data));
|
641
633
|
});
|
642
634
|
}
|
643
635
|
/**
|
@@ -657,20 +649,20 @@ class Message extends replayEventEmitter.ReplayEventEmitter {
|
|
657
649
|
return await this.services.messageRecipientsClient.getRecipientsFromMessage(this.conversation.sid, this.sid);
|
658
650
|
}
|
659
651
|
}
|
660
|
-
_Message_instances = new WeakSet(), _Message_wrapMedia = function _Message_wrapMedia(media
|
661
|
-
return media
|
652
|
+
_Message_instances = new WeakSet(), _Message_wrapMedia = function _Message_wrapMedia(media, category = null) {
|
653
|
+
return media
|
662
654
|
? category
|
663
|
-
? new
|
664
|
-
: new
|
655
|
+
? new Media(Object.assign(Object.assign({}, media), { category }), this.services)
|
656
|
+
: new Media(media, this.services)
|
665
657
|
: null;
|
666
658
|
}, _Message_assignMedias = function _Message_assignMedias(medias, media) {
|
667
|
-
this.state.media =
|
659
|
+
this.state.media = __classPrivateFieldGet(this, _Message_instances, "m", _Message_wrapMedia).call(this, media);
|
668
660
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
669
661
|
// @ts-ignore
|
670
662
|
this.state.medias = medias
|
671
|
-
? medias.map((m) =>
|
663
|
+
? medias.map((m) => __classPrivateFieldGet(this, _Message_instances, "m", _Message_wrapMedia).call(this, m)).filter((el) => el !== null)
|
672
664
|
: media && !medias
|
673
|
-
? [
|
665
|
+
? [__classPrivateFieldGet(this, _Message_instances, "m", _Message_wrapMedia).call(this, media, "media")].filter((el) => el !== null)
|
674
666
|
: null;
|
675
667
|
};
|
676
668
|
/**
|
@@ -682,37 +674,58 @@ _Message_instances = new WeakSet(), _Message_wrapMedia = function _Message_wrapM
|
|
682
674
|
* * {@link MessageUpdateReason}[] updateReasons - array of reasons for the update
|
683
675
|
*/
|
684
676
|
Message.updated = "updated";
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
677
|
+
__decorate([
|
678
|
+
deprecated("getMediaByCategory", "getMediaByCategories"),
|
679
|
+
__metadata("design:type", Function),
|
680
|
+
__metadata("design:paramtypes", [Array]),
|
681
|
+
__metadata("design:returntype", Array)
|
690
682
|
], Message.prototype, "getMediaByCategory", null);
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
683
|
+
__decorate([
|
684
|
+
validateTypes([nonEmptyString, "undefined"]),
|
685
|
+
__metadata("design:type", Function),
|
686
|
+
__metadata("design:paramtypes", [Object]),
|
687
|
+
__metadata("design:returntype", Media)
|
696
688
|
], Message.prototype, "getEmailBody", null);
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
689
|
+
__decorate([
|
690
|
+
validateTypes([nonEmptyString, "undefined"]),
|
691
|
+
__metadata("design:type", Function),
|
692
|
+
__metadata("design:paramtypes", [Object]),
|
693
|
+
__metadata("design:returntype", Media)
|
702
694
|
], Message.prototype, "getEmailHistory", null);
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
695
|
+
__decorate([
|
696
|
+
validateTypesAsync("string"),
|
697
|
+
__metadata("design:type", Function),
|
698
|
+
__metadata("design:paramtypes", [String]),
|
699
|
+
__metadata("design:returntype", Promise)
|
708
700
|
], Message.prototype, "updateBody", null);
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
701
|
+
__decorate([
|
702
|
+
validateTypesAsync(json),
|
703
|
+
__metadata("design:type", Function),
|
704
|
+
__metadata("design:paramtypes", [Object]),
|
705
|
+
__metadata("design:returntype", Promise)
|
714
706
|
], Message.prototype, "updateAttributes", null);
|
715
|
-
|
707
|
+
__decorate([
|
708
|
+
deprecated("attachTemporaryUrlsFor", "getTemporaryContentUrlsForMedia"),
|
709
|
+
__metadata("design:type", Function),
|
710
|
+
__metadata("design:paramtypes", [Array]),
|
711
|
+
__metadata("design:returntype", Promise)
|
712
|
+
], Message.prototype, "attachTemporaryUrlsFor", null);
|
713
|
+
__decorate([
|
714
|
+
validateTypesAsync(nonEmptyArray("media", Media)),
|
715
|
+
__metadata("design:type", Function),
|
716
|
+
__metadata("design:paramtypes", [Array]),
|
717
|
+
__metadata("design:returntype", CancellablePromise)
|
718
|
+
], Message.prototype, "getTemporaryContentUrlsForMedia", null);
|
719
|
+
__decorate([
|
720
|
+
validateTypesAsync(nonEmptyArray("strings", "string")),
|
721
|
+
__metadata("design:type", Function),
|
722
|
+
__metadata("design:paramtypes", [Array]),
|
723
|
+
__metadata("design:returntype", CancellablePromise)
|
724
|
+
], Message.prototype, "getTemporaryContentUrlsForMediaSids", null);
|
725
|
+
|
726
|
+
export { Message };
|
727
|
+
//# sourceMappingURL=message.js.map
|
728
|
+
corate([
|
716
729
|
deprecationDecorator.deprecated("attachTemporaryUrlsFor", "getTemporaryContentUrlsForMedia"),
|
717
730
|
tslib_es6.__metadata("design:type", Function),
|
718
731
|
tslib_es6.__metadata("design:paramtypes", [Array]),
|