@twilio/conversations 1.3.0-rc7 → 2.0.0-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +201 -0
- package/README.md +5 -5
- package/dist/browser.js +7866 -0
- package/dist/browser.js.map +1 -0
- package/dist/docs/assets/css/main.css +2660 -0
- package/dist/docs/assets/images/icons.png +0 -0
- package/dist/docs/assets/images/icons@2x.png +0 -0
- package/dist/docs/assets/images/widgets.png +0 -0
- package/dist/docs/assets/images/widgets@2x.png +0 -0
- package/dist/docs/assets/js/main.js +248 -0
- package/dist/docs/assets/js/search.js +1 -0
- package/dist/docs/classes/AggregatedDeliveryReceipt.html +3286 -0
- package/dist/docs/classes/Client.html +4181 -0
- package/dist/docs/classes/Conversation.html +4397 -0
- package/dist/docs/classes/DetailedDeliveryReceipt.html +3265 -0
- package/dist/docs/classes/Media.html +3295 -0
- package/dist/docs/classes/Message.html +3713 -0
- package/dist/docs/classes/MessageBuilder.html +3280 -0
- package/dist/docs/classes/Participant.html +3517 -0
- package/dist/docs/classes/PushNotification.html +3232 -0
- package/dist/docs/classes/RestPaginator.html +3262 -0
- package/dist/docs/classes/UnsentMessage.html +3144 -0
- package/dist/docs/classes/User.html +3451 -0
- package/dist/docs/index.html +3387 -212
- package/dist/docs/interfaces/ClientOptions.html +3136 -0
- package/dist/docs/interfaces/ConversationState.html +3152 -0
- package/dist/docs/interfaces/CreateConversationOptions.html +3168 -0
- package/dist/docs/interfaces/LastMessage.html +3152 -0
- package/dist/docs/interfaces/Paginator.html +3243 -0
- package/dist/docs/interfaces/PushNotificationData.html +3168 -0
- package/dist/docs/interfaces/SendEmailOptions.html +3136 -0
- package/dist/docs/interfaces/SendMediaOptions.html +3169 -0
- package/dist/docs/modules.html +3418 -0
- package/dist/lib.d.ts +1944 -0
- package/dist/lib.js +7866 -0
- package/dist/lib.js.map +1 -0
- package/dist/post-install.js +29 -0
- package/dist/react-native.js +4031 -0
- package/dist/react-native.js.map +1 -0
- package/dist/twilio-conversations.js +40905 -0
- package/dist/twilio-conversations.min.js +156 -0
- package/package.json +59 -48
- package/.circleci/config.yml +0 -650
- package/.deepsource.toml +0 -6
- package/.env.example +0 -13
- package/browser/aggregateddeliveryreceipt.js +0 -152
- package/browser/client.js +0 -991
- package/browser/configuration.js +0 -80
- package/browser/conversation.js +0 -1826
- package/browser/data/conversations.js +0 -665
- package/browser/data/messages.js +0 -522
- package/browser/data/participants.js +0 -411
- package/browser/data/users.js +0 -281
- package/browser/detaileddeliveryreceipt.js +0 -44
- package/browser/index.js +0 -4
- package/browser/interfaces/limits.js +0 -3
- package/browser/interfaces/notificationtypes.js +0 -21
- package/browser/interfaces/paginator.js +0 -53
- package/browser/interfaces/responsecodes.js +0 -20
- package/browser/interfaces/transport.js +0 -3
- package/browser/logger.js +0 -141
- package/browser/media.js +0 -198
- package/browser/message.js +0 -685
- package/browser/participant.js +0 -415
- package/browser/pushnotification.js +0 -49
- package/browser/restpaginator.js +0 -74
- package/browser/services/network.js +0 -223
- package/browser/services/readhorizon.js +0 -181
- package/browser/services/typingindicator.js +0 -142
- package/browser/session.js +0 -505
- package/browser/sessionerror.js +0 -93
- package/browser/sri.json +0 -1
- package/browser/synclist.js +0 -90
- package/browser/synclistdescriptor.js +0 -29
- package/browser/syncpaginator.js +0 -63
- package/browser/user.js +0 -431
- package/browser/util/deferred.js +0 -56
- package/browser/util/index.js +0 -108
- package/dist/@twilio/conversations.js +0 -35565
- package/dist/@twilio/conversations.min.js +0 -204
- package/dist/docs/AggregatedDeliveryReceipt.html +0 -948
- package/dist/docs/Client.html +0 -5075
- package/dist/docs/Conversation.html +0 -6018
- package/dist/docs/DetailedDeliveryReceipt.html +0 -641
- package/dist/docs/Media.html +0 -694
- package/dist/docs/Message.html +0 -1934
- package/dist/docs/Paginator.html +0 -605
- package/dist/docs/Participant.html +0 -1510
- package/dist/docs/PushNotification.html +0 -836
- package/dist/docs/SessionError.html +0 -379
- package/dist/docs/User.html +0 -1315
- package/dist/docs/classes.list.html +0 -4431
- package/dist/docs/fonts/glyphicons-halflings-regular.eot +0 -0
- package/dist/docs/fonts/glyphicons-halflings-regular.svg +0 -288
- package/dist/docs/fonts/glyphicons-halflings-regular.ttf +0 -0
- package/dist/docs/fonts/glyphicons-halflings-regular.woff +0 -0
- package/dist/docs/fonts/glyphicons-halflings-regular.woff2 +0 -0
- package/dist/docs/img/glyphicons-halflings-white.png +0 -0
- package/dist/docs/img/glyphicons-halflings.png +0 -0
- package/dist/docs/quicksearch.html +0 -31
- package/dist/docs/scripts/docstrap.lib.js +0 -11
- package/dist/docs/scripts/fulltext-search-ui.js +0 -89
- package/dist/docs/scripts/fulltext-search.js +0 -36
- package/dist/docs/scripts/lunr.min.js +0 -6
- package/dist/docs/scripts/prettify/Apache-License-2.0.txt +0 -202
- package/dist/docs/scripts/prettify/jquery.min.js +0 -6
- package/dist/docs/scripts/prettify/lang-css.js +0 -21
- package/dist/docs/scripts/prettify/prettify.js +0 -496
- package/dist/docs/scripts/sunlight.js +0 -1157
- package/dist/docs/scripts/toc.js +0 -203
- package/dist/docs/styles/darkstrap.css +0 -960
- package/dist/docs/styles/prettify-tomorrow.css +0 -132
- package/dist/docs/styles/site.cerulean.css +0 -7008
- package/dist/docs/styles/site.cosmo.css +0 -7061
- package/dist/docs/styles/site.cyborg.css +0 -7048
- package/dist/docs/styles/site.darkly.css +0 -7171
- package/dist/docs/styles/site.darkstrap.css +0 -5638
- package/dist/docs/styles/site.dibs-bootstrap.css +0 -5899
- package/dist/docs/styles/site.flatly.css +0 -7147
- package/dist/docs/styles/site.journal.css +0 -6973
- package/dist/docs/styles/site.lumen.css +0 -7298
- package/dist/docs/styles/site.paper.css +0 -7623
- package/dist/docs/styles/site.readable.css +0 -6997
- package/dist/docs/styles/site.sandstone.css +0 -7035
- package/dist/docs/styles/site.simplex.css +0 -7023
- package/dist/docs/styles/site.slate.css +0 -7343
- package/dist/docs/styles/site.spacelab.css +0 -7055
- package/dist/docs/styles/site.superhero.css +0 -7131
- package/dist/docs/styles/site.united.css +0 -6895
- package/dist/docs/styles/site.yeti.css +0 -7195
- package/dist/docs/styles/sunlight.dark.css +0 -345
- package/dist/docs/styles/sunlight.default.css +0 -344
- package/dist/sri.json +0 -1
- package/lib/aggregateddeliveryreceipt.d.ts +0 -98
- package/lib/aggregateddeliveryreceipt.js +0 -112
- package/lib/client.d.ts +0 -317
- package/lib/client.js +0 -633
- package/lib/configuration.d.ts +0 -21
- package/lib/configuration.js +0 -41
- package/lib/conversation.d.ts +0 -460
- package/lib/conversation.js +0 -940
- package/lib/data/conversations.d.ts +0 -57
- package/lib/data/conversations.js +0 -318
- package/lib/data/messages.d.ts +0 -75
- package/lib/data/messages.js +0 -208
- package/lib/data/participants.d.ts +0 -94
- package/lib/data/participants.js +0 -204
- package/lib/data/users.d.ts +0 -42
- package/lib/data/users.js +0 -113
- package/lib/detaileddeliveryreceipt.d.ts +0 -45
- package/lib/detaileddeliveryreceipt.js +0 -34
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -3
- package/lib/interfaces/limits.d.ts +0 -8
- package/lib/interfaces/limits.js +0 -2
- package/lib/interfaces/notificationtypes.d.ts +0 -8
- package/lib/interfaces/notificationtypes.js +0 -11
- package/lib/interfaces/paginator.d.ts +0 -52
- package/lib/interfaces/paginator.js +0 -28
- package/lib/interfaces/responsecodes.d.ts +0 -8
- package/lib/interfaces/responsecodes.js +0 -10
- package/lib/interfaces/transport.d.ts +0 -13
- package/lib/interfaces/transport.js +0 -2
- package/lib/logger.d.ts +0 -18
- package/lib/logger.js +0 -35
- package/lib/media.d.ts +0 -52
- package/lib/media.js +0 -69
- package/lib/message.d.ts +0 -136
- package/lib/message.js +0 -305
- package/lib/participant.d.ts +0 -142
- package/lib/participant.js +0 -219
- package/lib/pushnotification.d.ts +0 -48
- package/lib/pushnotification.js +0 -39
- package/lib/restpaginator.d.ts +0 -19
- package/lib/restpaginator.js +0 -36
- package/lib/services/network.d.ts +0 -22
- package/lib/services/network.js +0 -87
- package/lib/services/readhorizon.d.ts +0 -28
- package/lib/services/readhorizon.js +0 -112
- package/lib/services/typingindicator.d.ts +0 -50
- package/lib/services/typingindicator.js +0 -102
- package/lib/session.d.ts +0 -63
- package/lib/session.js +0 -213
- package/lib/sessionerror.d.ts +0 -12
- package/lib/sessionerror.js +0 -24
- package/lib/sri.json +0 -1
- package/lib/synclist.d.ts +0 -24
- package/lib/synclist.js +0 -28
- package/lib/synclistdescriptor.d.ts +0 -27
- package/lib/synclistdescriptor.js +0 -19
- package/lib/syncpaginator.d.ts +0 -22
- package/lib/syncpaginator.js +0 -37
- package/lib/user.d.ts +0 -98
- package/lib/user.js +0 -219
- package/lib/util/deferred.d.ts +0 -12
- package/lib/util/deferred.js +0 -22
- package/lib/util/index.d.ts +0 -28
- package/lib/util/index.js +0 -82
- package/tools/rtd-sdk-cdn-pin/.gitrepo +0 -12
- package/tools/rtd-sdk-cdn-pin/README.md +0 -54
- package/tools/rtd-sdk-cdn-pin/bintray-settings.xml.template +0 -16
- package/tools/rtd-sdk-cdn-pin/cdn-common/cdn-prepare.sh +0 -67
- package/tools/rtd-sdk-cdn-pin/cdn-pin-latest.sh +0 -19
- package/tools/rtd-sdk-cdn-pin/cdn-pin.sh +0 -19
- package/tools/rtd-sdk-cdn-pin/cdn-upload.sh +0 -13
- package/tools/rtd-sdk-cdn-pin/fetch/common/fetch-bintray-android.sh +0 -34
- package/tools/rtd-sdk-cdn-pin/fetch/common/fetch-npm.sh +0 -18
- package/tools/rtd-sdk-cdn-pin/fetch/twilio-chat-android.sh +0 -5
- package/tools/rtd-sdk-cdn-pin/fetch/twilio-chat-js.sh +0 -5
- package/tools/rtd-sdk-cdn-pin/fetch/twilio-conversations-android.sh +0 -6
- package/tools/rtd-sdk-cdn-pin/fetch/twilio-conversations-js.sh +0 -5
- package/tools/rtd-sdk-cdn-pin/fetch/twilio-sync-android.sh +0 -5
- package/tools/rtd-sdk-cdn-pin/fetch/twilio-sync-js.sh +0 -5
- package/tools/rtd-sdk-cdn-pin/fetch-artifact.sh +0 -26
- package/tools/sdk-release-tool/.gitrepo +0 -12
- package/tools/sdk-release-tool/Makefile +0 -49
- package/tools/sdk-release-tool/README.md +0 -275
- package/tools/sdk-release-tool/delete +0 -3
- package/tools/sdk-release-tool/download +0 -3
- package/tools/sdk-release-tool/get-cors +0 -3
- package/tools/sdk-release-tool/list +0 -3
- package/tools/sdk-release-tool/pin +0 -3
- package/tools/sdk-release-tool/pin-latest +0 -3
- package/tools/sdk-release-tool/requirements.txt +0 -4
- package/tools/sdk-release-tool/sdk-release-tool +0 -3
- package/tools/sdk-release-tool/sdk_release_tools/__init__.py +0 -0
- package/tools/sdk-release-tool/sdk_release_tools/__main__.py +0 -110
- package/tools/sdk-release-tool/sdk_release_tools/aws.py +0 -70
- package/tools/sdk-release-tool/sdk_release_tools/cli.py +0 -181
- package/tools/sdk-release-tool/sdk_release_tools/log.py +0 -24
- package/tools/sdk-release-tool/sdk_release_tools/ops.py +0 -295
- package/tools/sdk-release-tool/sdk_release_tools/rpm.py +0 -28
- package/tools/sdk-release-tool/sdk_release_tools/util.py +0 -186
- package/tools/sdk-release-tool/sdk_release_tools/versions.py +0 -362
- package/tools/sdk-release-tool/signal-sdk-js.json +0 -28
- package/tools/sdk-release-tool/tests/test_versions.py +0 -94
- package/tools/sdk-release-tool/twilio-accessmanager-android.json +0 -19
- package/tools/sdk-release-tool/twilio-accessmanager-ios.json +0 -26
- package/tools/sdk-release-tool/twilio-auth-ios.json +0 -29
- package/tools/sdk-release-tool/twilio-authenticator-ios.json +0 -29
- package/tools/sdk-release-tool/twilio-chat-android-2.json +0 -19
- package/tools/sdk-release-tool/twilio-chat-android.json +0 -22
- package/tools/sdk-release-tool/twilio-chat-ios.json +0 -26
- package/tools/sdk-release-tool/twilio-chat-js.json +0 -27
- package/tools/sdk-release-tool/twilio-client-android-aar.json +0 -22
- package/tools/sdk-release-tool/twilio-client-android.json +0 -22
- package/tools/sdk-release-tool/twilio-client-ios.json +0 -20
- package/tools/sdk-release-tool/twilio-client-js.json +0 -17
- package/tools/sdk-release-tool/twilio-client-sounds-js.json +0 -14
- package/tools/sdk-release-tool/twilio-common-android-maven.json +0 -16
- package/tools/sdk-release-tool/twilio-common-android.json +0 -22
- package/tools/sdk-release-tool/twilio-common-ios-rtc.json +0 -25
- package/tools/sdk-release-tool/twilio-common-ios.json +0 -25
- package/tools/sdk-release-tool/twilio-common-js.json +0 -19
- package/tools/sdk-release-tool/twilio-conversations-android.json +0 -22
- package/tools/sdk-release-tool/twilio-conversations-ios.json +0 -26
- package/tools/sdk-release-tool/twilio-conversations-js.json +0 -27
- package/tools/sdk-release-tool/twilio-flex-js.json +0 -20
- package/tools/sdk-release-tool/twilio-flex-webchat-js.json +0 -16
- package/tools/sdk-release-tool/twilio-frame-chat-android.json +0 -22
- package/tools/sdk-release-tool/twilio-frame-chat-ios.json +0 -23
- package/tools/sdk-release-tool/twilio-frame-chat-js.json +0 -23
- package/tools/sdk-release-tool/twilio-ip-messaging-android-maven.json +0 -16
- package/tools/sdk-release-tool/twilio-ip-messaging-android.json +0 -22
- package/tools/sdk-release-tool/twilio-ip-messaging-ios.json +0 -25
- package/tools/sdk-release-tool/twilio-ip-messaging-js.json +0 -21
- package/tools/sdk-release-tool/twilio-sync-android.json +0 -22
- package/tools/sdk-release-tool/twilio-sync-ios.json +0 -26
- package/tools/sdk-release-tool/twilio-sync-js.json +0 -39
- package/tools/sdk-release-tool/twilio-taskrouter-js.json +0 -17
- package/tools/sdk-release-tool/twilio-video-android.json +0 -22
- package/tools/sdk-release-tool/twilio-video-cpp-linux-cross-rootfs.json +0 -13
- package/tools/sdk-release-tool/twilio-video-cpp.json +0 -33
- package/tools/sdk-release-tool/twilio-video-ios.json +0 -25
- package/tools/sdk-release-tool/twilio-video-js.json +0 -19
- package/tools/sdk-release-tool/twilio-video-jsdocs.json +0 -14
- package/tools/sdk-release-tool/twilio-voice-android.json +0 -22
- package/tools/sdk-release-tool/twilio-voice-ios.json +0 -29
- package/tools/sdk-release-tool/unpin +0 -3
- package/tools/sdk-release-tool/unpin-latest +0 -3
- package/tools/sdk-release-tool/upload +0 -3
- package/twilio-chat.js.iml +0 -9
package/browser/data/messages.js
DELETED
@@ -1,522 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var _promise = require("babel-runtime/core-js/promise");
|
4
|
-
|
5
|
-
var _promise2 = _interopRequireDefault(_promise);
|
6
|
-
|
7
|
-
var _getIterator2 = require("babel-runtime/core-js/get-iterator");
|
8
|
-
|
9
|
-
var _getIterator3 = _interopRequireDefault(_getIterator2);
|
10
|
-
|
11
|
-
var _stringify = require("babel-runtime/core-js/json/stringify");
|
12
|
-
|
13
|
-
var _stringify2 = _interopRequireDefault(_stringify);
|
14
|
-
|
15
|
-
var _toConsumableArray2 = require("babel-runtime/helpers/toConsumableArray");
|
16
|
-
|
17
|
-
var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);
|
18
|
-
|
19
|
-
var _slicedToArray2 = require("babel-runtime/helpers/slicedToArray");
|
20
|
-
|
21
|
-
var _slicedToArray3 = _interopRequireDefault(_slicedToArray2);
|
22
|
-
|
23
|
-
var _regenerator = require("babel-runtime/regenerator");
|
24
|
-
|
25
|
-
var _regenerator2 = _interopRequireDefault(_regenerator);
|
26
|
-
|
27
|
-
var _asyncToGenerator2 = require("babel-runtime/helpers/asyncToGenerator");
|
28
|
-
|
29
|
-
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
|
30
|
-
|
31
|
-
var _map = require("babel-runtime/core-js/map");
|
32
|
-
|
33
|
-
var _map2 = _interopRequireDefault(_map);
|
34
|
-
|
35
|
-
var _getPrototypeOf = require("babel-runtime/core-js/object/get-prototype-of");
|
36
|
-
|
37
|
-
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
|
38
|
-
|
39
|
-
var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
|
40
|
-
|
41
|
-
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
|
42
|
-
|
43
|
-
var _createClass2 = require("babel-runtime/helpers/createClass");
|
44
|
-
|
45
|
-
var _createClass3 = _interopRequireDefault(_createClass2);
|
46
|
-
|
47
|
-
var _possibleConstructorReturn2 = require("babel-runtime/helpers/possibleConstructorReturn");
|
48
|
-
|
49
|
-
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
|
50
|
-
|
51
|
-
var _inherits2 = require("babel-runtime/helpers/inherits");
|
52
|
-
|
53
|
-
var _inherits3 = _interopRequireDefault(_inherits2);
|
54
|
-
|
55
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
56
|
-
|
57
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
58
|
-
var events_1 = require("events");
|
59
|
-
var logger_1 = require("../logger");
|
60
|
-
var message_1 = require("../message");
|
61
|
-
var log = logger_1.Logger.scope('Messages');
|
62
|
-
/**
|
63
|
-
* Represents the collection of messages in a conversation
|
64
|
-
*/
|
65
|
-
|
66
|
-
var Messages = function (_events_1$EventEmitte) {
|
67
|
-
(0, _inherits3.default)(Messages, _events_1$EventEmitte);
|
68
|
-
|
69
|
-
function Messages(conversation, services) {
|
70
|
-
(0, _classCallCheck3.default)(this, Messages);
|
71
|
-
|
72
|
-
var _this = (0, _possibleConstructorReturn3.default)(this, (Messages.__proto__ || (0, _getPrototypeOf2.default)(Messages)).call(this));
|
73
|
-
|
74
|
-
_this.conversation = conversation;
|
75
|
-
_this.services = services;
|
76
|
-
_this.messagesByIndex = new _map2.default();
|
77
|
-
_this.messagesListPromise = null;
|
78
|
-
return _this;
|
79
|
-
}
|
80
|
-
/**
|
81
|
-
* Subscribe to the Messages Event Stream
|
82
|
-
* @param {String} name - The name of Sync object for the Messages resource.
|
83
|
-
* @returns {Promise}
|
84
|
-
*/
|
85
|
-
|
86
|
-
|
87
|
-
(0, _createClass3.default)(Messages, [{
|
88
|
-
key: "subscribe",
|
89
|
-
value: function subscribe(name) {
|
90
|
-
var _this2 = this;
|
91
|
-
|
92
|
-
return this.messagesListPromise = this.messagesListPromise || this.services.syncClient.list({ id: name, mode: 'open_existing' }).then(function (list) {
|
93
|
-
list.on('itemAdded', function (args) {
|
94
|
-
log.debug(_this2.conversation.sid + ' itemAdded: ' + args.item.index);
|
95
|
-
var message = new message_1.Message(_this2.conversation, _this2.services, args.item.index, args.item.data);
|
96
|
-
if (_this2.messagesByIndex.has(message.index)) {
|
97
|
-
log.debug('Message arrived, but already known and ignored', _this2.conversation.sid, message.index);
|
98
|
-
return;
|
99
|
-
}
|
100
|
-
_this2.messagesByIndex.set(message.index, message);
|
101
|
-
message.on('updated', function (args) {
|
102
|
-
return _this2.emit('messageUpdated', args);
|
103
|
-
});
|
104
|
-
_this2.emit('messageAdded', message);
|
105
|
-
});
|
106
|
-
list.on('itemRemoved', function (args) {
|
107
|
-
log.debug(_this2.conversation.sid + ' itemRemoved: ' + args.index);
|
108
|
-
var index = args.index;
|
109
|
-
if (_this2.messagesByIndex.has(index)) {
|
110
|
-
var message = _this2.messagesByIndex.get(index);
|
111
|
-
_this2.messagesByIndex.delete(message.index);
|
112
|
-
message.removeAllListeners('updated');
|
113
|
-
_this2.emit('messageRemoved', message);
|
114
|
-
}
|
115
|
-
});
|
116
|
-
list.on('itemUpdated', function (args) {
|
117
|
-
log.debug(_this2.conversation.sid + ' itemUpdated: ' + args.item.index);
|
118
|
-
var message = _this2.messagesByIndex.get(args.item.index);
|
119
|
-
if (message) {
|
120
|
-
message._update(args.item.data);
|
121
|
-
}
|
122
|
-
});
|
123
|
-
return list;
|
124
|
-
}).catch(function (err) {
|
125
|
-
_this2.messagesListPromise = null;
|
126
|
-
if (_this2.services.syncClient.connectionState != 'disconnected') {
|
127
|
-
log.error('Failed to get messages object for conversation', _this2.conversation.sid, err);
|
128
|
-
}
|
129
|
-
log.debug('ERROR: Failed to get messages object for conversation', _this2.conversation.sid, err);
|
130
|
-
throw err;
|
131
|
-
});
|
132
|
-
}
|
133
|
-
}, {
|
134
|
-
key: "unsubscribe",
|
135
|
-
value: function () {
|
136
|
-
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee() {
|
137
|
-
var entity;
|
138
|
-
return _regenerator2.default.wrap(function _callee$(_context) {
|
139
|
-
while (1) {
|
140
|
-
switch (_context.prev = _context.next) {
|
141
|
-
case 0:
|
142
|
-
if (!this.messagesListPromise) {
|
143
|
-
_context.next = 6;
|
144
|
-
break;
|
145
|
-
}
|
146
|
-
|
147
|
-
_context.next = 3;
|
148
|
-
return this.messagesListPromise;
|
149
|
-
|
150
|
-
case 3:
|
151
|
-
entity = _context.sent;
|
152
|
-
|
153
|
-
entity.close();
|
154
|
-
this.messagesListPromise = null;
|
155
|
-
|
156
|
-
case 6:
|
157
|
-
case "end":
|
158
|
-
return _context.stop();
|
159
|
-
}
|
160
|
-
}
|
161
|
-
}, _callee, this);
|
162
|
-
}));
|
163
|
-
|
164
|
-
function unsubscribe() {
|
165
|
-
return _ref.apply(this, arguments);
|
166
|
-
}
|
167
|
-
|
168
|
-
return unsubscribe;
|
169
|
-
}()
|
170
|
-
/**
|
171
|
-
* Send Message to the conversation, message could include both text and multiple media atttachments.
|
172
|
-
* @param {String} message - Message to post
|
173
|
-
* @param {any} attributes Message attributes
|
174
|
-
* @param {Conversation.SendEmailOptions} emailOptions Options that modify E-mail integration behaviors.
|
175
|
-
* @returns Returns promise which can fail
|
176
|
-
*/
|
177
|
-
|
178
|
-
}, {
|
179
|
-
key: "sendV2",
|
180
|
-
value: function () {
|
181
|
-
var _ref2 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2(message) {
|
182
|
-
var _a, media, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _ref3, _ref4, category, mediaContent, mediaOptions;
|
183
|
-
|
184
|
-
return _regenerator2.default.wrap(function _callee2$(_context2) {
|
185
|
-
while (1) {
|
186
|
-
switch (_context2.prev = _context2.next) {
|
187
|
-
case 0:
|
188
|
-
log.debug('Sending message V2', message.mediaContent, message.attributes, message.emailOptions);
|
189
|
-
media = new Array();
|
190
|
-
_iteratorNormalCompletion = true;
|
191
|
-
_didIteratorError = false;
|
192
|
-
_iteratorError = undefined;
|
193
|
-
_context2.prev = 5;
|
194
|
-
_iterator = (0, _getIterator3.default)(message.mediaContent);
|
195
|
-
|
196
|
-
case 7:
|
197
|
-
if (_iteratorNormalCompletion = (_step = _iterator.next()).done) {
|
198
|
-
_context2.next = 33;
|
199
|
-
break;
|
200
|
-
}
|
201
|
-
|
202
|
-
_ref3 = _step.value;
|
203
|
-
_ref4 = (0, _slicedToArray3.default)(_ref3, 2);
|
204
|
-
category = _ref4[0];
|
205
|
-
mediaContent = _ref4[1];
|
206
|
-
|
207
|
-
if (!(typeof FormData !== 'undefined' && mediaContent instanceof FormData)) {
|
208
|
-
_context2.next = 21;
|
209
|
-
break;
|
210
|
-
}
|
211
|
-
|
212
|
-
log.debug('Adding media to a message as FormData', mediaContent);
|
213
|
-
_context2.t0 = media;
|
214
|
-
_context2.next = 17;
|
215
|
-
return this.services.mcsClient.postFormData(mediaContent, category);
|
216
|
-
|
217
|
-
case 17:
|
218
|
-
_context2.t1 = _context2.sent;
|
219
|
-
|
220
|
-
_context2.t0.push.call(_context2.t0, _context2.t1);
|
221
|
-
|
222
|
-
_context2.next = 30;
|
223
|
-
break;
|
224
|
-
|
225
|
-
case 21:
|
226
|
-
log.debug('Adding media to a message as SendMediaOptions', mediaContent);
|
227
|
-
mediaOptions = mediaContent;
|
228
|
-
|
229
|
-
if (!(!mediaOptions.contentType || !mediaOptions.media)) {
|
230
|
-
_context2.next = 25;
|
231
|
-
break;
|
232
|
-
}
|
233
|
-
|
234
|
-
throw new Error('Media content <Conversation#SendMediaOptions> must contain non-empty contentType and media');
|
235
|
-
|
236
|
-
case 25:
|
237
|
-
_context2.t2 = media;
|
238
|
-
_context2.next = 28;
|
239
|
-
return this.services.mcsClient.post(mediaOptions.contentType, mediaOptions.media, category);
|
240
|
-
|
241
|
-
case 28:
|
242
|
-
_context2.t3 = _context2.sent;
|
243
|
-
|
244
|
-
_context2.t2.push.call(_context2.t2, _context2.t3);
|
245
|
-
|
246
|
-
case 30:
|
247
|
-
_iteratorNormalCompletion = true;
|
248
|
-
_context2.next = 7;
|
249
|
-
break;
|
250
|
-
|
251
|
-
case 33:
|
252
|
-
_context2.next = 39;
|
253
|
-
break;
|
254
|
-
|
255
|
-
case 35:
|
256
|
-
_context2.prev = 35;
|
257
|
-
_context2.t4 = _context2["catch"](5);
|
258
|
-
_didIteratorError = true;
|
259
|
-
_iteratorError = _context2.t4;
|
260
|
-
|
261
|
-
case 39:
|
262
|
-
_context2.prev = 39;
|
263
|
-
_context2.prev = 40;
|
264
|
-
|
265
|
-
if (!_iteratorNormalCompletion && _iterator.return) {
|
266
|
-
_iterator.return();
|
267
|
-
}
|
268
|
-
|
269
|
-
case 42:
|
270
|
-
_context2.prev = 42;
|
271
|
-
|
272
|
-
if (!_didIteratorError) {
|
273
|
-
_context2.next = 45;
|
274
|
-
break;
|
275
|
-
}
|
276
|
-
|
277
|
-
throw _iteratorError;
|
278
|
-
|
279
|
-
case 45:
|
280
|
-
return _context2.finish(42);
|
281
|
-
|
282
|
-
case 46:
|
283
|
-
return _context2.finish(39);
|
284
|
-
|
285
|
-
case 47:
|
286
|
-
return _context2.abrupt("return", this.services.session.addCommand('sendMessageV2', {
|
287
|
-
conversationSid: this.conversation.sid,
|
288
|
-
text: message.text,
|
289
|
-
subject: (_a = message.emailOptions) === null || _a === void 0 ? void 0 : _a.subject,
|
290
|
-
mediaSids: [].concat((0, _toConsumableArray3.default)(media.map(function (m) {
|
291
|
-
return m.sid;
|
292
|
-
}))),
|
293
|
-
attributes: (0, _stringify2.default)(message.attributes)
|
294
|
-
}));
|
295
|
-
|
296
|
-
case 48:
|
297
|
-
case "end":
|
298
|
-
return _context2.stop();
|
299
|
-
}
|
300
|
-
}
|
301
|
-
}, _callee2, this, [[5, 35, 39, 47], [40,, 42, 46]]);
|
302
|
-
}));
|
303
|
-
|
304
|
-
function sendV2(_x) {
|
305
|
-
return _ref2.apply(this, arguments);
|
306
|
-
}
|
307
|
-
|
308
|
-
return sendV2;
|
309
|
-
}()
|
310
|
-
/**
|
311
|
-
* Send Message to the conversation
|
312
|
-
* @param {String} message - Message to post
|
313
|
-
* @param {any} attributes Message attributes
|
314
|
-
* @param {Conversation.SendEmailOptions} emailOptions Options that modify E-mail integration behaviors.
|
315
|
-
* @returns Returns promise which can fail
|
316
|
-
*/
|
317
|
-
|
318
|
-
}, {
|
319
|
-
key: "send",
|
320
|
-
value: function () {
|
321
|
-
var _ref5 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee3(message) {
|
322
|
-
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
323
|
-
var emailOptions = arguments[2];
|
324
|
-
|
325
|
-
var _a;
|
326
|
-
|
327
|
-
return _regenerator2.default.wrap(function _callee3$(_context3) {
|
328
|
-
while (1) {
|
329
|
-
switch (_context3.prev = _context3.next) {
|
330
|
-
case 0:
|
331
|
-
log.debug('Sending text message', message, attributes, emailOptions);
|
332
|
-
return _context3.abrupt("return", this.services.session.addCommand('sendMessage', {
|
333
|
-
channelSid: this.conversation.sid,
|
334
|
-
text: message,
|
335
|
-
attributes: (0, _stringify2.default)(attributes),
|
336
|
-
subject: (_a = emailOptions) === null || _a === void 0 ? void 0 : _a.subject
|
337
|
-
}));
|
338
|
-
|
339
|
-
case 2:
|
340
|
-
case "end":
|
341
|
-
return _context3.stop();
|
342
|
-
}
|
343
|
-
}
|
344
|
-
}, _callee3, this);
|
345
|
-
}));
|
346
|
-
|
347
|
-
function send(_x3) {
|
348
|
-
return _ref5.apply(this, arguments);
|
349
|
-
}
|
350
|
-
|
351
|
-
return send;
|
352
|
-
}()
|
353
|
-
/**
|
354
|
-
* Send Media Message to the conversation
|
355
|
-
* @param {FormData | Conversation#SendMediaOptions} mediaContent - Media content to post
|
356
|
-
* @param {any} attributes Message attributes
|
357
|
-
* @returns Returns promise which can fail
|
358
|
-
*/
|
359
|
-
|
360
|
-
}, {
|
361
|
-
key: "sendMedia",
|
362
|
-
value: function () {
|
363
|
-
var _ref6 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee4(mediaContent) {
|
364
|
-
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
365
|
-
var emailOptions = arguments[2];
|
366
|
-
var media, mediaOptions;
|
367
|
-
return _regenerator2.default.wrap(function _callee4$(_context4) {
|
368
|
-
while (1) {
|
369
|
-
switch (_context4.prev = _context4.next) {
|
370
|
-
case 0:
|
371
|
-
log.debug('Sending media message', mediaContent, attributes, emailOptions);
|
372
|
-
media = void 0;
|
373
|
-
|
374
|
-
if (!(typeof FormData !== 'undefined' && mediaContent instanceof FormData)) {
|
375
|
-
_context4.next = 9;
|
376
|
-
break;
|
377
|
-
}
|
378
|
-
|
379
|
-
log.debug('Sending media message as FormData', mediaContent, attributes);
|
380
|
-
_context4.next = 6;
|
381
|
-
return this.services.mcsClient.postFormData(mediaContent);
|
382
|
-
|
383
|
-
case 6:
|
384
|
-
media = _context4.sent;
|
385
|
-
_context4.next = 16;
|
386
|
-
break;
|
387
|
-
|
388
|
-
case 9:
|
389
|
-
log.debug('Sending media message as SendMediaOptions', mediaContent, attributes);
|
390
|
-
mediaOptions = mediaContent;
|
391
|
-
|
392
|
-
if (!(!mediaOptions.contentType || !mediaOptions.media)) {
|
393
|
-
_context4.next = 13;
|
394
|
-
break;
|
395
|
-
}
|
396
|
-
|
397
|
-
throw new Error('Media content <Conversation#SendMediaOptions> must contain non-empty contentType and media');
|
398
|
-
|
399
|
-
case 13:
|
400
|
-
_context4.next = 15;
|
401
|
-
return this.services.mcsClient.post(mediaOptions.contentType, mediaOptions.media);
|
402
|
-
|
403
|
-
case 15:
|
404
|
-
media = _context4.sent;
|
405
|
-
|
406
|
-
case 16:
|
407
|
-
return _context4.abrupt("return", this.services.session.addCommand('sendMediaMessage', {
|
408
|
-
channelSid: this.conversation.sid,
|
409
|
-
mediaSid: media.sid,
|
410
|
-
attributes: (0, _stringify2.default)(attributes)
|
411
|
-
}));
|
412
|
-
|
413
|
-
case 17:
|
414
|
-
case "end":
|
415
|
-
return _context4.stop();
|
416
|
-
}
|
417
|
-
}
|
418
|
-
}, _callee4, this);
|
419
|
-
}));
|
420
|
-
|
421
|
-
function sendMedia(_x5) {
|
422
|
-
return _ref6.apply(this, arguments);
|
423
|
-
}
|
424
|
-
|
425
|
-
return sendMedia;
|
426
|
-
}()
|
427
|
-
/**
|
428
|
-
* Returns messages from conversation using paginator interface
|
429
|
-
* @param {Number} [pageSize] Number of messages to return in single chunk. By default it's 30.
|
430
|
-
* @param {String} [anchor] Most early message id which is already known, or 'end' by default
|
431
|
-
* @param {String} [direction] Pagination order 'backwards' or 'forward', 'forward' by default
|
432
|
-
* @returns {Promise<Paginator<Message>>} last page of messages by default
|
433
|
-
*/
|
434
|
-
|
435
|
-
}, {
|
436
|
-
key: "getMessages",
|
437
|
-
value: function getMessages(pageSize, anchor, direction) {
|
438
|
-
anchor = typeof anchor !== 'undefined' ? anchor : 'end';
|
439
|
-
direction = direction || 'backwards';
|
440
|
-
return this._getMessages(pageSize, anchor, direction);
|
441
|
-
}
|
442
|
-
}, {
|
443
|
-
key: "wrapPaginator",
|
444
|
-
value: function wrapPaginator(order, page, op) {
|
445
|
-
var _this3 = this;
|
446
|
-
|
447
|
-
// We should swap next and prev page here, because of misfit of Sync and Chat paging conceptions
|
448
|
-
var shouldReverse = order === 'desc';
|
449
|
-
var np = function np() {
|
450
|
-
return page.nextPage().then(function (x) {
|
451
|
-
return _this3.wrapPaginator(order, x, op);
|
452
|
-
});
|
453
|
-
};
|
454
|
-
var pp = function pp() {
|
455
|
-
return page.prevPage().then(function (x) {
|
456
|
-
return _this3.wrapPaginator(order, x, op);
|
457
|
-
});
|
458
|
-
};
|
459
|
-
return op(page.items).then(function (items) {
|
460
|
-
return {
|
461
|
-
items: items.sort(function (x, y) {
|
462
|
-
return x.index - y.index;
|
463
|
-
}),
|
464
|
-
hasPrevPage: shouldReverse ? page.hasNextPage : page.hasPrevPage,
|
465
|
-
hasNextPage: shouldReverse ? page.hasPrevPage : page.hasNextPage,
|
466
|
-
prevPage: shouldReverse ? np : pp,
|
467
|
-
nextPage: shouldReverse ? pp : np
|
468
|
-
};
|
469
|
-
});
|
470
|
-
}
|
471
|
-
}, {
|
472
|
-
key: "_upsertMessage",
|
473
|
-
value: function _upsertMessage(index, value) {
|
474
|
-
var _this4 = this;
|
475
|
-
|
476
|
-
var cachedMessage = this.messagesByIndex.get(index);
|
477
|
-
if (cachedMessage) {
|
478
|
-
return cachedMessage;
|
479
|
-
}
|
480
|
-
var message = new message_1.Message(this.conversation, this.services, index, value);
|
481
|
-
this.messagesByIndex.set(message.index, message);
|
482
|
-
message.on('updated', function (args) {
|
483
|
-
return _this4.emit('messageUpdated', args);
|
484
|
-
});
|
485
|
-
return message;
|
486
|
-
}
|
487
|
-
/**
|
488
|
-
* Returns last messages from conversation
|
489
|
-
* @param {Number} [pageSize] Number of messages to return in single chunk. By default it's 30.
|
490
|
-
* @param {String} [anchor] Most early message id which is already known, or 'end' by default
|
491
|
-
* @param {String} [direction] Pagination order 'backwards' or 'forward', or 'forward' by default
|
492
|
-
* @returns {Promise<SyncPaginator<Message>>} last page of messages by default
|
493
|
-
* @private
|
494
|
-
*/
|
495
|
-
|
496
|
-
}, {
|
497
|
-
key: "_getMessages",
|
498
|
-
value: function _getMessages(pageSize, anchor, direction) {
|
499
|
-
var _this5 = this;
|
500
|
-
|
501
|
-
anchor = typeof anchor !== 'undefined' ? anchor : 'end';
|
502
|
-
pageSize = pageSize || 30;
|
503
|
-
var order = direction === 'backwards' ? 'desc' : 'asc';
|
504
|
-
return this.messagesListPromise.then(function (messagesList) {
|
505
|
-
return messagesList.getItems({
|
506
|
-
from: anchor !== 'end' ? anchor : void 0,
|
507
|
-
pageSize: pageSize,
|
508
|
-
order: order
|
509
|
-
});
|
510
|
-
}).then(function (page) {
|
511
|
-
return _this5.wrapPaginator(order, page, function (items) {
|
512
|
-
return _promise2.default.all(items.map(function (item) {
|
513
|
-
return _this5._upsertMessage(item.index, item.data);
|
514
|
-
}));
|
515
|
-
});
|
516
|
-
});
|
517
|
-
}
|
518
|
-
}]);
|
519
|
-
return Messages;
|
520
|
-
}(events_1.EventEmitter);
|
521
|
-
|
522
|
-
exports.Messages = Messages;
|