@twilio/conversations 1.3.0-rc8 → 2.0.0-rc.4

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 (282) hide show
  1. package/CHANGELOG.md +210 -0
  2. package/README.md +22 -17
  3. package/dist/browser.js +7873 -0
  4. package/dist/browser.js.map +1 -0
  5. package/dist/docs/assets/css/main.css +2660 -0
  6. package/dist/docs/assets/images/icons.png +0 -0
  7. package/dist/docs/assets/images/icons@2x.png +0 -0
  8. package/dist/docs/assets/images/widgets.png +0 -0
  9. package/dist/docs/assets/images/widgets@2x.png +0 -0
  10. package/dist/docs/assets/js/main.js +248 -0
  11. package/dist/docs/assets/js/search.js +1 -0
  12. package/dist/docs/classes/AggregatedDeliveryReceipt.html +3286 -0
  13. package/dist/docs/classes/Client.html +4181 -0
  14. package/dist/docs/classes/Conversation.html +4397 -0
  15. package/dist/docs/classes/DetailedDeliveryReceipt.html +3265 -0
  16. package/dist/docs/classes/Media.html +3295 -0
  17. package/dist/docs/classes/Message.html +3713 -0
  18. package/dist/docs/classes/MessageBuilder.html +3280 -0
  19. package/dist/docs/classes/Participant.html +3517 -0
  20. package/dist/docs/classes/PushNotification.html +3232 -0
  21. package/dist/docs/classes/RestPaginator.html +3262 -0
  22. package/dist/docs/classes/UnsentMessage.html +3144 -0
  23. package/dist/docs/classes/User.html +3451 -0
  24. package/dist/docs/index.html +3394 -212
  25. package/dist/docs/interfaces/ClientOptions.html +3136 -0
  26. package/dist/docs/interfaces/ConversationState.html +3152 -0
  27. package/dist/docs/interfaces/CreateConversationOptions.html +3168 -0
  28. package/dist/docs/interfaces/LastMessage.html +3152 -0
  29. package/dist/docs/interfaces/Paginator.html +3243 -0
  30. package/dist/docs/interfaces/PushNotificationData.html +3168 -0
  31. package/dist/docs/interfaces/SendEmailOptions.html +3136 -0
  32. package/dist/docs/interfaces/SendMediaOptions.html +3170 -0
  33. package/dist/docs/modules.html +3425 -0
  34. package/dist/lib.d.ts +1952 -0
  35. package/dist/lib.js +7873 -0
  36. package/dist/lib.js.map +1 -0
  37. package/dist/post-install.js +29 -0
  38. package/dist/react-native.js +4038 -0
  39. package/dist/react-native.js.map +1 -0
  40. package/dist/twilio-conversations.js +40912 -0
  41. package/dist/twilio-conversations.min.js +156 -0
  42. package/package.json +59 -48
  43. package/.circleci/config.yml +0 -650
  44. package/.deepsource.toml +0 -6
  45. package/.env.example +0 -13
  46. package/browser/aggregateddeliveryreceipt.js +0 -152
  47. package/browser/client.js +0 -991
  48. package/browser/configuration.js +0 -80
  49. package/browser/conversation.js +0 -1826
  50. package/browser/data/conversations.js +0 -632
  51. package/browser/data/messages.js +0 -522
  52. package/browser/data/participants.js +0 -411
  53. package/browser/data/users.js +0 -281
  54. package/browser/detaileddeliveryreceipt.js +0 -44
  55. package/browser/index.js +0 -4
  56. package/browser/interfaces/limits.js +0 -3
  57. package/browser/interfaces/notificationtypes.js +0 -21
  58. package/browser/interfaces/paginator.js +0 -53
  59. package/browser/interfaces/responsecodes.js +0 -20
  60. package/browser/interfaces/transport.js +0 -3
  61. package/browser/logger.js +0 -141
  62. package/browser/media.js +0 -198
  63. package/browser/message.js +0 -685
  64. package/browser/participant.js +0 -415
  65. package/browser/pushnotification.js +0 -49
  66. package/browser/restpaginator.js +0 -74
  67. package/browser/services/network.js +0 -223
  68. package/browser/services/readhorizon.js +0 -181
  69. package/browser/services/typingindicator.js +0 -142
  70. package/browser/session.js +0 -505
  71. package/browser/sessionerror.js +0 -93
  72. package/browser/sri.json +0 -1
  73. package/browser/synclist.js +0 -90
  74. package/browser/synclistdescriptor.js +0 -29
  75. package/browser/syncpaginator.js +0 -63
  76. package/browser/user.js +0 -431
  77. package/browser/util/deferred.js +0 -56
  78. package/browser/util/index.js +0 -108
  79. package/dist/@twilio/conversations.js +0 -35533
  80. package/dist/@twilio/conversations.min.js +0 -204
  81. package/dist/docs/AggregatedDeliveryReceipt.html +0 -948
  82. package/dist/docs/Client.html +0 -5075
  83. package/dist/docs/Conversation.html +0 -6018
  84. package/dist/docs/DetailedDeliveryReceipt.html +0 -641
  85. package/dist/docs/Media.html +0 -694
  86. package/dist/docs/Message.html +0 -1934
  87. package/dist/docs/Paginator.html +0 -605
  88. package/dist/docs/Participant.html +0 -1510
  89. package/dist/docs/PushNotification.html +0 -836
  90. package/dist/docs/SessionError.html +0 -379
  91. package/dist/docs/User.html +0 -1315
  92. package/dist/docs/classes.list.html +0 -4431
  93. package/dist/docs/fonts/glyphicons-halflings-regular.eot +0 -0
  94. package/dist/docs/fonts/glyphicons-halflings-regular.svg +0 -288
  95. package/dist/docs/fonts/glyphicons-halflings-regular.ttf +0 -0
  96. package/dist/docs/fonts/glyphicons-halflings-regular.woff +0 -0
  97. package/dist/docs/fonts/glyphicons-halflings-regular.woff2 +0 -0
  98. package/dist/docs/img/glyphicons-halflings-white.png +0 -0
  99. package/dist/docs/img/glyphicons-halflings.png +0 -0
  100. package/dist/docs/quicksearch.html +0 -31
  101. package/dist/docs/scripts/docstrap.lib.js +0 -11
  102. package/dist/docs/scripts/fulltext-search-ui.js +0 -89
  103. package/dist/docs/scripts/fulltext-search.js +0 -36
  104. package/dist/docs/scripts/lunr.min.js +0 -6
  105. package/dist/docs/scripts/prettify/Apache-License-2.0.txt +0 -202
  106. package/dist/docs/scripts/prettify/jquery.min.js +0 -6
  107. package/dist/docs/scripts/prettify/lang-css.js +0 -21
  108. package/dist/docs/scripts/prettify/prettify.js +0 -496
  109. package/dist/docs/scripts/sunlight.js +0 -1157
  110. package/dist/docs/scripts/toc.js +0 -203
  111. package/dist/docs/styles/darkstrap.css +0 -960
  112. package/dist/docs/styles/prettify-tomorrow.css +0 -132
  113. package/dist/docs/styles/site.cerulean.css +0 -7008
  114. package/dist/docs/styles/site.cosmo.css +0 -7061
  115. package/dist/docs/styles/site.cyborg.css +0 -7048
  116. package/dist/docs/styles/site.darkly.css +0 -7171
  117. package/dist/docs/styles/site.darkstrap.css +0 -5638
  118. package/dist/docs/styles/site.dibs-bootstrap.css +0 -5899
  119. package/dist/docs/styles/site.flatly.css +0 -7147
  120. package/dist/docs/styles/site.journal.css +0 -6973
  121. package/dist/docs/styles/site.lumen.css +0 -7298
  122. package/dist/docs/styles/site.paper.css +0 -7623
  123. package/dist/docs/styles/site.readable.css +0 -6997
  124. package/dist/docs/styles/site.sandstone.css +0 -7035
  125. package/dist/docs/styles/site.simplex.css +0 -7023
  126. package/dist/docs/styles/site.slate.css +0 -7343
  127. package/dist/docs/styles/site.spacelab.css +0 -7055
  128. package/dist/docs/styles/site.superhero.css +0 -7131
  129. package/dist/docs/styles/site.united.css +0 -6895
  130. package/dist/docs/styles/site.yeti.css +0 -7195
  131. package/dist/docs/styles/sunlight.dark.css +0 -345
  132. package/dist/docs/styles/sunlight.default.css +0 -344
  133. package/dist/sri.json +0 -1
  134. package/lib/aggregateddeliveryreceipt.d.ts +0 -98
  135. package/lib/aggregateddeliveryreceipt.js +0 -112
  136. package/lib/client.d.ts +0 -317
  137. package/lib/client.js +0 -633
  138. package/lib/configuration.d.ts +0 -21
  139. package/lib/configuration.js +0 -41
  140. package/lib/conversation.d.ts +0 -460
  141. package/lib/conversation.js +0 -940
  142. package/lib/data/conversations.d.ts +0 -57
  143. package/lib/data/conversations.js +0 -296
  144. package/lib/data/messages.d.ts +0 -75
  145. package/lib/data/messages.js +0 -208
  146. package/lib/data/participants.d.ts +0 -94
  147. package/lib/data/participants.js +0 -204
  148. package/lib/data/users.d.ts +0 -42
  149. package/lib/data/users.js +0 -113
  150. package/lib/detaileddeliveryreceipt.d.ts +0 -45
  151. package/lib/detaileddeliveryreceipt.js +0 -34
  152. package/lib/index.d.ts +0 -1
  153. package/lib/index.js +0 -3
  154. package/lib/interfaces/limits.d.ts +0 -8
  155. package/lib/interfaces/limits.js +0 -2
  156. package/lib/interfaces/notificationtypes.d.ts +0 -8
  157. package/lib/interfaces/notificationtypes.js +0 -11
  158. package/lib/interfaces/paginator.d.ts +0 -52
  159. package/lib/interfaces/paginator.js +0 -28
  160. package/lib/interfaces/responsecodes.d.ts +0 -8
  161. package/lib/interfaces/responsecodes.js +0 -10
  162. package/lib/interfaces/transport.d.ts +0 -13
  163. package/lib/interfaces/transport.js +0 -2
  164. package/lib/logger.d.ts +0 -18
  165. package/lib/logger.js +0 -35
  166. package/lib/media.d.ts +0 -52
  167. package/lib/media.js +0 -69
  168. package/lib/message.d.ts +0 -136
  169. package/lib/message.js +0 -305
  170. package/lib/participant.d.ts +0 -142
  171. package/lib/participant.js +0 -219
  172. package/lib/pushnotification.d.ts +0 -48
  173. package/lib/pushnotification.js +0 -39
  174. package/lib/restpaginator.d.ts +0 -19
  175. package/lib/restpaginator.js +0 -36
  176. package/lib/services/network.d.ts +0 -22
  177. package/lib/services/network.js +0 -87
  178. package/lib/services/readhorizon.d.ts +0 -28
  179. package/lib/services/readhorizon.js +0 -112
  180. package/lib/services/typingindicator.d.ts +0 -50
  181. package/lib/services/typingindicator.js +0 -102
  182. package/lib/session.d.ts +0 -63
  183. package/lib/session.js +0 -213
  184. package/lib/sessionerror.d.ts +0 -12
  185. package/lib/sessionerror.js +0 -24
  186. package/lib/sri.json +0 -1
  187. package/lib/synclist.d.ts +0 -24
  188. package/lib/synclist.js +0 -28
  189. package/lib/synclistdescriptor.d.ts +0 -27
  190. package/lib/synclistdescriptor.js +0 -19
  191. package/lib/syncpaginator.d.ts +0 -22
  192. package/lib/syncpaginator.js +0 -37
  193. package/lib/user.d.ts +0 -98
  194. package/lib/user.js +0 -219
  195. package/lib/util/deferred.d.ts +0 -12
  196. package/lib/util/deferred.js +0 -22
  197. package/lib/util/index.d.ts +0 -28
  198. package/lib/util/index.js +0 -82
  199. package/tools/rtd-sdk-cdn-pin/.gitrepo +0 -12
  200. package/tools/rtd-sdk-cdn-pin/README.md +0 -54
  201. package/tools/rtd-sdk-cdn-pin/bintray-settings.xml.template +0 -16
  202. package/tools/rtd-sdk-cdn-pin/cdn-common/cdn-prepare.sh +0 -67
  203. package/tools/rtd-sdk-cdn-pin/cdn-pin-latest.sh +0 -19
  204. package/tools/rtd-sdk-cdn-pin/cdn-pin.sh +0 -19
  205. package/tools/rtd-sdk-cdn-pin/cdn-upload.sh +0 -13
  206. package/tools/rtd-sdk-cdn-pin/fetch/common/fetch-bintray-android.sh +0 -34
  207. package/tools/rtd-sdk-cdn-pin/fetch/common/fetch-npm.sh +0 -18
  208. package/tools/rtd-sdk-cdn-pin/fetch/twilio-chat-android.sh +0 -5
  209. package/tools/rtd-sdk-cdn-pin/fetch/twilio-chat-js.sh +0 -5
  210. package/tools/rtd-sdk-cdn-pin/fetch/twilio-conversations-android.sh +0 -6
  211. package/tools/rtd-sdk-cdn-pin/fetch/twilio-conversations-js.sh +0 -5
  212. package/tools/rtd-sdk-cdn-pin/fetch/twilio-sync-android.sh +0 -5
  213. package/tools/rtd-sdk-cdn-pin/fetch/twilio-sync-js.sh +0 -5
  214. package/tools/rtd-sdk-cdn-pin/fetch-artifact.sh +0 -26
  215. package/tools/sdk-release-tool/.gitrepo +0 -12
  216. package/tools/sdk-release-tool/Makefile +0 -49
  217. package/tools/sdk-release-tool/README.md +0 -275
  218. package/tools/sdk-release-tool/delete +0 -3
  219. package/tools/sdk-release-tool/download +0 -3
  220. package/tools/sdk-release-tool/get-cors +0 -3
  221. package/tools/sdk-release-tool/list +0 -3
  222. package/tools/sdk-release-tool/pin +0 -3
  223. package/tools/sdk-release-tool/pin-latest +0 -3
  224. package/tools/sdk-release-tool/requirements.txt +0 -4
  225. package/tools/sdk-release-tool/sdk-release-tool +0 -3
  226. package/tools/sdk-release-tool/sdk_release_tools/__init__.py +0 -0
  227. package/tools/sdk-release-tool/sdk_release_tools/__main__.py +0 -110
  228. package/tools/sdk-release-tool/sdk_release_tools/aws.py +0 -70
  229. package/tools/sdk-release-tool/sdk_release_tools/cli.py +0 -181
  230. package/tools/sdk-release-tool/sdk_release_tools/log.py +0 -24
  231. package/tools/sdk-release-tool/sdk_release_tools/ops.py +0 -295
  232. package/tools/sdk-release-tool/sdk_release_tools/rpm.py +0 -28
  233. package/tools/sdk-release-tool/sdk_release_tools/util.py +0 -186
  234. package/tools/sdk-release-tool/sdk_release_tools/versions.py +0 -362
  235. package/tools/sdk-release-tool/signal-sdk-js.json +0 -28
  236. package/tools/sdk-release-tool/tests/test_versions.py +0 -94
  237. package/tools/sdk-release-tool/twilio-accessmanager-android.json +0 -19
  238. package/tools/sdk-release-tool/twilio-accessmanager-ios.json +0 -26
  239. package/tools/sdk-release-tool/twilio-auth-ios.json +0 -29
  240. package/tools/sdk-release-tool/twilio-authenticator-ios.json +0 -29
  241. package/tools/sdk-release-tool/twilio-chat-android-2.json +0 -19
  242. package/tools/sdk-release-tool/twilio-chat-android.json +0 -22
  243. package/tools/sdk-release-tool/twilio-chat-ios.json +0 -26
  244. package/tools/sdk-release-tool/twilio-chat-js.json +0 -27
  245. package/tools/sdk-release-tool/twilio-client-android-aar.json +0 -22
  246. package/tools/sdk-release-tool/twilio-client-android.json +0 -22
  247. package/tools/sdk-release-tool/twilio-client-ios.json +0 -20
  248. package/tools/sdk-release-tool/twilio-client-js.json +0 -17
  249. package/tools/sdk-release-tool/twilio-client-sounds-js.json +0 -14
  250. package/tools/sdk-release-tool/twilio-common-android-maven.json +0 -16
  251. package/tools/sdk-release-tool/twilio-common-android.json +0 -22
  252. package/tools/sdk-release-tool/twilio-common-ios-rtc.json +0 -25
  253. package/tools/sdk-release-tool/twilio-common-ios.json +0 -25
  254. package/tools/sdk-release-tool/twilio-common-js.json +0 -19
  255. package/tools/sdk-release-tool/twilio-conversations-android.json +0 -22
  256. package/tools/sdk-release-tool/twilio-conversations-ios.json +0 -26
  257. package/tools/sdk-release-tool/twilio-conversations-js.json +0 -27
  258. package/tools/sdk-release-tool/twilio-flex-js.json +0 -20
  259. package/tools/sdk-release-tool/twilio-flex-webchat-js.json +0 -16
  260. package/tools/sdk-release-tool/twilio-frame-chat-android.json +0 -22
  261. package/tools/sdk-release-tool/twilio-frame-chat-ios.json +0 -23
  262. package/tools/sdk-release-tool/twilio-frame-chat-js.json +0 -23
  263. package/tools/sdk-release-tool/twilio-ip-messaging-android-maven.json +0 -16
  264. package/tools/sdk-release-tool/twilio-ip-messaging-android.json +0 -22
  265. package/tools/sdk-release-tool/twilio-ip-messaging-ios.json +0 -25
  266. package/tools/sdk-release-tool/twilio-ip-messaging-js.json +0 -21
  267. package/tools/sdk-release-tool/twilio-sync-android.json +0 -22
  268. package/tools/sdk-release-tool/twilio-sync-ios.json +0 -26
  269. package/tools/sdk-release-tool/twilio-sync-js.json +0 -39
  270. package/tools/sdk-release-tool/twilio-taskrouter-js.json +0 -17
  271. package/tools/sdk-release-tool/twilio-video-android.json +0 -22
  272. package/tools/sdk-release-tool/twilio-video-cpp-linux-cross-rootfs.json +0 -13
  273. package/tools/sdk-release-tool/twilio-video-cpp.json +0 -33
  274. package/tools/sdk-release-tool/twilio-video-ios.json +0 -25
  275. package/tools/sdk-release-tool/twilio-video-js.json +0 -19
  276. package/tools/sdk-release-tool/twilio-video-jsdocs.json +0 -14
  277. package/tools/sdk-release-tool/twilio-voice-android.json +0 -22
  278. package/tools/sdk-release-tool/twilio-voice-ios.json +0 -29
  279. package/tools/sdk-release-tool/unpin +0 -3
  280. package/tools/sdk-release-tool/unpin-latest +0 -3
  281. package/tools/sdk-release-tool/upload +0 -3
  282. package/twilio-chat.js.iml +0 -9
