@twilio/conversations 2.0.1 → 2.1.0-rc.6

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.
Files changed (86) hide show
  1. package/CHANGELOG.md +74 -0
  2. package/NOTICE.txt +679 -0
  3. package/builds/browser.js +889 -619
  4. package/builds/browser.js.map +1 -1
  5. package/builds/lib.d.ts +384 -129
  6. package/builds/lib.js +889 -619
  7. package/builds/lib.js.map +1 -1
  8. package/builds/twilio-conversations.js +1065 -939
  9. package/builds/twilio-conversations.min.js +2 -14
  10. package/dist/aggregated-delivery-receipt.js +6 -1
  11. package/dist/aggregated-delivery-receipt.js.map +1 -1
  12. package/dist/client.js +165 -142
  13. package/dist/client.js.map +1 -1
  14. package/dist/command-executor.js +16 -14
  15. package/dist/command-executor.js.map +1 -1
  16. package/dist/configuration.js +14 -10
  17. package/dist/configuration.js.map +1 -1
  18. package/dist/conversation.js +232 -159
  19. package/dist/conversation.js.map +1 -1
  20. package/dist/data/conversations.js +82 -78
  21. package/dist/data/conversations.js.map +1 -1
  22. package/dist/data/messages.js +43 -39
  23. package/dist/data/messages.js.map +1 -1
  24. package/dist/data/participants.js +100 -78
  25. package/dist/data/participants.js.map +1 -1
  26. package/dist/data/users.js +24 -22
  27. package/dist/data/users.js.map +1 -1
  28. package/dist/detailed-delivery-receipt.js +1 -1
  29. package/dist/detailed-delivery-receipt.js.map +1 -1
  30. package/dist/interfaces/attributes.js +147 -0
  31. package/dist/interfaces/attributes.js.map +1 -0
  32. package/dist/interfaces/notification-types.js +5 -5
  33. package/dist/interfaces/notification-types.js.map +1 -1
  34. package/dist/logger.js +36 -15
  35. package/dist/logger.js.map +1 -1
  36. package/dist/media.js +21 -9
  37. package/dist/media.js.map +1 -1
  38. package/dist/message-builder.js +56 -3
  39. package/dist/message-builder.js.map +1 -1
  40. package/dist/message.js +157 -78
  41. package/dist/message.js.map +1 -1
  42. package/dist/packages/conversations/package.json.js +1 -1
  43. package/dist/participant.js +101 -50
  44. package/dist/participant.js.map +1 -1
  45. package/dist/push-notification.js.map +1 -1
  46. package/dist/rest-paginator.js +16 -6
  47. package/dist/rest-paginator.js.map +1 -1
  48. package/dist/services/network.js +18 -14
  49. package/dist/services/network.js.map +1 -1
  50. package/dist/services/typing-indicator.js +20 -17
  51. package/dist/services/typing-indicator.js.map +1 -1
  52. package/dist/unsent-message.js.map +1 -1
  53. package/dist/user.js +87 -60
  54. package/dist/user.js.map +1 -1
  55. package/dist/util/deferred.js +3 -1
  56. package/dist/util/deferred.js.map +1 -1
  57. package/dist/util/index.js +6 -6
  58. package/dist/util/index.js.map +1 -1
  59. package/docs/assets/js/search.js +1 -1
  60. package/docs/classes/AggregatedDeliveryReceipt.html +0 -102
  61. package/docs/classes/Client.html +24 -132
  62. package/docs/classes/Conversation.html +37 -132
  63. package/docs/classes/DetailedDeliveryReceipt.html +1 -103
  64. package/docs/classes/Media.html +0 -102
  65. package/docs/classes/Message.html +73 -109
  66. package/docs/classes/MessageBuilder.html +78 -104
  67. package/docs/classes/Participant.html +37 -110
  68. package/docs/classes/PushNotification.html +0 -102
  69. package/docs/classes/RestPaginator.html +0 -102
  70. package/docs/classes/UnsentMessage.html +0 -102
  71. package/docs/classes/User.html +7 -109
  72. package/docs/index.html +93 -3
  73. package/docs/interfaces/ClientOptions.html +0 -102
  74. package/docs/interfaces/ConversationBindings.html +3001 -0
  75. package/docs/interfaces/ConversationEmailBinding.html +3001 -0
  76. package/docs/interfaces/ConversationState.html +0 -102
  77. package/docs/interfaces/CreateConversationOptions.html +1 -103
  78. package/docs/interfaces/LastMessage.html +0 -102
  79. package/docs/interfaces/Paginator.html +0 -102
  80. package/docs/interfaces/ParticipantBindings.html +3001 -0
  81. package/docs/interfaces/ParticipantEmailBinding.html +3001 -0
  82. package/docs/interfaces/PushNotificationData.html +0 -102
  83. package/docs/interfaces/SendEmailOptions.html +0 -102
  84. package/docs/interfaces/SendMediaOptions.html +0 -102
  85. package/docs/modules.html +93 -3
  86. package/package.json +23 -17
@@ -134,7 +134,7 @@ var logger = require('../logger.js');
134
134
  var message = require('../message.js');
135
135
  var replayEventEmitter = require('@twilio/replay-event-emitter');
136
136
 
137
- const log = logger.Logger.scope('Messages');
137
+ const log = logger.Logger.scope("Messages");
138
138
  /**
139
139
  * Represents the collection of messages in a conversation
140
140
  */
@@ -157,11 +157,11 @@ class Messages extends replayEventEmitter.ReplayEventEmitter {
157
157
  }
158
158
  this.messagesListPromise = this.services.syncClient.list({
159
159
  id: name,
160
- mode: 'open_existing',
160
+ mode: "open_existing",
161
161
  });