@@ -1,57 +0,0 @@
1
- /// <reference types="node" />
2
- import { EventEmitter } from 'events';
3
- import { Conversation } from '../conversation';
4
- import { SyncClient } from 'twilio-sync';
5
- import { Session } from '../session';
6
- import { SyncList } from '../synclist';
7
- import { Users } from './users';
8
- import { Network } from '../services/network';
9
- import { TypingIndicator } from '../services/typingindicator';
10
- import { ReadHorizon } from '../services/readhorizon';
11
- import { McsClient } from 'twilio-mcs-client';
12
- import { Deferred } from '../util/deferred';
13
- export interface ConversationsServices {
14
- session: Session;
15
- syncClient: SyncClient;
16
- syncList: SyncList;
17
- users: Users;
18
- typingIndicator: TypingIndicator;
19
- readHorizon: ReadHorizon;
20
- network: Network;
21
- mcsClient: McsClient;
22
- }
23
- /**
24
- * Represents conversations collection
25
- * {@see Conversation}
26
- */
27
- declare class Conversations extends EventEmitter {
28
- private services;
29
- readonly conversations: Map<string, Conversation>;
30
- private readonly tombstones;
31
- private syncListFetched;
32
- readonly syncListRead: Deferred<boolean>;
33
- constructor(services: ConversationsServices);
34
- private getMap;
35
- /**
36
- * Add conversation to server
37
- * @private
38
- * @returns {Promise<Conversation>} Conversation
39
- */
40
- addConversation(options: any): Promise<Conversation>;
41
- /**
42
- * Fetch conversations list and instantiate all necessary objects
43
- */
44
- fetchConversations(): void;
45
- private _wrapPaginator;
46
- getConversations(args: any): Promise<any>;
47
- getConversation(sid: string): Promise<Conversation>;
48
- getConversationByUniqueName(uniqueName: string): Promise<Conversation>;
49
- getWhisperConversation(sid: string): Promise<Conversation>;
50
- private upsertConversation;
51
- private onConversationRemoved;
52
- private registerForEvents;
53
- }
54
- declare namespace Conversations {
55
- type DataSource = 'sync' | 'chat' | 'synclist';
56
- }
57
- export { Conversation, Conversations };
@@ -1,296 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const events_1 = require("events");
4
- const logger_1 = require("../logger");
5
- const conversation_1 = require("../conversation");
6
- exports.Conversation = conversation_1.Conversation;
7
- const deferred_1 = require("../util/deferred");
8
- const util_1 = require("../util");
9
- const log = logger_1.Logger.scope('Conversations');
10
- async function wrapService(services) {
11
- return {
12
- limits: await services.session.getMediaLimits(),
13
- session: services.session,
14
- syncClient: services.syncClient,
15
- users: services.users,
16
- typingIndicator: services.typingIndicator,
17
- readHorizon: services.readHorizon,
18
- network: services.network,
19
- mcsClient: services.mcsClient,
20
- };
21
- }
22
- /**
23
- * Represents conversations collection
24
- * {@see Conversation}
25
- */
26
- class Conversations extends events_1.EventEmitter {
27
- constructor(services) {
28
- super();
29
- this.services = services;
30
- this.conversations = new Map();
31
- this.tombstones = new Set();
32
- this.syncListFetched = false;
33
- this.syncListRead = new deferred_1.Deferred();
34
- }
35
- getMap() {
36
- return this.services.session.getMyConversationsId()
37
- .then(name => this.services.syncClient.map({ id: name, mode: 'open_existing' }));
38
- }
39
- /**
40
- * Add conversation to server
41
- * @private
42
- * @returns {Promise<Conversation>} Conversation
43
- */
44
- async addConversation(options) {
45
- let attributes;
46
- if (typeof options.attributes === 'undefined') {
47
- attributes = {};
48
- }
49
- else {
50
- attributes = options.attributes;
51
- }
52
- let response = await this.services.session.addCommand('createConversation', {
53
- friendlyName: options.friendlyName,
54
- uniqueName: options.uniqueName,
55
- attributes: JSON.stringify(attributes)
56
- });
57
- let conversationSid = 'conversationSid' in response ? response['conversationSid'] : null;
58
- let conversationDocument = 'conversation' in response ? response['conversation'] : null;
59
- let existingConversation = this.conversations.get(conversationSid);
60
- if (existingConversation) {
61
- await existingConversation._subscribe();
62
- return existingConversation;
63
- }
64
- let conversation = new conversation_1.Conversation(await wrapService(this.services), {
65
- channel: conversationDocument,
66
- entityName: null,
67
- uniqueName: null,
68
- attributes: null,
69
- createdBy: null,
70
- friendlyName: null,
71
- lastConsumedMessageIndex: null,
72
- dateCreated: null,
73
- dateUpdated: null
74
- }, conversationSid);
75
- this.conversations.set(conversation.sid, conversation);
76
- this.registerForEvents(conversation);
77
- await conversation._subscribe();
78
- this.emit('conversationAdded', conversation);
79
- return conversation;
80
- }
81
- /**
82
- * Fetch conversations list and instantiate all necessary objects
83
- */
84
- fetchConversations() {
85
- this.getMap()
86
- .then(async (map) => {
87
- map.on('itemAdded', args => {
88
- log.debug('itemAdded: ' + args.item.key);
89
- this.upsertConversation('sync', args.item.key, args.item.data);
90
- });
91
- map.on('itemRemoved', args => {
92
- log.debug('itemRemoved: ' + args.key);
93
- let sid = args.key;
94
- if (!this.syncListFetched) {
95
- this.tombstones.add(sid);
96
- }
97
- let conversation = this.conversations.get(sid);
98
- if (conversation) {
99
- if (conversation && conversation.status === 'joined' /*|| conversation.status === 'invited'*/) {
100
- conversation._setStatus('notParticipating', 'sync');
101
- this.emit('conversationLeft', conversation);
102
- }
103
- this.conversations.delete(sid);
104
- this.emit('conversationRemoved', conversation);
105
- conversation.emit('removed', conversation);
106
- }
107
- });
108
- map.on('itemUpdated', args => {
109
- log.debug('itemUpdated: ' + args.item.key);
110
- this.upsertConversation('sync', args.item.key, args.item.data);
111
- });
112
- let upserts = [];
113
- let paginator = await this.services.syncList.getPage();
114
- let items = paginator.items;
115
- items.forEach(item => {
116
- upserts.push(this.upsertConversation('synclist', item.channel_sid, item));
117
- });
118
- while (paginator.hasNextPage) {
119
- paginator = await paginator.nextPage();
120
- paginator.items.forEach(item => {
121
- upserts.push(this.upsertConversation('synclist', item.channel_sid, item));
122
- });
123
- }
124
- this.syncListRead.set(true);
125
- return Promise.all(upserts);
126
- })
127
- .then(() => {
128
- this.syncListFetched = true;
129
- this.tombstones.clear();
130
- log.debug('Conversations list fetched');
131
- })
132
- .then(() => this)
133
- .catch(e => {
134
- if (this.services.syncClient.connectionState != 'disconnected') {
135
- log.error('Failed to get conversations list', e);
136
- }
137
- log.debug('ERROR: Failed to get conversations list', e);
138
- throw e;
139
- });
140
- }
141
- _wrapPaginator(page, op) {
142
- return op(page.items)
143
- .then(items => ({
144
- items: items,
145
- hasNextPage: page.hasNextPage,
146
- hasPrevPage: page.hasPrevPage,
147
- nextPage: () => page.nextPage().then(x => this._wrapPaginator(x, op)),
148
- prevPage: () => page.prevPage().then(x => this._wrapPaginator(x, op))
149
- }));
150
- }
151
- getConversations(args) {
152
- return this.getMap()
153
- .then(conversationsMap => conversationsMap.getItems(args))
154
- .then(page => this._wrapPaginator(page, items => Promise.all(items.map(item => this.upsertConversation('sync', item.key, item.data)))));
155
- }
156
- getConversation(sid) {
157
- return this.getMap()
158
- .then(conversationsMap => conversationsMap.getItems({ key: sid }))
159
- .then(page => page.items.map(item => this.upsertConversation('sync', item.key, item.data)))
160
- .then(items => items.length > 0 ? items[0] : null);
161
- }
162
- async getConversationByUniqueName(uniqueName) {
163
- var _a, _b;
164
- const links = await this.services.session.getSessionLinks();
165
- const url = new util_1.UriBuilder(links.myChannelsUrl).path(uniqueName).build();
166
- const response = await this.services.network.get(url);
167
- const body = response.body;
168
- const sid = body.channel_sid;
169
- const data = {
170
- entityName: null,
171
- lastConsumedMessageIndex: body.last_consumed_message_index,
172
- status: ((_a = body) === null || _a === void 0 ? void 0 : _a.status) || 'unknown',
173
- friendlyName: body.friendly_name,
174
- dateUpdated: body.date_updated,
175
- dateCreated: body.date_created,
176
- uniqueName: body.unique_name,
177
- createdBy: body.created_by,
178
- attributes: body.attributes,
179
- channel: `${sid}.channel`,
180
- notificationLevel: (_b = body) === null || _b === void 0 ? void 0 : _b.notification_level,
181
- sid
182
- };
183
- return this.upsertConversation('sync', sid, data);
184
- }
185
- async getWhisperConversation(sid) {
186
- var _a, _b;
187
- const links = await this.services.session.getSessionLinks();
188
- const url = new util_1.UriBuilder(links.publicChannelsUrl).path(sid).build();
189
- const response = await this.services.network.get(url);
190
- const body = response.body;
191
- if (body.type !== 'private') {
192
- return null;
193
- }
194
- const data = {
195
- entityName: null,
196
- lastConsumedMessageIndex: body.last_consumed_message_index,
197
- status: ((_a = body) === null || _a === void 0 ? void 0 : _a.status) || 'unknown',
198
- friendlyName: body.friendly_name,
199
- dateUpdated: body.date_updated,
200
- dateCreated: body.date_created,
201
- uniqueName: body.unique_name,
202
- createdBy: body.created_by,
203
- attributes: body.attributes,
204
- channel: `${sid}.channel`,
205
- notificationLevel: (_b = body) === null || _b === void 0 ? void 0 : _b.notification_level,
206
- sid
207
- };
208
- return this.upsertConversation('sync', sid, data);
209
- }
210
- async upsertConversation(source, sid, data) {
211
- log.trace('upsertConversation(sid=' + sid + ', data=', data);
212
- let conversation = this.conversations.get(sid);
213
- // Update the Conversation's status if we know about it
214
- if (conversation) {
215
- log.trace('upsertConversation: conversation ' + sid + ' is known and it\'s' +
216
- ' status is known from source ' + conversation._statusSource() +
217
- ' and update came from source ' + source, conversation);
218
- if (typeof conversation._statusSource() === 'undefined'
219
- || source === conversation._statusSource()
220
- || (source === 'synclist' && conversation._statusSource() !== 'sync')
221
- || source === 'sync') {
222
- if (data.status === 'joined' && conversation.status !== 'joined') {
223
- conversation._setStatus('joined', source);
224
- let updateData = {};
225
- if (typeof data.notificationLevel !== 'undefined') {
226
- updateData.notificationLevel = data.notificationLevel;
227
- }
228
- if (typeof data.lastConsumedMessageIndex !== 'undefined') {
229
- updateData.lastConsumedMessageIndex = data.lastConsumedMessageIndex;
230
- }
231
- if (!util_1.isDeepEqual(updateData, {})) {
232
- conversation._update(updateData);
233
- }
234
- conversation._subscribe().then(() => { this.emit('conversationJoined', conversation); });
235
- }
236
- else if (data.status === 'notParticipating' && conversation.status === 'joined') {
237
- conversation._setStatus('notParticipating', source);
238
- conversation._update(data);
239
- conversation._subscribe().then(() => { this.emit('conversationLeft', conversation); });
240
- }
241
- else if (data.status === 'notParticipating') {
242
- conversation._subscribe();
243
- }
244
- else {
245
- conversation._update(data);
246
- }
247
- }
248
- else {
249
- log.trace('upsertConversation: conversation is known from sync and came from chat, ignoring', {
250
- sid: sid,
251
- data: data.status,
252
- conversation: conversation.status
253
- });
254
- }
255
- return conversation._subscribe().then(() => conversation);
256
- }
257
- if ((source === 'chat' || source === 'synclist') && this.tombstones.has(sid)) {
258
- // if conversation was deleted, we ignore it
259
- log.trace('upsertConversation: conversation is deleted and came again from chat, ignoring', sid);
260
- return;
261
- }
262
- // Fetch the Conversation if we don't know about it
263
- log.trace('upsertConversation: creating local conversation object with sid ' + sid, data);
264
- conversation = new conversation_1.Conversation(await wrapService(this.services), data, sid);
265
- this.conversations.set(sid, conversation);
266
- return conversation._subscribe().then(() => {
267
- this.registerForEvents(conversation);
268
- this.emit('conversationAdded', conversation);
269
- if (data.status === 'joined') {
270
- conversation._setStatus('joined', source);
271
- this.emit('conversationJoined', conversation);
272
- }
273
- return conversation;
274
- });
275
- }
276
- onConversationRemoved(sid) {
277
- let conversation = this.conversations.get(sid);
278
- if (conversation) {
279
- this.conversations.delete(sid);
280
- this.emit('conversationRemoved', conversation);
281
- }
282
- }
283
- registerForEvents(conversation) {
284
- conversation.on('removed', () => this.onConversationRemoved(conversation.sid));
285
- conversation.on('updated', (args) => this.emit('conversationUpdated', args));
286
- conversation.on('participantJoined', this.emit.bind(this, 'participantJoined'));
287
- conversation.on('participantLeft', this.emit.bind(this, 'participantLeft'));
288
- conversation.on('participantUpdated', (args) => this.emit('participantUpdated', args));
289
- conversation.on('messageAdded', this.emit.bind(this, 'messageAdded'));
290
- conversation.on('messageUpdated', (args) => this.emit('messageUpdated', args));
291
- conversation.on('messageRemoved', this.emit.bind(this, 'messageRemoved'));
292
- conversation.on('typingStarted', this.emit.bind(this, 'typingStarted'));
293
- conversation.on('typingEnded', this.emit.bind(this, 'typingEnded'));
294
- }
295
- }
296
- exports.Conversations = Conversations;
@@ -1,75 +0,0 @@
1
- /// <reference types="node" />
2
- import { EventEmitter } from 'events';
3
- import { Message } from '../message';
4
- import { Conversation, UnsentMessage } from '../conversation';
5
- import { SyncList, SyncClient } from 'twilio-sync';
6
- import { SyncPaginator } from '../syncpaginator';
7
- import { Session } from '../session';
8
- import { McsClient } from 'twilio-mcs-client';
9
- import { Network } from '../services/network';
10
- export interface MessagesServices {
11
- session: Session;
12
- mcsClient: McsClient;
13
- network: Network;
14
- syncClient: SyncClient;
15
- }
16
- /**
17
- * Represents the collection of messages in a conversation
18
- */
19
- declare class Messages extends EventEmitter {
20
- private readonly services;
21
- private readonly messagesByIndex;
22
- private messagesListPromise;
23
- readonly conversation: Conversation;
24
- constructor(conversation: Conversation, services: MessagesServices);
25
- /**
26
- * Subscribe to the Messages Event Stream
27
- * @param {String} name - The name of Sync object for the Messages resource.
28
- * @returns {Promise}
29
- */
30
- subscribe(name: string): Promise<SyncList>;
31
- unsubscribe(): Promise<void>;
32
- /**
33
- * Send Message to the conversation, message could include both text and multiple media atttachments.
34
- * @param {String} message - Message to post
35
- * @param {any} attributes Message attributes
36
- * @param {Conversation.SendEmailOptions} emailOptions Options that modify E-mail integration behaviors.
37
- * @returns Returns promise which can fail
38
- */
39
- sendV2(message: UnsentMessage): Promise<any>;
40
- /**
41
- * Send Message to the conversation
42
- * @param {String} message - Message to post
43
- * @param {any} attributes Message attributes
44
- * @param {Conversation.SendEmailOptions} emailOptions Options that modify E-mail integration behaviors.
45
- * @returns Returns promise which can fail
46
- */
47
- send(message: string, attributes?: any, emailOptions?: Conversation.SendEmailOptions): Promise<any>;
48
- /**
49
- * Send Media Message to the conversation
50
- * @param {FormData | Conversation#SendMediaOptions} mediaContent - Media content to post
51
- * @param {any} attributes Message attributes
52
- * @returns Returns promise which can fail
53
- */
54
- sendMedia(mediaContent: FormData | Conversation.SendMediaOptions, attributes?: any, emailOptions?: Conversation.SendEmailOptions): Promise<any>;
55
- /**
56
- * Returns messages from conversation using paginator interface
57
- * @param {Number} [pageSize] Number of messages to return in single chunk. By default it's 30.
58
- * @param {String} [anchor] Most early message id which is already known, or 'end' by default
59
- * @param {String} [direction] Pagination order 'backwards' or 'forward', 'forward' by default
60
- * @returns {Promise<Paginator<Message>>} last page of messages by default
61
- */
62
- getMessages(pageSize: any, anchor: any, direction: any): Promise<SyncPaginator<Message>>;
63
- private wrapPaginator;
64
- private _upsertMessage;
65
- /**
66
- * Returns last messages from conversation
67
- * @param {Number} [pageSize] Number of messages to return in single chunk. By default it's 30.
68
- * @param {String} [anchor] Most early message id which is already known, or 'end' by default
69
- * @param {String} [direction] Pagination order 'backwards' or 'forward', or 'forward' by default
70
- * @returns {Promise<SyncPaginator<Message>>} last page of messages by default
71
- * @private
72
- */
73
- private _getMessages;
74
- }
75
- export { Messages };
@@ -1,208 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const events_1 = require("events");
4
- const logger_1 = require("../logger");
5
- const message_1 = require("../message");
6
- const log = logger_1.Logger.scope('Messages');
7
- /**
8
- * Represents the collection of messages in a conversation
9
- */
10
- class Messages extends events_1.EventEmitter {
11
- constructor(conversation, services) {
12
- super();
13
- this.conversation = conversation;
14
- this.services = services;
15
- this.messagesByIndex = new Map();
16
- this.messagesListPromise = null;
17
- }
18
- /**
19
- * Subscribe to the Messages Event Stream
20
- * @param {String} name - The name of Sync object for the Messages resource.
21
- * @returns {Promise}
22
- */
23
- subscribe(name) {
24
- return this.messagesListPromise =
25
- this.messagesListPromise ||
26
- this.services.syncClient.list({ id: name, mode: 'open_existing' })
27
- .then(list => {
28
- list.on('itemAdded', args => {
29
- log.debug(this.conversation.sid + ' itemAdded: ' + args.item.index);
30
- let message = new message_1.Message(this.conversation, this.services, args.item.index, args.item.data);
31
- if (this.messagesByIndex.has(message.index)) {
32
- log.debug('Message arrived, but already known and ignored', this.conversation.sid, message.index);
33
- return;
34
- }
35
- this.messagesByIndex.set(message.index, message);
36
- message.on('updated', (args) => this.emit('messageUpdated', args));
37
- this.emit('messageAdded', message);
38
- });
39
- list.on('itemRemoved', args => {
40
- log.debug(this.conversation.sid + ' itemRemoved: ' + args.index);
41
- let index = args.index;
42
- if (this.messagesByIndex.has(index)) {
43
- let message = this.messagesByIndex.get(index);
44
- this.messagesByIndex.delete(message.index);
45
- message.removeAllListeners('updated');
46
- this.emit('messageRemoved', message);
47
- }
48
- });
49
- list.on('itemUpdated', args => {
50
- log.debug(this.conversation.sid + ' itemUpdated: ' + args.item.index);
51
- let message = this.messagesByIndex.get(args.item.index);
52
- if (message) {
53
- message._update(args.item.data);
54
- }
55
- });
56
- return list;
57
- })
58
- .catch(err => {
59
- this.messagesListPromise = null;
60
- if (this.services.syncClient.connectionState != 'disconnected') {
61
- log.error('Failed to get messages object for conversation', this.conversation.sid, err);
62
- }
63
- log.debug('ERROR: Failed to get messages object for conversation', this.conversation.sid, err);
64
- throw err;
65
- });
66
- }
67
- async unsubscribe() {
68
- if (this.messagesListPromise) {
69
- let entity = await this.messagesListPromise;
70
- entity.close();
71
- this.messagesListPromise = null;
72
- }
73
- }
74
- /**
75
- * Send Message to the conversation, message could include both text and multiple media atttachments.
76
- * @param {String} message - Message to post
77
- * @param {any} attributes Message attributes
78
- * @param {Conversation.SendEmailOptions} emailOptions Options that modify E-mail integration behaviors.
79
- * @returns Returns promise which can fail
80
- */
81
- async sendV2(message) {
82
- var _a;
83
- log.debug('Sending message V2', message.mediaContent, message.attributes, message.emailOptions);
84
- let media = new Array();
85
- for (const [category, mediaContent] of message.mediaContent) {
86
- if (typeof FormData !== 'undefined' && (mediaContent instanceof FormData)) {
87
- log.debug('Adding media to a message as FormData', mediaContent);
88
- media.push(await this.services.mcsClient.postFormData(mediaContent, category));
89
- }
90
- else {
91
- log.debug('Adding media to a message as SendMediaOptions', mediaContent);
92
- const mediaOptions = mediaContent;
93
- if (!mediaOptions.contentType || !mediaOptions.media) {
94
- throw new Error('Media content <Conversation#SendMediaOptions> must contain non-empty contentType and media');
95
- }
96
- media.push(await this.services.mcsClient.post(mediaOptions.contentType, mediaOptions.media, category));
97
- }
98
- }
99
- return this.services.session.addCommand('sendMessageV2', {
100
- conversationSid: this.conversation.sid,
101
- text: message.text,
102
- subject: (_a = message.emailOptions) === null || _a === void 0 ? void 0 : _a.subject,
103
- mediaSids: [...media.map((m) => m.sid)],
104
- attributes: JSON.stringify(message.attributes),
105
- });
106
- }
107
- /**
108
- * Send Message to the conversation
109
- * @param {String} message - Message to post
110
- * @param {any} attributes Message attributes
111
- * @param {Conversation.SendEmailOptions} emailOptions Options that modify E-mail integration behaviors.
112
- * @returns Returns promise which can fail
113
- */
114
- async send(message, attributes = {}, emailOptions) {
115
- var _a;
116
- log.debug('Sending text message', message, attributes, emailOptions);
117
- return this.services.session.addCommand('sendMessage', {
118
- channelSid: this.conversation.sid,
119
- text: message,
120
- attributes: JSON.stringify(attributes),
121
- subject: (_a = emailOptions) === null || _a === void 0 ? void 0 : _a.subject,
122
- });
123
- }
124
- /**
125
- * Send Media Message to the conversation
126
- * @param {FormData | Conversation#SendMediaOptions} mediaContent - Media content to post
127
- * @param {any} attributes Message attributes
128
- * @returns Returns promise which can fail
129
- */
130
- async sendMedia(mediaContent, attributes = {}, emailOptions) {
131
- log.debug('Sending media message', mediaContent, attributes, emailOptions);
132
- let media;
133
- if (typeof FormData !== 'undefined' && (mediaContent instanceof FormData)) {
134
- log.debug('Sending media message as FormData', mediaContent, attributes);
135
- media = await this.services.mcsClient.postFormData(mediaContent);
136
- }
137
- else {
138
- log.debug('Sending media message as SendMediaOptions', mediaContent, attributes);
139
- let mediaOptions = mediaContent;
140
- if (!mediaOptions.contentType || !mediaOptions.media) {
141
- throw new Error('Media content <Conversation#SendMediaOptions> must contain non-empty contentType and media');
142
- }
143
- media = await this.services.mcsClient.post(mediaOptions.contentType, mediaOptions.media);
144
- }
145
- // emailOptions are currently ignored for media messages.
146
- return this.services.session.addCommand('sendMediaMessage', {
147
- channelSid: this.conversation.sid,
148
- mediaSid: media.sid,
149
- attributes: JSON.stringify(attributes)
150
- });
151
- }
152
- /**
153
- * Returns messages from conversation using paginator interface
154
- * @param {Number} [pageSize] Number of messages to return in single chunk. By default it's 30.
155
- * @param {String} [anchor] Most early message id which is already known, or 'end' by default
156
- * @param {String} [direction] Pagination order 'backwards' or 'forward', 'forward' by default
157
- * @returns {Promise<Paginator<Message>>} last page of messages by default
158
- */
159
- getMessages(pageSize, anchor, direction) {
160
- anchor = (typeof anchor !== 'undefined') ? anchor : 'end';
161
- direction = direction || 'backwards';
162
- return this._getMessages(pageSize, anchor, direction);
163
- }
164
- wrapPaginator(order, page, op) {
165
- // We should swap next and prev page here, because of misfit of Sync and Chat paging conceptions
166
- let shouldReverse = order === 'desc';
167
- let np = () => page.nextPage().then(x => this.wrapPaginator(order, x, op));
168
- let pp = () => page.prevPage().then(x => this.wrapPaginator(order, x, op));
169
- return op(page.items).then(items => ({
170
- items: items.sort((x, y) => { return x.index - y.index; }),
171
- hasPrevPage: shouldReverse ? page.hasNextPage : page.hasPrevPage,
172
- hasNextPage: shouldReverse ? page.hasPrevPage : page.hasNextPage,
173
- prevPage: shouldReverse ? np : pp,
174
- nextPage: shouldReverse ? pp : np
175
- }));
176
- }
177
- _upsertMessage(index, value) {
178
- let cachedMessage = this.messagesByIndex.get(index);
179
- if (cachedMessage) {
180
- return cachedMessage;
181
- }
182
- let message = new message_1.Message(this.conversation, this.services, index, value);
183
- this.messagesByIndex.set(message.index, message);
184
- message.on('updated', (args) => this.emit('messageUpdated', args));
185
- return message;
186
- }
187
- /**
188
- * Returns last messages from conversation
189
- * @param {Number} [pageSize] Number of messages to return in single chunk. By default it's 30.
190
- * @param {String} [anchor] Most early message id which is already known, or 'end' by default
191
- * @param {String} [direction] Pagination order 'backwards' or 'forward', or 'forward' by default
192
- * @returns {Promise<SyncPaginator<Message>>} last page of messages by default
193
- * @private
194
- */
195
- _getMessages(pageSize, anchor, direction) {
196
- anchor = (typeof anchor !== 'undefined') ? anchor : 'end';
197
- pageSize = pageSize || 30;
198
- let order = direction === 'backwards' ? 'desc' : 'asc';
199
- return this.messagesListPromise
200
- .then(messagesList => messagesList.getItems({
201
- from: anchor !== 'end' ? anchor : void (0),
202
- pageSize,
203
- order
204
- }))
205
- .then(page => this.wrapPaginator(order, page, items => Promise.all(items.map(item => this._upsertMessage(item.index, item.data)))));
206
- }
207
- }
208
- exports.Messages = Messages;