162
162
  try {
163
163
  const list = await this.messagesListPromise;
164
- list.on('itemAdded', (args) => {
164
+ list.on("itemAdded", (args) => {
165
165
  log.debug(`${this.conversation.sid} itemAdded: ${args.item.index}`);
166
166
  const links = {
167
167
  self: `${this.conversation.links.messages}/${args.item.data.sid}`,
@@ -170,24 +170,27 @@ class Messages extends replayEventEmitter.ReplayEventEmitter {
170
170
  };
171
171
  const message$1 = new message.Message(args.item.index, args.item.data, this.conversation, links, this.configuration, this.services);
172
172
  if (this.messagesByIndex.has(message$1.index)) {
173
- log.debug('Message arrived, but is already known and ignored', this.conversation.sid, message$1.index);
173
+ log.debug("Message arrived, but is already known and ignored", this.conversation.sid, message$1.index);
174
174
  return;
175
175
  }
176
176
  this.messagesByIndex.set(message$1.index, message$1);
177
- message$1.on('updated', (args) => this.emit('messageUpdated', args));
178
- this.emit('messageAdded', message$1);
177
+ message$1.on("updated", (args) => this.emit("messageUpdated", args));
178
+ this.emit("messageAdded", message$1);
179
179
  });
180
- list.on('itemRemoved', (args) => {
180
+ list.on("itemRemoved", (args) => {
181
181
  log.debug(`#{this.conversation.sid} itemRemoved: ${args.index}`);
182
182
  const index = args.index;
183
183
  if (this.messagesByIndex.has(index)) {
184
- let message = this.messagesByIndex.get(index);
184
+ const message = this.messagesByIndex.get(index);
185
+ if (!message) {
186
+ return;
187
+ }
185
188
  this.messagesByIndex.delete(message.index);
186
- message.removeAllListeners('updated');
187
- this.emit('messageRemoved', message);
189
+ message.removeAllListeners("updated");
190
+ this.emit("messageRemoved", message);
188
191
  }
189
192
  });
190
- list.on('itemUpdated', (args) => {
193
+ list.on("itemUpdated", (args) => {
191
194
  log.debug(`${this.conversation.sid} itemUpdated: ${args.item.index}`);
192
195
  const message = this.messagesByIndex.get(args.item.index);
193
196
  if (message) {
@@ -198,10 +201,10 @@ class Messages extends replayEventEmitter.ReplayEventEmitter {
198
201
  }
199
202
  catch (err) {
200
203
  this.messagesListPromise = null;
201
- if (this.services.syncClient.connectionState !== 'disconnected') {
202
- log.error('Failed to get messages object for conversation', this.conversation.sid, err);
204
+ if (this.services.syncClient.connectionState !== "disconnected") {
205
+ log.error("Failed to get messages object for conversation", this.conversation.sid, err);
203
206
  }
204
- log.debug('ERROR: Failed to get messages object for conversation', this.conversation.sid, err);
207
+ log.debug("ERROR: Failed to get messages object for conversation", this.conversation.sid, err);
205
208
  throw err;
206
209
  }
207
210
  }
@@ -216,23 +219,23 @@ class Messages extends replayEventEmitter.ReplayEventEmitter {
216
219
  /**
217
220
  * Send Message to the conversation, message could include both text and multiple media attachments.
218
221
  * @param message Message to post
219
- * @returns Returns promise which can fail
222
+ * @returns Returns a promise which can fail
220
223
  */
221
224
  async sendV2(message) {
222
- var _a;
223
- log.debug('Sending message V2', message.mediaContent, message.attributes, message.emailOptions);
225
+ var _a, _b, _c;
226
+ log.debug("Sending message V2", message.mediaContent, message.attributes, message.emailOptions);
224
227
  const media = [];
225
228
  for (const [category, mediaContent] of message.mediaContent) {
226
- log.debug(`Adding media to a message as ${mediaContent instanceof FormData ? 'FormData' : 'SendMediaOptions'}`, mediaContent);
229
+ log.debug(`Adding media to a message as ${mediaContent instanceof FormData ? "FormData" : "SendMediaOptions"}`, mediaContent);
227
230
  media.push(mediaContent instanceof FormData
228
231
  ? await this.services.mcsClient.postFormData(mediaContent, category)
229
- : await this.services.mcsClient.post(mediaContent.contentType, mediaContent.media, category, mediaContent.filename));
232
+ : await this.services.mcsClient.post((_a = mediaContent.contentType) !== null && _a !== void 0 ? _a : "", (_b = mediaContent.media) !== null && _b !== void 0 ? _b : "", category, mediaContent.filename));
230
233
  }
231
- return await this.services.commandExecutor.mutateResource('post', this.conversation.links.messages, {
234
+ return await this.services.commandExecutor.mutateResource("post", this.conversation.links.messages, {
232
235
  body: message.text,
233
- subject: (_a = message.emailOptions) === null || _a === void 0 ? void 0 : _a.subject,
236
+ subject: (_c = message.emailOptions) === null || _c === void 0 ? void 0 : _c.subject,
234
237
  media_sids: media.map((m) => m.sid),
235
- attributes: typeof message.attributes !== 'undefined'
238
+ attributes: typeof message.attributes !== "undefined"
236
239
  ? JSON.stringify(message.attributes)
237
240
  : undefined,
238
241
  });
@@ -245,10 +248,10 @@ class Messages extends replayEventEmitter.ReplayEventEmitter {
245
248
  * @returns Returns promise which can fail
246
249
  */
247
250
  async send(message, attributes = {}, emailOptions) {
248
- log.debug('Sending text message', message, attributes, emailOptions);
249
- return await this.services.commandExecutor.mutateResource('post', this.conversation.links.messages, {
250
- body: message !== null && message !== void 0 ? message : '',
251
- attributes: typeof attributes !== 'undefined'
251
+ log.debug("Sending text message", message, attributes, emailOptions);
252
+ return await this.services.commandExecutor.mutateResource("post", this.conversation.links.messages, {
253
+ body: message !== null && message !== void 0 ? message : "",
254
+ attributes: typeof attributes !== "undefined"
252
255
  ? JSON.stringify(attributes)
253
256
  : undefined,
254
257
  subject: emailOptions === null || emailOptions === void 0 ? void 0 : emailOptions.subject,
@@ -262,15 +265,16 @@ class Messages extends replayEventEmitter.ReplayEventEmitter {
262
265
  * @returns Returns promise which can fail
263
266
  */
264
267
  async sendMedia(mediaContent, attributes = {}, emailOptions) {
265
- log.debug('Sending media message', mediaContent, attributes, emailOptions);
266
- log.debug(`Sending media message as ${mediaContent instanceof FormData ? 'FormData' : 'SendMediaOptions'}`, mediaContent, attributes);
268
+ var _a, _b;
269
+ log.debug("Sending media message", mediaContent, attributes, emailOptions);
270
+ log.debug(`Sending media message as ${mediaContent instanceof FormData ? "FormData" : "SendMediaOptions"}`, mediaContent, attributes);
267
271
  const media = mediaContent instanceof FormData
268
272
  ? await this.services.mcsClient.postFormData(mediaContent)
269
- : await this.services.mcsClient.post(mediaContent.contentType, mediaContent.media, 'media', mediaContent.filename);
273
+ : await this.services.mcsClient.post((_a = mediaContent.contentType) !== null && _a !== void 0 ? _a : "", (_b = mediaContent.media) !== null && _b !== void 0 ? _b : "", "media", mediaContent.filename);
270
274
  // emailOptions are currently ignored for media messages.
271
- return await this.services.commandExecutor.mutateResource('post', this.conversation.links.messages, {
275
+ return await this.services.commandExecutor.mutateResource("post", this.conversation.links.messages, {
272
276
  media_sids: [media.sid],
273
- attributes: typeof attributes !== 'undefined'
277
+ attributes: typeof attributes !== "undefined"
274
278
  ? JSON.stringify(attributes)
275
279
  : undefined,
276
280
  });
@@ -282,13 +286,13 @@ class Messages extends replayEventEmitter.ReplayEventEmitter {
282
286
  * @param direction Pagination order 'backwards' or 'forward', 'forward' by default
283
287
  * @returns Last page of messages by default
284
288
  */
285
- async getMessages(pageSize, anchor, direction = 'backwards') {
289
+ async getMessages(pageSize, anchor, direction = "backwards") {
286
290
  return this._getMessages(pageSize, anchor, direction);
287
291
  }
288
292
  _wrapPaginator(order, page, op) {
289
293
  // Due to an inconsistency between Sync and Chat conventions, next and
290
294
  // previous pages should be swapped.
291
- const shouldReverse = order === 'desc';
295
+ const shouldReverse = order === "desc";
292
296
  const nextPage = () => page.nextPage().then((page) => this._wrapPaginator(order, page, op));
293
297
  const previousPage = () => page.prevPage().then((page) => this._wrapPaginator(order, page, op));
294
298
  return op(page.items).then((items) => ({
@@ -313,7 +317,7 @@ class Messages extends replayEventEmitter.ReplayEventEmitter {
313
317
  };
314
318
  const message$1 = new message.Message(index, value, this.conversation, links, this.configuration, this.services);
315
319
  this.messagesByIndex.set(message$1.index, message$1);
316
- message$1.on('updated', (args) => this.emit('messageUpdated', args));
320
+ message$1.on("updated", (args) => this.emit("messageUpdated", args));
317
321
  return message$1;
318
322
  }
319
323
  /**
@@ -324,15 +328,15 @@ class Messages extends replayEventEmitter.ReplayEventEmitter {
324
328
  * @returns {Promise<SyncPaginator<Message>>} last page of messages by default
325
329
  * @private
326
330
  */
327
- async _getMessages(pageSize = 30, anchor = 'end', direction = 'forward') {
328
- const order = direction === 'backwards' ? 'desc' : 'asc';
331
+ async _getMessages(pageSize = 30, anchor = "end", direction = "forward") {
332
+ const order = direction === "backwards" ? "desc" : "asc";
329
333
  const list = await this.messagesListPromise;
330
- const page = await list.getItems({
331
- from: anchor !== 'end' ? anchor : void 0,
334
+ const page = await (list === null || list === void 0 ? void 0 : list.getItems({
335
+ from: anchor !== "end" ? anchor : void 0,
332
336
  pageSize,
333
337
  order,
334
338
  limit: pageSize, // @todo Limit equals pageSize by default in Sync. This is probably not ideal.
335
- });
339
+ }));
336
340
  return await this._wrapPaginator(order, page, (items) => Promise.all(items.map((item) => this._upsertMessage(item.index, item.data))));
337
341
  }
338
342
  }
@@ -1 +1 @@
1
- {"version":3,"file":"messages.js","sources":["../../src/data/messages.ts"],"sourcesContent":["import { EventEmitter } from 'events';\nimport { Logger } from '../logger';\n\nimport {\n Message,\n MessageUpdatedEventArgs,\n MessageUpdateReason\n} from '../message';\nimport {\n Conversation,\n SendEmailOptions,\n SendMediaOptions\n} from '../conversation';\nimport { UnsentMessage } from '../unsent-message';\n\nimport { SyncList, SyncClient } from 'twilio-sync';\nimport { SyncPaginator } from '../sync-paginator';\n\nimport { McsClient, McsMedia } from '@twilio/mcs-client';\nimport { Network } from '../services/network';\nimport { Configuration } from '../configuration';\nimport { CommandExecutor } from '../command-executor';\nimport { SendMessageRequest } from '../interfaces/commands/send-message';\nimport { MessageResponse } from '../interfaces/commands/message-response';\nimport { ReplayEventEmitter } from '@twilio/replay-event-emitter';\n\ntype MessagesEvents = {\n messageAdded: (message: Message) => void;\n messageRemoved: (message: Message) => void;\n messageUpdated: (data: {\n message: Message;\n updateReasons: MessageUpdateReason[];\n }) => void;\n};\n\nconst log = Logger.scope('Messages');\n\nexport interface MessagesServices {\n mcsClient: McsClient;\n network: Network;\n syncClient: SyncClient;\n commandExecutor: CommandExecutor;\n}\n\n/**\n * Represents the collection of messages in a conversation\n */\nclass Messages extends ReplayEventEmitter<MessagesEvents> {\n public readonly conversation: Conversation;\n private readonly configuration: Configuration;\n private readonly services: MessagesServices;\n private readonly messagesByIndex: Map<number, Message>;\n private messagesListPromise: Promise<SyncList>;\n\n public constructor(\n conversation: Conversation,\n configuration: Configuration,\n services: MessagesServices\n ) {\n super();\n\n this.conversation = conversation;\n this.configuration = configuration;\n this.services = services;\n\n this.messagesByIndex = new Map();\n this.messagesListPromise = null;\n }\n\n /**\n * Subscribe to the Messages Event Stream\n * @param name - The name of Sync object for the Messages resource.\n */\n public async subscribe(name: string) {\n if (this.messagesListPromise) {\n return this.messagesListPromise;\n }\n\n this.messagesListPromise = this.services.syncClient.list({\n id: name,\n mode: 'open_existing',\n });\n\n try {\n const list = await this.messagesListPromise;\n\n list.on('itemAdded', (args) => {\n log.debug(`${this.conversation.sid} itemAdded: ${args.item.index}`);\n\n const links = {\n self: `${this.conversation.links.messages}/${args.item.data.sid}`,\n conversation: this.conversation.links.self,\n messages_receipts: `${this.conversation.links.messages}/${args.item.data.sid}/Receipts`,\n };\n const message = new Message(\n args.item.index,\n args.item.data,\n this.conversation,\n links,\n this.configuration,\n this.services\n );\n\n if (this.messagesByIndex.has(message.index)) {\n log.debug(\n 'Message arrived, but is already known and ignored',\n this.conversation.sid,\n message.index\n );\n return;\n }\n\n this.messagesByIndex.set(message.index, message);\n\n message.on('updated', (args: MessageUpdatedEventArgs) =>\n this.emit('messageUpdated', args)\n );\n\n this.emit('messageAdded', message);\n });\n\n list.on('itemRemoved', (args) => {\n log.debug(`#{this.conversation.sid} itemRemoved: ${args.index}`);\n\n const index = args.index;\n\n if (this.messagesByIndex.has(index)) {\n let message = this.messagesByIndex.get(index);\n this.messagesByIndex.delete(message.index);\n message.removeAllListeners('updated');\n this.emit('messageRemoved', message);\n }\n });\n\n list.on('itemUpdated', (args) => {\n log.debug(`${this.conversation.sid} itemUpdated: ${args.item.index}`);\n\n const message = this.messagesByIndex.get(args.item.index);\n\n if (message) {\n message._update(args.item.data);\n }\n });\n\n return list;\n } catch (err) {\n this.messagesListPromise = null;\n\n if (this.services.syncClient.connectionState !== 'disconnected') {\n log.error(\n 'Failed to get messages object for conversation',\n this.conversation.sid,\n err\n );\n }\n\n log.debug(\n 'ERROR: Failed to get messages object for conversation',\n this.conversation.sid,\n err\n );\n\n throw err;\n }\n }\n\n public async unsubscribe() {\n if (!this.messagesListPromise) {\n return;\n }\n\n const entity = await this.messagesListPromise;\n entity.close();\n this.messagesListPromise = null;\n }\n\n /**\n * Send Message to the conversation, message could include both text and multiple media attachments.\n * @param message Message to post\n * @returns Returns promise which can fail\n */\n public async sendV2(message: UnsentMessage) {\n log.debug(\n 'Sending message V2',\n message.mediaContent,\n message.attributes,\n message.emailOptions\n );\n\n const media: McsMedia[] = [];\n\n for (const [category, mediaContent] of message.mediaContent) {\n log.debug(\n `Adding media to a message as ${\n mediaContent instanceof FormData ? 'FormData' : 'SendMediaOptions'\n }`,\n mediaContent\n );\n\n media.push(\n mediaContent instanceof FormData\n ? await this.services.mcsClient.postFormData(mediaContent, category)\n : await this.services.mcsClient.post(\n mediaContent.contentType,\n mediaContent.media,\n category,\n mediaContent.filename\n )\n );\n }\n\n return await this.services.commandExecutor.mutateResource<\n SendMessageRequest,\n MessageResponse\n >('post', this.conversation.links.messages, {\n body: message.text,\n subject: message.emailOptions?.subject,\n media_sids: media.map((m) => m.sid),\n attributes:\n typeof message.attributes !== 'undefined'\n ? JSON.stringify(message.attributes)\n : undefined,\n });\n }\n\n /**\n * Send Message to the conversation\n * @param message Message to post\n * @param attributes Message attributes\n * @param emailOptions Options that modify E-mail integration behaviors.\n * @returns Returns promise which can fail\n */\n public async send(\n message: string | null,\n attributes: any = {},\n emailOptions?: SendEmailOptions\n ): Promise<MessageResponse> {\n log.debug('Sending text message', message, attributes, emailOptions);\n\n return await this.services.commandExecutor.mutateResource<\n SendMessageRequest,\n MessageResponse\n >('post', this.conversation.links.messages, {\n body: message ?? '',\n attributes:\n typeof attributes !== 'undefined'\n ? JSON.stringify(attributes)\n : undefined,\n subject: emailOptions?.subject,\n });\n }\n\n /**\n * Send Media Message to the conversation\n * @param mediaContent Media content to post\n * @param attributes Message attributes\n * @param emailOptions Email options\n * @returns Returns promise which can fail\n */\n public async sendMedia(\n mediaContent: FormData | SendMediaOptions,\n attributes: any = {},\n emailOptions?: SendEmailOptions\n ) {\n log.debug('Sending media message', mediaContent, attributes, emailOptions);\n log.debug(\n `Sending media message as ${\n mediaContent instanceof FormData ? 'FormData' : 'SendMediaOptions'\n }`,\n mediaContent,\n attributes\n );\n\n const media: McsMedia =\n mediaContent instanceof FormData\n ? await this.services.mcsClient.postFormData(mediaContent)\n : await this.services.mcsClient.post(\n mediaContent.contentType,\n mediaContent.media,\n 'media',\n mediaContent.filename\n );\n\n // emailOptions are currently ignored for media messages.\n return await this.services.commandExecutor.mutateResource<\n SendMessageRequest,\n MessageResponse\n >('post', this.conversation.links.messages, {\n media_sids: [media.sid],\n attributes:\n typeof attributes !== 'undefined'\n ? JSON.stringify(attributes)\n : undefined,\n });\n }\n\n /**\n * Returns messages from conversation using paginator interface\n * @param pageSize Number of messages to return in single chunk. By default it's 30.\n * @param anchor Most early message id which is already known, or 'end' by default\n * @param direction Pagination order 'backwards' or 'forward', 'forward' by default\n * @returns Last page of messages by default\n */\n public async getMessages(\n pageSize: number,\n anchor: number | 'end',\n direction: 'forward' | 'backwards' = 'backwards'\n ): Promise<SyncPaginator<Message>> {\n return this._getMessages(pageSize, anchor, direction);\n }\n\n private _wrapPaginator(order, page, op) {\n // Due to an inconsistency between Sync and Chat conventions, next and\n // previous pages should be swapped.\n const shouldReverse = order === 'desc';\n\n const nextPage = () =>\n page.nextPage().then((page) => this._wrapPaginator(order, page, op));\n const previousPage = () =>\n page.prevPage().then((page) => this._wrapPaginator(order, page, op));\n\n return op(page.items).then((items) => ({\n items: items.sort((x, y) => {\n return x.index - y.index;\n }),\n hasPrevPage: shouldReverse ? page.hasNextPage : page.hasPrevPage,\n hasNextPage: shouldReverse ? page.hasPrevPage : page.hasNextPage,\n prevPage: shouldReverse ? nextPage : previousPage,\n nextPage: shouldReverse ? previousPage : nextPage,\n }));\n }\n\n private _upsertMessage(index: number, value: any) {\n const cachedMessage = this.messagesByIndex.get(index);\n\n if (cachedMessage) {\n return cachedMessage;\n }\n\n const links = {\n self: `${this.conversation.links.messages}/${value.sid}`,\n conversation: this.conversation.links.self,\n messages_receipts: `${this.conversation.links.messages}/${value.sid}/Receipts`,\n };\n const message = new Message(\n index,\n value,\n this.conversation,\n links,\n this.configuration,\n this.services\n );\n\n this.messagesByIndex.set(message.index, message);\n\n message.on('updated', (args: MessageUpdatedEventArgs) =>\n this.emit('messageUpdated', args)\n );\n\n return message;\n }\n\n /**\n * Returns last messages from conversation\n * @param {Number} [pageSize] Number of messages to return in single chunk. By default it's 30.\n * @param {String} [anchor] Most early message id which is already known, or 'end' by default\n * @param {String} [direction] Pagination order 'backwards' or 'forward', or 'forward' by default\n * @returns {Promise<SyncPaginator<Message>>} last page of messages by default\n * @private\n */\n private async _getMessages(\n pageSize = 30,\n anchor: number | 'end' = 'end',\n direction: 'forward' | 'backwards' = 'forward'\n ): Promise<SyncPaginator<Message>> {\n const order = direction === 'backwards' ? 'desc' : 'asc';\n const list = await this.messagesListPromise;\n const page = await list.getItems({\n from: anchor !== 'end' ? anchor : void 0,\n pageSize,\n order,\n limit: pageSize, // @todo Limit equals pageSize by default in Sync. This is probably not ideal.\n });\n\n return await this._wrapPaginator(order, page, (items) =>\n Promise.all(\n items.map((item) => this._upsertMessage(item.index, item.data))\n )\n );\n }\n}\n\nexport { Messages };\n"],"names":["Logger","ReplayEventEmitter","message","Message"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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C,KAAK,KAClD,OAAO,CAAC,GAAG,CACT,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAChE,CACF,CAAC;KACH;;;;;"}
1
+ {"version":3,"file":"messages.js","sources":["../../src/data/messages.ts"],"sourcesContent":["import { Logger } from \"../logger\";\n\nimport {\n Message,\n MessageData,\n MessageUpdatedEventArgs,\n MessageUpdateReason,\n} from \"../message\";\nimport {\n Conversation,\n SendEmailOptions,\n SendMediaOptions,\n} from \"../conversation\";\nimport { UnsentMessage } from \"../unsent-message\";\n\nimport { SyncList, SyncClient } from \"twilio-sync\";\nimport { SyncPaginator } from \"../sync-paginator\";\n\nimport { McsClient, McsMedia } from \"@twilio/mcs-client\";\nimport { Network } from \"../services/network\";\nimport { Configuration } from \"../configuration\";\nimport { CommandExecutor } from \"../command-executor\";\nimport { SendMessageRequest } from \"../interfaces/commands/send-message\";\nimport { MessageResponse } from \"../interfaces/commands/message-response\";\nimport { ReplayEventEmitter } from \"@twilio/replay-event-emitter\";\nimport { JSONValue } from \"../types\";\n\ntype MessagesEvents = {\n messageAdded: (message: Message) => void;\n messageRemoved: (message: Message) => void;\n messageUpdated: (data: {\n message: Message;\n updateReasons: MessageUpdateReason[];\n }) => void;\n};\n\nconst log = Logger.scope(\"Messages\");\n\nexport interface MessagesServices {\n mcsClient: McsClient;\n network: Network;\n syncClient: SyncClient;\n commandExecutor: CommandExecutor;\n}\n\n/**\n * Represents the collection of messages in a conversation\n */\nclass Messages extends ReplayEventEmitter<MessagesEvents> {\n public readonly conversation: Conversation;\n private readonly configuration: Configuration;\n private readonly services: MessagesServices;\n private readonly messagesByIndex: Map<number, Message>;\n private messagesListPromise: Promise<SyncList> | null;\n\n public constructor(\n conversation: Conversation,\n configuration: Configuration,\n services: MessagesServices\n ) {\n super();\n\n this.conversation = conversation;\n this.configuration = configuration;\n this.services = services;\n\n this.messagesByIndex = new Map();\n this.messagesListPromise = null;\n }\n\n /**\n * Subscribe to the Messages Event Stream\n * @param name - The name of Sync object for the Messages resource.\n */\n public async subscribe(name: string) {\n if (this.messagesListPromise) {\n return this.messagesListPromise;\n }\n\n this.messagesListPromise = this.services.syncClient.list({\n id: name,\n mode: \"open_existing\",\n });\n\n try {\n const list = await this.messagesListPromise;\n\n list.on(\"itemAdded\", (args) => {\n log.debug(`${this.conversation.sid} itemAdded: ${args.item.index}`);\n\n const links = {\n self: `${this.conversation.links.messages}/${args.item.data.sid}`,\n conversation: this.conversation.links.self,\n messages_receipts: `${this.conversation.links.messages}/${args.item.data.sid}/Receipts`,\n };\n const message = new Message(\n args.item.index,\n args.item.data,\n this.conversation,\n links,\n this.configuration,\n this.services\n );\n\n if (this.messagesByIndex.has(message.index)) {\n log.debug(\n \"Message arrived, but is already known and ignored\",\n this.conversation.sid,\n message.index\n );\n return;\n }\n\n this.messagesByIndex.set(message.index, message);\n\n message.on(\"updated\", (args: MessageUpdatedEventArgs) =>\n this.emit(\"messageUpdated\", args)\n );\n\n this.emit(\"messageAdded\", message);\n });\n\n list.on(\"itemRemoved\", (args) => {\n log.debug(`#{this.conversation.sid} itemRemoved: ${args.index}`);\n\n const index = args.index;\n\n if (this.messagesByIndex.has(index)) {\n const message = this.messagesByIndex.get(index);\n if (!message) {\n return;\n }\n\n this.messagesByIndex.delete(message.index);\n message.removeAllListeners(\"updated\");\n this.emit(\"messageRemoved\", message);\n }\n });\n\n list.on(\"itemUpdated\", (args) => {\n log.debug(`${this.conversation.sid} itemUpdated: ${args.item.index}`);\n\n const message = this.messagesByIndex.get(args.item.index);\n\n if (message) {\n message._update(args.item.data);\n }\n });\n\n return list;\n } catch (err) {\n this.messagesListPromise = null;\n\n if (this.services.syncClient.connectionState !== \"disconnected\") {\n log.error(\n \"Failed to get messages object for conversation\",\n this.conversation.sid,\n err\n );\n }\n\n log.debug(\n \"ERROR: Failed to get messages object for conversation\",\n this.conversation.sid,\n err\n );\n\n throw err;\n }\n }\n\n public async unsubscribe() {\n if (!this.messagesListPromise) {\n return;\n }\n\n const entity = await this.messagesListPromise;\n entity.close();\n this.messagesListPromise = null;\n }\n\n /**\n * Send Message to the conversation, message could include both text and multiple media attachments.\n * @param message Message to post\n * @returns Returns a promise which can fail\n */\n public async sendV2(message: UnsentMessage): Promise<MessageResponse> {\n log.debug(\n \"Sending message V2\",\n message.mediaContent,\n message.attributes,\n message.emailOptions\n );\n\n const media: McsMedia[] = [];\n\n for (const [category, mediaContent] of message.mediaContent) {\n log.debug(\n `Adding media to a message as ${\n mediaContent instanceof FormData ? \"FormData\" : \"SendMediaOptions\"\n }`,\n mediaContent\n );\n\n media.push(\n mediaContent instanceof FormData\n ? await this.services.mcsClient.postFormData(mediaContent, category)\n : await this.services.mcsClient.post(\n mediaContent.contentType ?? \"\",\n mediaContent.media ?? \"\",\n category,\n mediaContent.filename\n )\n );\n }\n\n return await this.services.commandExecutor.mutateResource<\n SendMessageRequest,\n MessageResponse\n >(\"post\", this.conversation.links.messages, {\n body: message.text,\n subject: message.emailOptions?.subject,\n media_sids: media.map((m) => m.sid),\n attributes:\n typeof message.attributes !== \"undefined\"\n ? JSON.stringify(message.attributes)\n : undefined,\n });\n }\n\n /**\n * Send Message to the conversation\n * @param message Message to post\n * @param attributes Message attributes\n * @param emailOptions Options that modify E-mail integration behaviors.\n * @returns Returns promise which can fail\n */\n public async send(\n message: null | string | FormData | SendMediaOptions,\n attributes: JSONValue = {},\n emailOptions?: SendEmailOptions\n ): Promise<MessageResponse> {\n log.debug(\"Sending text message\", message, attributes, emailOptions);\n\n return await this.services.commandExecutor.mutateResource<\n SendMessageRequest,\n MessageResponse\n >(\"post\", this.conversation.links.messages, {\n body: message ?? \"\",\n attributes:\n typeof attributes !== \"undefined\"\n ? JSON.stringify(attributes)\n : undefined,\n subject: emailOptions?.subject,\n });\n }\n\n /**\n * Send Media Message to the conversation\n * @param mediaContent Media content to post\n * @param attributes Message attributes\n * @param emailOptions Email options\n * @returns Returns promise which can fail\n */\n public async sendMedia(\n mediaContent: FormData | SendMediaOptions,\n attributes: JSONValue = {},\n emailOptions?: SendEmailOptions\n ) {\n log.debug(\"Sending media message\", mediaContent, attributes, emailOptions);\n log.debug(\n `Sending media message as ${\n mediaContent instanceof FormData ? \"FormData\" : \"SendMediaOptions\"\n }`,\n mediaContent,\n attributes\n );\n\n const media: McsMedia =\n mediaContent instanceof FormData\n ? await this.services.mcsClient.postFormData(mediaContent)\n : await this.services.mcsClient.post(\n mediaContent.contentType ?? \"\",\n mediaContent.media ?? \"\",\n \"media\",\n mediaContent.filename\n );\n\n // emailOptions are currently ignored for media messages.\n return await this.services.commandExecutor.mutateResource<\n SendMessageRequest,\n MessageResponse\n >(\"post\", this.conversation.links.messages, {\n media_sids: [media.sid],\n attributes:\n typeof attributes !== \"undefined\"\n ? JSON.stringify(attributes)\n : undefined,\n });\n }\n\n /**\n * Returns messages from conversation using paginator interface\n * @param pageSize Number of messages to return in single chunk. By default it's 30.\n * @param anchor Most early message id which is already known, or 'end' by default\n * @param direction Pagination order 'backwards' or 'forward', 'forward' by default\n * @returns Last page of messages by default\n */\n public async getMessages(\n pageSize: number | undefined,\n anchor: number | \"end\" | undefined,\n direction: \"forward\" | \"backwards\" = \"backwards\"\n ): Promise<SyncPaginator<Message>> {\n return this._getMessages(pageSize, anchor, direction);\n }\n\n private _wrapPaginator(order, page, op) {\n // Due to an inconsistency between Sync and Chat conventions, next and\n // previous pages should be swapped.\n const shouldReverse = order === \"desc\";\n\n const nextPage = () =>\n page.nextPage().then((page) => this._wrapPaginator(order, page, op));\n const previousPage = () =>\n page.prevPage().then((page) => this._wrapPaginator(order, page, op));\n\n return op(page.items).then((items) => ({\n items: items.sort((x, y) => {\n return x.index - y.index;\n }),\n hasPrevPage: shouldReverse ? page.hasNextPage : page.hasPrevPage,\n hasNextPage: shouldReverse ? page.hasPrevPage : page.hasNextPage,\n prevPage: shouldReverse ? nextPage : previousPage,\n nextPage: shouldReverse ? previousPage : nextPage,\n }));\n }\n\n private _upsertMessage(index: number, value: MessageData) {\n const cachedMessage = this.messagesByIndex.get(index);\n\n if (cachedMessage) {\n return cachedMessage;\n }\n\n const links = {\n self: `${this.conversation.links.messages}/${value.sid}`,\n conversation: this.conversation.links.self,\n messages_receipts: `${this.conversation.links.messages}/${value.sid}/Receipts`,\n };\n const message = new Message(\n index,\n value,\n this.conversation,\n links,\n this.configuration,\n this.services\n );\n\n this.messagesByIndex.set(message.index, message);\n\n message.on(\"updated\", (args: MessageUpdatedEventArgs) =>\n this.emit(\"messageUpdated\", args)\n );\n\n return message;\n }\n\n /**\n * Returns last messages from conversation\n * @param {Number} [pageSize] Number of messages to return in single chunk. By default it's 30.\n * @param {String} [anchor] Most early message id which is already known, or 'end' by default\n * @param {String} [direction] Pagination order 'backwards' or 'forward', or 'forward' by default\n * @returns {Promise<SyncPaginator<Message>>} last page of messages by default\n * @private\n */\n private async _getMessages(\n pageSize = 30,\n anchor: number | \"end\" = \"end\",\n direction: \"forward\" | \"backwards\" = \"forward\"\n ): Promise<SyncPaginator<Message>> {\n const order = direction === \"backwards\" ? \"desc\" : \"asc\";\n const list = await this.messagesListPromise;\n const page = await list?.getItems({\n from: anchor !== \"end\" ? anchor : void 0,\n pageSize,\n order,\n limit: pageSize, // @todo Limit equals pageSize by default in Sync. This is probably not ideal.\n });\n\n return await this._wrapPaginator(order, page, (items) =>\n Promise.all(\n items.map((item) => this._upsertMessage(item.index, item.data))\n )\n );\n }\n}\n\nexport { Messages };\n"],"names":["Logger","ReplayEventEmitter","message","Message"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAM,GAAG,GAAGA,aAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;AASrC;;;AAGA,MA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GAAG,CACT,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAChE,CACF,CAAC;KACH;;;;;"}
@@ -134,7 +134,7 @@ var participant = require('../participant.js');
134
134
  var logger = require('../logger.js');
135
135
  var replayEventEmitter = require('@twilio/replay-event-emitter');
136
136
 
137
- const log = logger.Logger.scope('Participants');
137
+ const log = logger.Logger.scope("Participants");
138
138
  /**
139
139
  * @classdesc Represents the collection of participants for the conversation
140
140
  * @fires Participants#participantJoined
@@ -144,6 +144,7 @@ const log = logger.Logger.scope('Participants');
144
144
  class Participants extends replayEventEmitter.ReplayEventEmitter {
145
145
  constructor(conversation, participants, links, configuration, services) {
146
146
  super();
147
+ this.rosterEntityPromise = null;
147
148
  this.conversation = conversation;
148
149
  this.participants = participants;
149
150
  this.links = links;
@@ -152,56 +153,63 @@ class Participants extends replayEventEmitter.ReplayEventEmitter {
152
153
  }
153
154
  async unsubscribe() {
154
155
  if (this.rosterEntityPromise) {
155
- let entity = await this.rosterEntityPromise;
156
+ const entity = await this.rosterEntityPromise;
156
157
  entity.close();
157
158
  this.rosterEntityPromise = null;
158
159
  }
159
160
  }
160
161
  subscribe(rosterObjectName) {
161
- return this.rosterEntityPromise = this.rosterEntityPromise
162
- || this.services.syncClient.map({ id: rosterObjectName, mode: 'open_existing' })
163
- .then(rosterMap => {
164
- rosterMap.on('itemAdded', args => {
165
- log.debug(this.conversation.sid + ' itemAdded: ' + args.item.key);
166
- this.upsertParticipant(args.item.key, args.item.data)
167
- .then(participant => {
168
- this.emit('participantJoined', participant);
162
+ return (this.rosterEntityPromise =
163
+ this.rosterEntityPromise ||
164
+ this.services.syncClient
165
+ .map({ id: rosterObjectName, mode: "open_existing" })
166
+ .then((rosterMap) => {
167
+ rosterMap.on("itemAdded", (args) => {
168
+ log.debug(this.conversation.sid + " itemAdded: " + args.item.key);
169
+ this.upsertParticipant(args.item.key, args.item.data).then((participant) => {
170
+ this.emit("participantJoined", participant);
171
+ });
169
172
  });
170
- });
171
- rosterMap.on('itemRemoved', args => {
172
- log.debug(this.conversation.sid + ' itemRemoved: ' + args.key);
173
- let participantSid = args.key;
174
- if (!this.participants.has(participantSid)) {
175
- return;
173
+ rosterMap.on("itemRemoved", (args) => {
174
+ log.debug(this.conversation.sid + " itemRemoved: " + args.key);
175
+ const participantSid = args.key;
176
+ if (!this.participants.has(participantSid)) {
177
+ return;
178
+ }
179
+ const leftParticipant = this.participants.get(participantSid);
180
+ this.participants.delete(participantSid);
181
+ if (!leftParticipant) {
182
+ return;
183
+ }
184
+ this.emit("participantLeft", leftParticipant);
185
+ });
186
+ rosterMap.on("itemUpdated", (args) => {
187
+ log.debug(this.conversation.sid + " itemUpdated: " + args.item.key);
188
+ this.upsertParticipant(args.item.key, args.item.data);
189
+ });
190
+ const participantsPromises = [];
191
+ const rosterMapHandler = (paginator) => {
192
+ paginator.items.forEach((item) => {
193
+ participantsPromises.push(this.upsertParticipant(item.key, item.data));
194
+ });
195
+ return paginator.hasNextPage
196
+ ? paginator.nextPage().then(rosterMapHandler)
197
+ : null;
198
+ };
199
+ return rosterMap
200
+ .getItems()
201
+ .then(rosterMapHandler)
202
+ .then(() => Promise.all(participantsPromises))
203
+ .then(() => rosterMap);
204
+ })
205
+ .catch((err) => {
206
+ this.rosterEntityPromise = null;
207
+ if (this.services.syncClient.connectionState != "disconnected") {
208
+ log.error("Failed to get roster object for conversation", this.conversation.sid, err);
176
209
  }
177
- let leftParticipant = this.participants.get(participantSid);
178
- this.participants.delete(participantSid);
179
- this.emit('participantLeft', leftParticipant);
180
- });
181
- rosterMap.on('itemUpdated', args => {
182
- log.debug(this.conversation.sid + ' itemUpdated: ' + args.item.key);
183
- this.upsertParticipant(args.item.key, args.item.data);
184
- });
185
- let participantsPromises = [];
186
- let that = this;
187
- const rosterMapHandler = function (paginator) {
188
- paginator.items.forEach(item => { participantsPromises.push(that.upsertParticipant(item.key, item.data)); });
189
- return paginator.hasNextPage ? paginator.nextPage().then(rosterMapHandler) : null;
190
- };
191
- return rosterMap
192
- .getItems()
193
- .then(rosterMapHandler)
194
- .then(() => Promise.all(participantsPromises))
195
- .then(() => rosterMap);
196
- })
197
- .catch(err => {
198
- this.rosterEntityPromise = null;
199
- if (this.services.syncClient.connectionState != 'disconnected') {
200
- log.error('Failed to get roster object for conversation', this.conversation.sid, err);
201
- }
202
- log.debug('ERROR: Failed to get roster object for conversation', this.conversation.sid, err);
203
- throw err;
204
- });
210
+ log.debug("ERROR: Failed to get roster object for conversation", this.conversation.sid, err);
211
+ throw err;
212
+ }));
205
213
  }
206
214
  async upsertParticipant(participantSid, data) {
207
215
  let participant$1 = this.participants.get(participantSid);
@@ -209,35 +217,39 @@ class Participants extends replayEventEmitter.ReplayEventEmitter {
209
217
  return participant$1._update(data);
210
218
  }
211
219
  const links = {
212
- self: `${this.links.participants}/${participantSid}`
220
+ self: `${this.links.participants}/${participantSid}`,
213
221
  };
214
222
  participant$1 = new participant.Participant(data, participantSid, this.conversation, links, this.services);
215
223
  this.participants.set(participantSid, participant$1);
216
- participant$1.on('updated', (args) => this.emit('participantUpdated', args));
224
+ participant$1.on("updated", (args) => this.emit("participantUpdated", args));
217
225
  return participant$1;
218
226
  }
219
227
  /**
220
228
  * @returns {Promise<Array<Participant>>} returns list of participants {@see Participant}
221
229
  */
222
- getParticipants() {
223
- return this.rosterEntityPromise.then(() => {
224
- let participants = [];
225
- this.participants.forEach(participant => participants.push(participant));
226
- return participants;
227
- });
230
+ async getParticipants() {
231
+ return this.rosterEntityPromise
232
+ ? this.rosterEntityPromise.then(() => {
233
+ const participants = [];
234
+ this.participants.forEach((participant) => participants.push(participant));
235
+ return participants;
236
+ })
237
+ : [];
228
238
  }
229
239
  /**
230
240
  * Get participant by SID from conversation
231
241
  * @returns {Promise<Participant>}
232
242
  */
233
243
  async getParticipantBySid(participantSid) {
234
- return this.rosterEntityPromise.then(() => {
235
- let participant = this.participants.get(participantSid);
236
- if (!participant) {
237
- throw new Error('Participant with SID ' + participantSid + ' was not found');
238
- }
239
- return participant;
240
- });
244
+ return this.rosterEntityPromise
245
+ ? this.rosterEntityPromise.then(() => {
246
+ const participant = this.participants.get(participantSid);
247
+ if (!participant) {
248
+ throw new Error("Participant with SID " + participantSid + " was not found");
249
+ }
250
+ return participant;
251
+ })
252
+ : null;
241
253
  }
242
254
  /**
243
255
  * Get participant by identity from conversation
@@ -245,26 +257,30 @@ class Participants extends replayEventEmitter.ReplayEventEmitter {
245
257
  */
246
258
  async getParticipantByIdentity(identity) {
247
259
  let foundParticipant = null;
248
- return this.rosterEntityPromise.then(() => {
249
- this.participants.forEach(participant => {
250
- if (participant.identity === identity) {
251
- foundParticipant = participant;
260
+ return this.rosterEntityPromise
261
+ ? this.rosterEntityPromise.then(() => {
262
+ this.participants.forEach((participant) => {
263
+ if (participant.identity === identity) {
264
+ foundParticipant = participant;
265
+ }
266
+ });
267
+ if (!foundParticipant) {
268
+ throw new Error("Participant with identity " + identity + " was not found");
252
269
  }
253
- });
254
- if (!foundParticipant) {
255
- throw new Error('Participant with identity ' + identity + ' was not found');
256
- }
257
- return foundParticipant;
258
- });
270
+ return foundParticipant;
271
+ })
272
+ : null;
259
273
  }
260
274
  /**
261
275
  * Add a chat participant to the conversation
262
- * @returns {Promise<any>}
276
+ * @returns {Promise<ParticipantResponse>}
263
277
  */
264
278
  async add(identity, attributes) {
265
- return await this.services.commandExecutor.mutateResource('post', this.links.participants, {
279
+ return await this.services.commandExecutor.mutateResource("post", this.links.participants, {
266
280
  identity,
267
- attributes: typeof attributes !== 'undefined' ? JSON.stringify(attributes) : undefined
281
+ attributes: typeof attributes !== "undefined"
282
+ ? JSON.stringify(attributes)
283
+ : undefined,
268
284
  });
269
285
  }
270
286
  /**
@@ -273,22 +289,28 @@ class Participants extends replayEventEmitter.ReplayEventEmitter {
273
289
  * @param proxyAddress
274
290
  * @param address
275
291
  * @param attributes
292
+ * @param bindingOptions
276
293
  * @returns {Promise<any>}
277
294
  */
278
- addNonChatParticipant(proxyAddress, address, attributes) {
279
- return this.services.commandExecutor.mutateResource('post', this.links.participants, {
280
- attributes: typeof attributes !== 'undefined' ? JSON.stringify(attributes) : undefined,
295
+ addNonChatParticipant(proxyAddress, address, attributes = {}, bindingOptions = {}) {
296
+ var _a, _b;
297
+ return this.services.commandExecutor.mutateResource("post", this.links.participants, {
298
+ attributes: typeof attributes !== "undefined"
299
+ ? JSON.stringify(attributes)
300
+ : undefined,
281
301
  messaging_binding: {
282
302
  address,
283
- proxy_address: proxyAddress
284
- }
303
+ proxy_address: proxyAddress,
304
+ name: (_a = bindingOptions === null || bindingOptions === void 0 ? void 0 : bindingOptions.email) === null || _a === void 0 ? void 0 : _a.name,
305
+ level: (_b = bindingOptions === null || bindingOptions === void 0 ? void 0 : bindingOptions.email) === null || _b === void 0 ? void 0 : _b.level,
306
+ },
285
307
  });
286
308
  }
287
309
  /**
288
310
  * Remove the participant with a given identity from a conversation.
289
311
  */
290
312
  remove(identity) {
291
- return this.services.commandExecutor.mutateResource('delete', `${this.links.participants}/${identity}`);
313
+ return this.services.commandExecutor.mutateResource("delete", `${this.links.participants}/${identity}`);
292
314
  }
293
315
  }
294
316
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"participants.js","sources":["../../src/data/participants.ts"],"sourcesContent":["import { EventEmitter } from 'events';\nimport {\n ParticipantDescriptor,\n Participant,\n ParticipantUpdatedEventArgs,\n ParticipantUpdateReason\n} from '../participant';\nimport { Logger } from '../logger';\n\nimport { Conversation } from '../conversation';\n\nimport { SyncMap, SyncClient } from 'twilio-sync';\nimport { Users } from './users';\nimport { CommandExecutor } from '../command-executor';\nimport {\n AddParticipantRequest\n} from '../interfaces/commands/add-participant';\nimport { Configuration } from '../configuration';\nimport { ParticipantResponse } from '../interfaces/commands/participant-response';\nimport { ReplayEventEmitter } from '@twilio/replay-event-emitter';\n\ntype ParticipantsEvents = {\n participantJoined: (participant: Participant) => void;\n participantLeft: (participant: Participant) => void;\n participantUpdated: (data: {\n participant: Participant;\n updateReasons: ParticipantUpdateReason[];\n }) => void;\n};\n\nconst log = Logger.scope('Participants');\n\nexport interface ParticipantsServices {\n syncClient: SyncClient;\n users: Users;\n commandExecutor: CommandExecutor;\n}\n\ninterface ParticipantsLinks {\n participants: string;\n}\n\n/**\n * @classdesc Represents the collection of participants for the conversation\n * @fires Participants#participantJoined\n * @fires Participants#participantLeft\n * @fires Participants#participantUpdated\n */\nclass Participants extends ReplayEventEmitter<ParticipantsEvents> {\n\n private readonly configuration: Configuration;\n private readonly services: ParticipantsServices;\n private readonly links: ParticipantsLinks;\n\n rosterEntityPromise: Promise<SyncMap>;\n\n public readonly conversation: Conversation;\n public readonly participants: Map<string, Participant>;\n\n constructor(\n conversation: Conversation,\n participants: Map<string, Participant>,\n links: ParticipantsLinks,\n configuration: Configuration,\n services: ParticipantsServices,\n ) {\n super();\n this.conversation = conversation;\n this.participants = participants;\n this.links = links;\n this.configuration = configuration;\n this.services = services;\n }\n\n async unsubscribe(): Promise<void> {\n if (this.rosterEntityPromise) {\n let entity = await this.rosterEntityPromise;\n entity.close();\n this.rosterEntityPromise = null;\n }\n }\n\n subscribe(rosterObjectName: string) {\n return this.rosterEntityPromise = this.rosterEntityPromise\n || this.services.syncClient.map({ id: rosterObjectName, mode: 'open_existing' })\n .then(rosterMap => {\n rosterMap.on('itemAdded', args => {\n log.debug(this.conversation.sid + ' itemAdded: ' + args.item.key);\n this.upsertParticipant(args.item.key, args.item.data)\n .then(participant => {\n this.emit('participantJoined', participant);\n });\n });\n\n rosterMap.on('itemRemoved', args => {\n log.debug(this.conversation.sid + ' itemRemoved: ' + args.key);\n let participantSid = args.key;\n if (!this.participants.has(participantSid)) {\n return;\n }\n let leftParticipant = this.participants.get(participantSid);\n this.participants.delete(participantSid);\n this.emit('participantLeft', leftParticipant);\n });\n\n rosterMap.on('itemUpdated', args => {\n log.debug(this.conversation.sid + ' itemUpdated: ' + args.item.key);\n this.upsertParticipant(args.item.key, args.item.data);\n });\n\n let participantsPromises = [];\n let that = this;\n const rosterMapHandler = function(paginator) {\n paginator.items.forEach(item => { participantsPromises.push(that.upsertParticipant(item.key, item.data)); });\n return paginator.hasNextPage ? paginator.nextPage().then(rosterMapHandler) : null;\n };\n\n return rosterMap\n .getItems()\n .then(rosterMapHandler)\n .then(() => Promise.all(participantsPromises))\n .then(() => rosterMap);\n })\n .catch(err => {\n this.rosterEntityPromise = null;\n if (this.services.syncClient.connectionState != 'disconnected') {\n log.error('Failed to get roster object for conversation', this.conversation.sid, err);\n }\n log.debug('ERROR: Failed to get roster object for conversation', this.conversation.sid, err);\n throw err;\n });\n }\n\n async upsertParticipant(participantSid: string, data: ParticipantDescriptor): Promise<Participant> {\n let participant = this.participants.get(participantSid);\n if (participant) {\n return participant._update(data);\n }\n\n const links = {\n self: `${this.links.participants}/${participantSid}`\n };\n\n participant = new Participant(data, participantSid, this.conversation, links, this.services);\n this.participants.set(participantSid, participant);\n participant.on('updated', (args: ParticipantUpdatedEventArgs) => this.emit('participantUpdated', args));\n return participant;\n }\n\n /**\n * @returns {Promise<Array<Participant>>} returns list of participants {@see Participant}\n */\n getParticipants(): Promise<Array<Participant>> {\n return this.rosterEntityPromise.then(() => {\n let participants = [];\n this.participants.forEach(participant => participants.push(participant));\n return participants;\n });\n }\n\n /**\n * Get participant by SID from conversation\n * @returns {Promise<Participant>}\n */\n async getParticipantBySid(participantSid: string): Promise<Participant> {\n return this.rosterEntityPromise.then(() => {\n let participant = this.participants.get(participantSid);\n if (!participant) {\n throw new Error('Participant with SID ' + participantSid + ' was not found');\n }\n return participant;\n });\n }\n\n /**\n * Get participant by identity from conversation\n * @returns {Promise<Participant>}\n */\n async getParticipantByIdentity(identity: string): Promise<Participant> {\n let foundParticipant = null;\n return this.rosterEntityPromise.then(() => {\n this.participants.forEach(participant => {\n if (participant.identity === identity) {\n foundParticipant = participant;\n }\n });\n if (!foundParticipant) {\n throw new Error('Participant with identity ' + identity + ' was not found');\n }\n return foundParticipant;\n });\n }\n\n /**\n * Add a chat participant to the conversation\n * @returns {Promise<any>}\n */\n async add(identity: string, attributes: any): Promise<any> {\n return await this.services.commandExecutor.mutateResource<AddParticipantRequest, ParticipantResponse>(\n 'post',\n this.links.participants,\n {\n identity,\n attributes: typeof attributes !== 'undefined' ? JSON.stringify(attributes) : undefined\n }\n );\n }\n\n /**\n * Add a non-chat participant to the conversation.\n *\n * @param proxyAddress\n * @param address\n * @param attributes\n * @returns {Promise<any>}\n */\n addNonChatParticipant(proxyAddress: string, address: string, attributes: any): Promise<any> {\n return this.services.commandExecutor.mutateResource<AddParticipantRequest, ParticipantResponse>(\n 'post',\n this.links.participants,\n {\n attributes: typeof attributes !== 'undefined' ? JSON.stringify(attributes) : undefined,\n messaging_binding: {\n address,\n proxy_address: proxyAddress\n }\n }\n );\n }\n\n /**\n * Remove the participant with a given identity from a conversation.\n */\n remove(identity: string): Promise<any> {\n return this.services.commandExecutor.mutateResource(\n 'delete',\n `${this.links.participants}/${identity}`,\n );\n }\n}\n\nexport { Participants };\n\n/**\n * Fired when participant joined conversation\n * @event Participants#participantJoined\n * @type {Participant}\n */\n\n/**\n * Fired when participant left conversation\n * @event Participants#participantLeft\n * @type {Participant}\n */\n\n/**\n * Fired when participant updated\n * @event Participants#participantUpdated\n * @type {Object}\n * @property {Participant} participant - Updated Participant\n * @property {Participant#UpdateReason[]} updateReasons - Array of Participant's updated event reasons\n */\n"],"names":["Logger","ReplayEventEmitter","participant","Participant"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,MAAM,GAAG,GAAGA,aAAM,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;AAYzC;;;;;;AAMA,MAAM,YAAa,SAAQC,qCAAsC;IAW/D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AAU,KAAK,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,GAAG,SAAS;SACvF,CACF,CAAC;KACH;;;;;;;;;IAUD,qBAAqB,CAAC,YAAoB,EAAE,OAAe,EAAE,UAAe;QAC1E,OAAO,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,cAAc,CACjD,MAAM,EACN,IAAI,CAAC,KAAK,CAAC,YAAY,EACvB;YACE,UAAU,EAAE,OAAO,UAAU,KAAK,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,GAAG,SAAS;YACtF,iBAAiB,EAAE;gBACjB,OAAO;gBACP,aAAa,EAAE,YAAY;aAC5B;SACF,CACF,CAAC;KACH;;;;IAKD,MAAM,CAAC,QAAgB;QACrB,OAAO,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,cAAc,CACjD,QAAQ,EACR,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,IAAI,QAAQ,EAAE,CACzC,CAAC;KACH;CACF;AAID;;;;;AAMA;;;;;AAMA;;;;;;;;;;"}
1
+ {"version":3,"file":"participants.js","sources":["../../src/data/participants.ts"],"sourcesContent":["import {\n ParticipantDescriptor,\n Participant,\n ParticipantUpdatedEventArgs,\n ParticipantUpdateReason,\n ParticipantEmailBinding,\n} from \"../participant\";\nimport { Logger } from \"../logger\";\n\nimport { Conversation } from \"../conversation\";\n\nimport { SyncMap, SyncClient } from \"twilio-sync\";\nimport { Users } from \"./users\";\nimport { CommandExecutor } from \"../command-executor\";\nimport { AddParticipantRequest } from \"../interfaces/commands/add-participant\";\nimport { Configuration } from \"../configuration\";\nimport { ParticipantResponse } from \"../interfaces/commands/participant-response\";\nimport { ReplayEventEmitter } from \"@twilio/replay-event-emitter\";\nimport { JSONValue } from \"../types\";\n\ntype ParticipantsEvents = {\n participantJoined: (participant: Participant) => void;\n participantLeft: (participant: Participant) => void;\n participantUpdated: (data: {\n participant: Participant;\n updateReasons: ParticipantUpdateReason[];\n }) => void;\n};\n\nconst log = Logger.scope(\"Participants\");\n\nexport interface ParticipantsServices {\n syncClient: SyncClient;\n users: Users;\n commandExecutor: CommandExecutor;\n}\n\ninterface ParticipantsLinks {\n participants: string;\n}\n\nexport interface ParticipantBindingOptions {\n email?: ParticipantEmailBinding;\n}\n\n/**\n * @classdesc Represents the collection of participants for the conversation\n * @fires Participants#participantJoined\n * @fires Participants#participantLeft\n * @fires Participants#participantUpdated\n */\nclass Participants extends ReplayEventEmitter<ParticipantsEvents> {\n private readonly configuration: Configuration;\n private readonly services: ParticipantsServices;\n private readonly links: ParticipantsLinks;\n\n rosterEntityPromise: Promise<SyncMap> | null = null;\n\n public readonly conversation: Conversation;\n public readonly participants: Map<string, Participant>;\n\n constructor(\n conversation: Conversation,\n participants: Map<string, Participant>,\n links: ParticipantsLinks,\n configuration: Configuration,\n services: ParticipantsServices\n ) {\n super();\n this.conversation = conversation;\n this.participants = participants;\n this.links = links;\n this.configuration = configuration;\n this.services = services;\n }\n\n async unsubscribe(): Promise<void> {\n if (this.rosterEntityPromise) {\n const entity = await this.rosterEntityPromise;\n entity.close();\n this.rosterEntityPromise = null;\n }\n }\n\n subscribe(rosterObjectName: string) {\n return (this.rosterEntityPromise =\n this.rosterEntityPromise ||\n this.services.syncClient\n .map({ id: rosterObjectName, mode: \"open_existing\" })\n .then((rosterMap) => {\n rosterMap.on(\"itemAdded\", (args) => {\n log.debug(this.conversation.sid + \" itemAdded: \" + args.item.key);\n this.upsertParticipant(args.item.key, args.item.data).then(\n (participant) => {\n this.emit(\"participantJoined\", participant);\n }\n );\n });\n\n rosterMap.on(\"itemRemoved\", (args) => {\n log.debug(this.conversation.sid + \" itemRemoved: \" + args.key);\n const participantSid = args.key;\n if (!this.participants.has(participantSid)) {\n return;\n }\n const leftParticipant = this.participants.get(participantSid);\n this.participants.delete(participantSid);\n if (!leftParticipant) {\n return;\n }\n this.emit(\"participantLeft\", leftParticipant);\n });\n\n rosterMap.on(\"itemUpdated\", (args) => {\n log.debug(this.conversation.sid + \" itemUpdated: \" + args.item.key);\n this.upsertParticipant(args.item.key, args.item.data);\n });\n\n const participantsPromises: Promise<Participant>[] = [];\n const rosterMapHandler = (paginator) => {\n paginator.items.forEach((item) => {\n participantsPromises.push(\n this.upsertParticipant(item.key, item.data)\n );\n });\n return paginator.hasNextPage\n ? paginator.nextPage().then(rosterMapHandler)\n : null;\n };\n\n return rosterMap\n .getItems()\n .then(rosterMapHandler)\n .then(() => Promise.all(participantsPromises))\n .then(() => rosterMap);\n })\n .catch((err) => {\n this.rosterEntityPromise = null;\n if (this.services.syncClient.connectionState != \"disconnected\") {\n log.error(\n \"Failed to get roster object for conversation\",\n this.conversation.sid,\n err\n );\n }\n log.debug(\n \"ERROR: Failed to get roster object for conversation\",\n this.conversation.sid,\n err\n );\n throw err;\n }));\n }\n\n async upsertParticipant(\n participantSid: string,\n data: ParticipantDescriptor\n ): Promise<Participant> {\n let participant = this.participants.get(participantSid);\n if (participant) {\n return participant._update(data);\n }\n\n const links = {\n self: `${this.links.participants}/${participantSid}`,\n };\n\n participant = new Participant(\n data,\n participantSid,\n this.conversation,\n links,\n this.services\n );\n this.participants.set(participantSid, participant);\n participant.on(\"updated\", (args: ParticipantUpdatedEventArgs) =>\n this.emit(\"participantUpdated\", args)\n );\n return participant;\n }\n\n /**\n * @returns {Promise<Array<Participant>>} returns list of participants {@see Participant}\n */\n async getParticipants(): Promise<Participant[]> {\n return this.rosterEntityPromise\n ? this.rosterEntityPromise.then(() => {\n const participants: Participant[] = [];\n this.participants.forEach((participant) =>\n participants.push(participant)\n );\n return participants;\n })\n : [];\n }\n\n /**\n * Get participant by SID from conversation\n * @returns {Promise<Participant>}\n */\n async getParticipantBySid(\n participantSid: string\n ): Promise<Participant | null> {\n return this.rosterEntityPromise\n ? this.rosterEntityPromise.then(() => {\n const participant = this.participants.get(participantSid);\n if (!participant) {\n throw new Error(\n \"Participant with SID \" + participantSid + \" was not found\"\n );\n }\n return participant;\n })\n : null;\n }\n\n /**\n * Get participant by identity from conversation\n * @returns {Promise<Participant>}\n */\n async getParticipantByIdentity(\n identity: string\n ): Promise<Participant | null> {\n let foundParticipant: Participant | null = null;\n return this.rosterEntityPromise\n ? this.rosterEntityPromise.then(() => {\n this.participants.forEach((participant) => {\n if (participant.identity === identity) {\n foundParticipant = participant;\n }\n });\n if (!foundParticipant) {\n throw new Error(\n \"Participant with identity \" + identity + \" was not found\"\n );\n }\n return foundParticipant;\n })\n : null;\n }\n\n /**\n * Add a chat participant to the conversation\n * @returns {Promise<ParticipantResponse>}\n */\n async add(\n identity: string,\n attributes: JSONValue\n ): Promise<ParticipantResponse> {\n return await this.services.commandExecutor.mutateResource<\n AddParticipantRequest,\n ParticipantResponse\n >(\"post\", this.links.participants, {\n identity,\n attributes:\n typeof attributes !== \"undefined\"\n ? JSON.stringify(attributes)\n : undefined,\n });\n }\n\n /**\n * Add a non-chat participant to the conversation.\n *\n * @param proxyAddress\n * @param address\n * @param attributes\n * @param bindingOptions\n * @returns {Promise<any>}\n */\n addNonChatParticipant(\n proxyAddress: string,\n address: string,\n attributes: JSONValue = {},\n bindingOptions: ParticipantBindingOptions = {}\n ): Promise<ParticipantResponse> {\n return this.services.commandExecutor.mutateResource<\n AddParticipantRequest,\n ParticipantResponse\n >(\"post\", this.links.participants, {\n attributes:\n typeof attributes !== \"undefined\"\n ? JSON.stringify(attributes)\n : undefined,\n messaging_binding: {\n address,\n proxy_address: proxyAddress,\n name: bindingOptions?.email?.name,\n level: bindingOptions?.email?.level,\n },\n });\n }\n\n /**\n * Remove the participant with a given identity from a conversation.\n */\n remove(identity: string): Promise<void> {\n return this.services.commandExecutor.mutateResource(\n \"delete\",\n `${this.links.participants}/${identity}`\n );\n }\n}\n\nexport { Participants };\n\n/**\n * Fired when participant joined conversation\n * @event Participants#participantJoined\n * @type {Participant}\n */\n\n/**\n * Fired when participant left conversation\n * @event Participants#participantLeft\n * @type {Participant}\n */\n\n/**\n * Fired when participant updated\n * @event Participants#participantUpdated\n * @type {Object}\n * @property {Participant} participant - Updated Participant\n * @property {Participant#UpdateReason[]} updateReasons - Array of Participant's updated event reasons\n */\n"],"names":["Logger","ReplayEventEmitter","participant","Participant"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,MAAM,GAAG,GAAGA,aAAM,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;AAgBzC;;;;;;AAMA,MAAM,YAAa,SAAQC,qCAAsC;IAU/D,YACE,YAA0B,EAC1B,YAAsC,EACtC,KAAwB,EACxB,aAA4B,EAC5B,QAA8B;QAE9B,KAAK,EAAE,CAAC;QAZV,wBAAmB,GAA4B,IAAI,CAAC;QAalD,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;KAC1B;IAED,MAAM,WAAW;QACf,IAAI,IAAI,CAAC,mBAAmB,EAAE;YAC5B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAAC;YAC9C,MAAM,CAAC,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC;SACjC;KACF;IAED,SAAS,CAAC,gBAAwB;QAChC,QAAQ,IAAI,CAAC,mBAAmB;YAC9B,IAAI,CAAC,mBAAmB;gBACxB,IAAI,CAAC,QAAQ,CAAC,UAAU;qBACrB,GAAG,CAAC,EAAE,EAAE,EAAE,gBAAgB,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC;qBACpD,IAAI,CAAC,CAAC,SAAS;oBACd,SAAS,CAAC,EAAE,CAAC,WAAW,EA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