@webex/plugin-messages 3.0.0-beta.4 → 3.0.0-beta.400
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -6
- package/dist/index.js +2 -8
- package/dist/index.js.map +1 -1
- package/dist/messages.js +12 -54
- package/dist/messages.js.map +1 -1
- package/package.json +14 -14
- package/src/messages.js +47 -54
- package/test/integration/spec/messages.js +222 -183
package/README.md
CHANGED
|
@@ -29,15 +29,12 @@ npm install --save @webex/plugin-messages
|
|
|
29
29
|
## Usage
|
|
30
30
|
|
|
31
31
|
```js
|
|
32
|
-
|
|
33
32
|
const Webex = require('webex');
|
|
34
33
|
|
|
35
34
|
const webex = Webex.init();
|
|
36
|
-
webex.messages.get(id)
|
|
37
|
-
.
|
|
38
|
-
|
|
39
|
-
})
|
|
40
|
-
|
|
35
|
+
webex.messages.get(id).then((message) => {
|
|
36
|
+
console.log(message);
|
|
37
|
+
});
|
|
41
38
|
```
|
|
42
39
|
|
|
43
40
|
## Maintainers
|
package/dist/index.js
CHANGED
|
@@ -1,27 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
4
|
-
|
|
5
4
|
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
|
6
|
-
|
|
7
5
|
_Object$defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
|
-
|
|
11
8
|
exports.default = void 0;
|
|
12
|
-
|
|
13
9
|
require("@webex/internal-plugin-conversation");
|
|
14
|
-
|
|
15
10
|
require("@webex/internal-plugin-mercury");
|
|
16
|
-
|
|
17
11
|
var _webexCore = require("@webex/webex-core");
|
|
18
|
-
|
|
19
12
|
var _messages = _interopRequireDefault(require("./messages"));
|
|
20
|
-
|
|
21
13
|
/*!
|
|
22
14
|
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
23
15
|
*/
|
|
16
|
+
|
|
24
17
|
// decrypt mercury activities
|
|
18
|
+
|
|
25
19
|
(0, _webexCore.registerPlugin)('messages', _messages.default);
|
|
26
20
|
var _default = _messages.default;
|
|
27
21
|
exports.default = _default;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["registerPlugin","Messages"],"sources":["index.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport '@webex/internal-plugin-conversation'; // decrypt mercury activities\nimport '@webex/internal-plugin-mercury';\n\nimport {registerPlugin} from '@webex/webex-core';\n\nimport Messages from './messages';\n\nregisterPlugin('messages', Messages);\n\nexport default Messages;\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["registerPlugin","Messages"],"sources":["index.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport '@webex/internal-plugin-conversation'; // decrypt mercury activities\nimport '@webex/internal-plugin-mercury';\n\nimport {registerPlugin} from '@webex/webex-core';\n\nimport Messages from './messages';\n\nregisterPlugin('messages', Messages);\n\nexport default Messages;\n"],"mappings":";;;;;;;;AAIA;AACA;AAEA;AAEA;AATA;AACA;AACA;;AAE8C;;AAO9C,IAAAA,yBAAc,EAAC,UAAU,EAAEC,iBAAQ,CAAC;AAAC,eAEtBA,iBAAQ;AAAA"}
|
package/dist/messages.js
CHANGED
|
@@ -1,52 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _Object$keys = require("@babel/runtime-corejs2/core-js/object/keys");
|
|
4
|
-
|
|
5
4
|
var _Object$getOwnPropertySymbols = require("@babel/runtime-corejs2/core-js/object/get-own-property-symbols");
|
|
6
|
-
|
|
7
5
|
var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptor");
|
|
8
|
-
|
|
9
6
|
var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptors");
|
|
10
|
-
|
|
11
7
|
var _Object$defineProperties = require("@babel/runtime-corejs2/core-js/object/define-properties");
|
|
12
|
-
|
|
13
8
|
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
14
|
-
|
|
15
9
|
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
|
16
|
-
|
|
17
10
|
_Object$defineProperty(exports, "__esModule", {
|
|
18
11
|
value: true
|
|
19
12
|
});
|
|
20
|
-
|
|
21
13
|
exports.default = void 0;
|
|
22
|
-
|
|
23
14
|
var _apply = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/reflect/apply"));
|
|
24
|
-
|
|
25
15
|
var _deleteProperty = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/reflect/delete-property"));
|
|
26
|
-
|
|
27
16
|
var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
|
|
28
|
-
|
|
29
17
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty"));
|
|
30
|
-
|
|
31
18
|
var _isArray2 = _interopRequireDefault(require("lodash/isArray"));
|
|
32
|
-
|
|
33
19
|
var _cloneDeep2 = _interopRequireDefault(require("lodash/cloneDeep"));
|
|
34
|
-
|
|
35
20
|
var _common = require("@webex/common");
|
|
36
|
-
|
|
37
21
|
var _webexCore = require("@webex/webex-core");
|
|
38
|
-
|
|
39
22
|
var _verbToType;
|
|
40
|
-
|
|
41
23
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
42
|
-
|
|
43
24
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
44
|
-
|
|
45
25
|
var verbToType = (_verbToType = {}, (0, _defineProperty2.default)(_verbToType, _common.SDK_EVENT.INTERNAL.ACTIVITY_VERB.SHARE, _common.SDK_EVENT.EXTERNAL.EVENT_TYPE.CREATED), (0, _defineProperty2.default)(_verbToType, _common.SDK_EVENT.INTERNAL.ACTIVITY_VERB.POST, _common.SDK_EVENT.EXTERNAL.EVENT_TYPE.CREATED), (0, _defineProperty2.default)(_verbToType, _common.SDK_EVENT.INTERNAL.ACTIVITY_VERB.DELETE, _common.SDK_EVENT.EXTERNAL.EVENT_TYPE.DELETED), _verbToType);
|
|
46
|
-
|
|
47
26
|
var getRoomType = function getRoomType(roomTags) {
|
|
48
27
|
return roomTags.includes(_common.SDK_EVENT.INTERNAL.ACTIVITY_TAG.ONE_ON_ONE) ? _common.SDK_EVENT.EXTERNAL.SPACE_TYPE.DIRECT : _common.SDK_EVENT.EXTERNAL.SPACE_TYPE.GROUP;
|
|
49
28
|
};
|
|
29
|
+
|
|
50
30
|
/**
|
|
51
31
|
* @typedef {Object} MessageObject
|
|
52
32
|
* @property {string} id - (server generated) Unique identifier for the message
|
|
@@ -69,8 +49,6 @@ var getRoomType = function getRoomType(roomTags) {
|
|
|
69
49
|
* for a list of supported media types.
|
|
70
50
|
* @class
|
|
71
51
|
*/
|
|
72
|
-
|
|
73
|
-
|
|
74
52
|
var Messages = _webexCore.WebexPlugin.extend({
|
|
75
53
|
/**
|
|
76
54
|
* Initializer used to generate Messages
|
|
@@ -84,10 +62,8 @@ var Messages = _webexCore.WebexPlugin.extend({
|
|
|
84
62
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
85
63
|
args[_key] = arguments[_key];
|
|
86
64
|
}
|
|
87
|
-
|
|
88
65
|
(0, _apply.default)(_webexCore.WebexPlugin.prototype.initialize, this, args);
|
|
89
66
|
},
|
|
90
|
-
|
|
91
67
|
/**
|
|
92
68
|
* Register to listen for incoming messages events
|
|
93
69
|
* This is an alternate approach to registering for messages webhooks.
|
|
@@ -123,11 +99,11 @@ var Messages = _webexCore.WebexPlugin.extend({
|
|
|
123
99
|
*/
|
|
124
100
|
listen: function listen() {
|
|
125
101
|
var _this = this;
|
|
126
|
-
|
|
127
102
|
// Create a common envelope that we will wrap all events in
|
|
128
103
|
return (0, _common.createEventEnvelope)(this.webex, _common.SDK_EVENT.EXTERNAL.RESOURCE.MESSAGES).then(function (envelope) {
|
|
129
|
-
_this.eventEnvelope = envelope;
|
|
104
|
+
_this.eventEnvelope = envelope;
|
|
130
105
|
|
|
106
|
+
// Register to listen to events
|
|
131
107
|
return _this.webex.internal.mercury.connect().then(function () {
|
|
132
108
|
_this.listenTo(_this.webex.internal.mercury, _common.SDK_EVENT.INTERNAL.WEBEX_ACTIVITY, function (event) {
|
|
133
109
|
return _this.onWebexApiEvent(event);
|
|
@@ -135,7 +111,6 @@ var Messages = _webexCore.WebexPlugin.extend({
|
|
|
135
111
|
});
|
|
136
112
|
});
|
|
137
113
|
},
|
|
138
|
-
|
|
139
114
|
/**
|
|
140
115
|
* Post a new message and/or media content into a room.
|
|
141
116
|
* @instance
|
|
@@ -163,19 +138,16 @@ var Messages = _webexCore.WebexPlugin.extend({
|
|
|
163
138
|
*/
|
|
164
139
|
create: function create(message) {
|
|
165
140
|
var key = 'body';
|
|
166
|
-
|
|
167
141
|
if (message.file) {
|
|
168
142
|
this.logger.warn('Supplying a single `file` property is deprecated; please supply a `files` array');
|
|
169
143
|
message.files = [message.file];
|
|
170
144
|
(0, _deleteProperty.default)(message, 'file');
|
|
171
145
|
}
|
|
172
|
-
|
|
173
146
|
if ((0, _isArray2.default)(message.files) && message.files.reduce(function (type, file) {
|
|
174
147
|
return type || typeof file !== 'string';
|
|
175
148
|
}, false)) {
|
|
176
149
|
key = 'formData';
|
|
177
150
|
}
|
|
178
|
-
|
|
179
151
|
var options = (0, _defineProperty2.default)({
|
|
180
152
|
method: 'POST',
|
|
181
153
|
service: 'hydra',
|
|
@@ -185,7 +157,6 @@ var Messages = _webexCore.WebexPlugin.extend({
|
|
|
185
157
|
return res.body;
|
|
186
158
|
});
|
|
187
159
|
},
|
|
188
|
-
|
|
189
160
|
/**
|
|
190
161
|
* Returns a single message.
|
|
191
162
|
* @instance
|
|
@@ -221,7 +192,6 @@ var Messages = _webexCore.WebexPlugin.extend({
|
|
|
221
192
|
return res.body.items || res.body;
|
|
222
193
|
});
|
|
223
194
|
},
|
|
224
|
-
|
|
225
195
|
/**
|
|
226
196
|
* Returns a list of messages. In most cases the results will only contain
|
|
227
197
|
* messages posted in rooms that the authenticated user is a member of.
|
|
@@ -263,7 +233,6 @@ var Messages = _webexCore.WebexPlugin.extend({
|
|
|
263
233
|
*/
|
|
264
234
|
list: function list(options) {
|
|
265
235
|
var _this2 = this;
|
|
266
|
-
|
|
267
236
|
return this.request({
|
|
268
237
|
service: 'hydra',
|
|
269
238
|
resource: 'messages',
|
|
@@ -272,7 +241,6 @@ var Messages = _webexCore.WebexPlugin.extend({
|
|
|
272
241
|
return new _webexCore.Page(res, _this2.webex);
|
|
273
242
|
});
|
|
274
243
|
},
|
|
275
|
-
|
|
276
244
|
/**
|
|
277
245
|
* Deletes a single message. Deleting a message will notify all members of the
|
|
278
246
|
* room that the authenticated user deleted the message. Generally, users can
|
|
@@ -325,11 +293,9 @@ var Messages = _webexCore.WebexPlugin.extend({
|
|
|
325
293
|
if (res.statusCode === 204) {
|
|
326
294
|
return undefined;
|
|
327
295
|
}
|
|
328
|
-
|
|
329
296
|
return res.body;
|
|
330
297
|
});
|
|
331
298
|
},
|
|
332
|
-
|
|
333
299
|
/**
|
|
334
300
|
* Curry the 'trigger' method
|
|
335
301
|
* @private
|
|
@@ -339,12 +305,10 @@ var Messages = _webexCore.WebexPlugin.extend({
|
|
|
339
305
|
*/
|
|
340
306
|
fire: function fire(type) {
|
|
341
307
|
var _this3 = this;
|
|
342
|
-
|
|
343
308
|
return function (event) {
|
|
344
309
|
return _this3.trigger(type, event);
|
|
345
310
|
};
|
|
346
311
|
},
|
|
347
|
-
|
|
348
312
|
/**
|
|
349
313
|
* This function is called when an internal membership events fires,
|
|
350
314
|
* if the user registered for these events with the listen() function.
|
|
@@ -359,14 +323,11 @@ var Messages = _webexCore.WebexPlugin.extend({
|
|
|
359
323
|
onWebexApiEvent: function onWebexApiEvent(_ref) {
|
|
360
324
|
var activity = _ref.data.activity;
|
|
361
325
|
var type = verbToType[activity.verb];
|
|
362
|
-
|
|
363
326
|
if (!type) {
|
|
364
327
|
return;
|
|
365
328
|
}
|
|
366
|
-
|
|
367
329
|
this.getMessageEvent(activity, type).then(this.fire(type));
|
|
368
330
|
},
|
|
369
|
-
|
|
370
331
|
/**
|
|
371
332
|
* Constructs the data object for an event on the messages resource,
|
|
372
333
|
* adhering to Hydra's Webhook data structure messages.
|
|
@@ -379,18 +340,17 @@ var Messages = _webexCore.WebexPlugin.extend({
|
|
|
379
340
|
*/
|
|
380
341
|
getMessageEvent: function getMessageEvent(activity, type) {
|
|
381
342
|
var id = activity.id,
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
343
|
+
_activity$actor = activity.actor,
|
|
344
|
+
actorId = _activity$actor.entryUUID,
|
|
345
|
+
emailAddress = _activity$actor.emailAddress,
|
|
346
|
+
objectId = activity.object.id,
|
|
347
|
+
_activity$target = activity.target,
|
|
348
|
+
roomId = _activity$target.id,
|
|
349
|
+
roomUrl = _activity$target.url,
|
|
350
|
+
roomTags = _activity$target.tags;
|
|
390
351
|
var cluster = (0, _common.getHydraClusterString)(this.webex, roomUrl);
|
|
391
352
|
var combinedEvent = (0, _cloneDeep2.default)(this.eventEnvelope);
|
|
392
353
|
combinedEvent.event = type;
|
|
393
|
-
|
|
394
354
|
if (type === _common.SDK_EVENT.EXTERNAL.EVENT_TYPE.DELETED) {
|
|
395
355
|
// Cannot fetch since the message is deleted
|
|
396
356
|
// Convert the Mercury event to a Hydra event
|
|
@@ -406,7 +366,6 @@ var Messages = _webexCore.WebexPlugin.extend({
|
|
|
406
366
|
}
|
|
407
367
|
}));
|
|
408
368
|
}
|
|
409
|
-
|
|
410
369
|
return this.get((0, _common.buildHydraMessageId)(id, cluster)).then(function (data) {
|
|
411
370
|
return _objectSpread(_objectSpread({}, combinedEvent), {}, {
|
|
412
371
|
actorId: data.personId,
|
|
@@ -414,9 +373,8 @@ var Messages = _webexCore.WebexPlugin.extend({
|
|
|
414
373
|
});
|
|
415
374
|
});
|
|
416
375
|
},
|
|
417
|
-
version: "3.0.0-beta.
|
|
376
|
+
version: "3.0.0-beta.400"
|
|
418
377
|
});
|
|
419
|
-
|
|
420
378
|
var _default = Messages;
|
|
421
379
|
exports.default = _default;
|
|
422
380
|
//# sourceMappingURL=messages.js.map
|
package/dist/messages.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["verbToType","SDK_EVENT","INTERNAL","ACTIVITY_VERB","SHARE","EXTERNAL","EVENT_TYPE","CREATED","POST","DELETE","DELETED","getRoomType","roomTags","includes","ACTIVITY_TAG","ONE_ON_ONE","SPACE_TYPE","DIRECT","GROUP","Messages","WebexPlugin","extend","initialize","args","prototype","listen","createEventEnvelope","webex","RESOURCE","MESSAGES","then","envelope","eventEnvelope","internal","mercury","connect","listenTo","WEBEX_ACTIVITY","event","onWebexApiEvent","create","message","key","file","logger","warn","files","reduce","type","options","method","service","resource","request","res","body","get","id","items","list","qs","Page","remove","statusCode","undefined","fire","trigger","activity","data","verb","getMessageEvent","actor","actorId","entryUUID","emailAddress","objectId","object","target","roomId","roomUrl","url","tags","cluster","getHydraClusterString","combinedEvent","personId","buildHydraPersonId","resolve","buildHydraMessageId","personEmail","buildHydraRoomId","roomType"],"sources":["messages.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {\n SDK_EVENT,\n buildHydraMessageId,\n buildHydraPersonId,\n buildHydraRoomId,\n createEventEnvelope,\n getHydraClusterString\n} from '@webex/common';\nimport {\n Page,\n WebexPlugin\n} from '@webex/webex-core';\nimport {cloneDeep, isArray} from 'lodash';\n\nconst verbToType = {\n [SDK_EVENT.INTERNAL.ACTIVITY_VERB.SHARE]:\n SDK_EVENT.EXTERNAL.EVENT_TYPE.CREATED,\n [SDK_EVENT.INTERNAL.ACTIVITY_VERB.POST]:\n SDK_EVENT.EXTERNAL.EVENT_TYPE.CREATED,\n [SDK_EVENT.INTERNAL.ACTIVITY_VERB.DELETE]:\n SDK_EVENT.EXTERNAL.EVENT_TYPE.DELETED\n};\n\nconst getRoomType = (roomTags) =>\n (roomTags.includes(SDK_EVENT.INTERNAL.ACTIVITY_TAG.ONE_ON_ONE) ?\n SDK_EVENT.EXTERNAL.SPACE_TYPE.DIRECT :\n SDK_EVENT.EXTERNAL.SPACE_TYPE.GROUP);\n\n/**\n * @typedef {Object} MessageObject\n * @property {string} id - (server generated) Unique identifier for the message\n * @property {string} personId - The ID for the author of the message\n * @property {email} personEmail - The email for the author of the message\n * @property {string} roomId - The ID for the room of the message\n * @property {string} text - The message posted to the room in plain text\n * @property {string} markdown - The message posted to the room in markdown\n * @property {Array<string>} files - The source URL(s) for the message attachment(s).\n * See the {@link https://developer.webex.com/docs/api/basics#message-attachments|Message Attachments}\n * Guide for a list of supported media types.\n * @property {isoDate} created - (server generated) The date and time that the message was created\n */\n\n/**\n * Messages are how people communicate in rooms. Each message timestamped and\n * represented in Webex as a distinct block of content. Messages can contain\n * plain text and a single file attachment. See the\n * {@link https://developer.webex.com/docs/api/basics#message-attachments|Message Attachments} Guide\n * for a list of supported media types.\n * @class\n */\nconst Messages = WebexPlugin.extend({\n /**\n * Initializer used to generate Messages\n * as a plugin wrapped around the provided arguments.\n * @private\n * @see WebexPlugin.initialize\n * @param {...any} args\n * @returns {undefined}\n */\n initialize(...args) {\n Reflect.apply(WebexPlugin.prototype.initialize, this, args);\n },\n\n /**\n * Register to listen for incoming messages events\n * This is an alternate approach to registering for messages webhooks.\n * The events passed to any registered handlers will be similar to the webhook JSON,\n * but will omit webhook specific fields such as name, secret, url, etc.\n * The messages.listen() event objects can also include additional fields not\n * available in the webhook's JSON payload: `text`, `markdown`, and `files`.\n * These fields are available when their details are included in the web socket's\n * `activity` object. Retrieving other fields, such as the `html` field,\n * will require a manual request to get the corresponding message object.\n * To utilize the `listen()` method, the authorization token used\n * will need to have `spark:all` and `spark:kms` scopes enabled.\n * Note that by configuring your application to enable or disable `spark:all`\n * via its configuration page will also enable or disable `spark:kms`.\n * See the <a href=\"https://webex.github.io/webex-js-sdk/samples/browser-socket/\">Sample App</a>\n * for more details.\n * @instance\n * @memberof Messages\n * @returns {Promise}\n * @example\n * webex.messages.listen()\n * .then(() => {\n * console.log('listening to message events');\n * webex.messages.on('created', (event) => console.log(`Got a message:created event:\\n${event}`));\n * webex.messages.on('deleted', (event) => console.log(`Got a message:deleted event:\\n${event}`));\n * })\n * .catch((e) => console.error(`Unable to register for message events: ${e}`));\n * // Some app logic...\n * // When it is time to cleanup\n * webex.messages.stopListening();\n * webex.messages.off('created');\n * webex.messages.off('deleted');\n */\n listen() {\n // Create a common envelope that we will wrap all events in\n return createEventEnvelope(this.webex,\n SDK_EVENT.EXTERNAL.RESOURCE.MESSAGES)\n .then((envelope) => {\n this.eventEnvelope = envelope;\n\n // Register to listen to events\n return this.webex.internal.mercury.connect().then(() => {\n this.listenTo(this.webex.internal.mercury,\n SDK_EVENT.INTERNAL.WEBEX_ACTIVITY,\n (event) => this.onWebexApiEvent(event));\n });\n });\n },\n\n /**\n * Post a new message and/or media content into a room.\n * @instance\n * @memberof Messages\n * @param {MessageObject} message\n * @returns {Promise<MessageObject>}\n * @example\n * webex.rooms.create({title: 'Create Message Example'})\n * .then(function(room) {\n * return webex.messages.create({\n * text: 'Howdy!',\n * roomId: room.id\n * });\n * })\n * .then(function(message) {\n * var assert = require('assert');\n * assert(message.id);\n * assert(message.personId);\n * assert(message.personEmail);\n * assert(message.roomId);\n * assert(message.created);\n * return 'success';\n * });\n * // => success\n */\n create(message) {\n let key = 'body';\n\n if (message.file) {\n this.logger.warn('Supplying a single `file` property is deprecated; please supply a `files` array');\n message.files = [message.file];\n Reflect.deleteProperty(message, 'file');\n }\n\n if (isArray(message.files) && message.files.reduce((type, file) => type || typeof file !== 'string', false)) {\n key = 'formData';\n }\n\n const options = {\n method: 'POST',\n service: 'hydra',\n resource: 'messages',\n [key]: message\n };\n\n return this.request(options)\n .then((res) => res.body);\n },\n\n /**\n * Returns a single message.\n * @instance\n * @memberof Messages\n * @param {RoomObject|string} message\n * @returns {Promise<MessageObject>}\n * @example\n * var message;\n * webex.rooms.create({title: 'Get Message Example'})\n * .then(function(room) {\n * return webex.messages.create({\n * text: 'Howdy!',\n * roomId: room.id\n * });\n * })\n * .then(function(m) {\n * message = m;\n * return webex.messages.get(message.id);\n * })\n * .then(function(message2) {\n * var assert = require('assert');\n * assert.deepEqual(message2, message);\n * return 'success';\n * });\n * // => success\n */\n get(message) {\n const id = message.id || message;\n\n return this.request({\n service: 'hydra',\n resource: `messages/${id}`\n })\n .then((res) => res.body.items || res.body);\n },\n\n /**\n * Returns a list of messages. In most cases the results will only contain\n * messages posted in rooms that the authenticated user is a member of.\n * @instance\n * @memberof Messages\n * @param {Object} options\n * @param {string} options.roomId\n * @param {number} options.max\n * @returns {Promise<Page<MessageObject>>}\n * @example\n * var message1, message2, room;\n * webex.rooms.create({title: 'List Messages Example'})\n * .then(function(r) {\n * room = r;\n * return webex.messages.create({\n * text: 'Howdy!',\n * roomId: room.id\n * });\n * })\n * .then(function(m) {\n * message1 = m;\n * return webex.messages.create({\n * text: 'How are you?',\n * roomId: room.id\n * });\n * })\n * .then(function(m) {\n * message2 = m;\n * return webex.messages.list({roomId: room.id});\n * })\n * .then(function(messages) {\n * var assert = require('assert');\n * assert.equal(messages.length, 2);\n * assert.equal(messages.items[0].id, message2.id);\n * assert.equal(messages.items[1].id, message1.id);\n * return 'success';\n * });\n * // => success\n */\n list(options) {\n return this.request({\n service: 'hydra',\n resource: 'messages',\n qs: options\n })\n .then((res) => new Page(res, this.webex));\n },\n\n /**\n * Deletes a single message. Deleting a message will notify all members of the\n * room that the authenticated user deleted the message. Generally, users can\n * only delete their own messages except for the case of Moderated Rooms and\n * Org Administrators.\n * @instance\n * @memberof Messages\n * @param {MessageObject|uuid} message\n * @returns {Promise}}\n * @example\n * var message1, room;\n * webex.rooms.create({title: 'Messages Example'})\n * .then(function(r) {\n * room = r;\n * return webex.messages.create({\n * text: 'Howdy!',\n * roomId: room.id\n * });\n * })\n * .then(function(m) {\n * message1 = m;\n * return webex.messages.create({\n * text: 'How are you?',\n * roomId: room.id\n * });\n * })\n * .then(function() {\n * return webex.messages.remove(message1);\n * })\n * .then(function() {\n * return webex.messages.list({roomId: room.id});\n * })\n * .then(function(messages) {\n * var assert = require('assert');\n * assert.equal(messages.items.length, 1);\n * assert(messages.items[0].id !== message1.id);\n * return 'success';\n * });\n * // => success\n */\n remove(message) {\n const id = message.id || message;\n\n return this.request({\n method: 'DELETE',\n service: 'hydra',\n resource: `messages/${id}`\n })\n .then((res) => {\n // Firefox has some issues with 204s and/or DELETE. This should move to\n // http-core\n if (res.statusCode === 204) {\n return undefined;\n }\n\n return res.body;\n });\n },\n\n /**\n * Curry the 'trigger' method\n * @private\n * @memberof Messages\n * @param {string} type the type of event to fire\n * @returns {function} takes event and triggers it\n */\n fire(type) {\n return (event) => this.trigger(type, event);\n },\n\n /**\n * This function is called when an internal membership events fires,\n * if the user registered for these events with the listen() function.\n * External users of the SDK should not call this function\n * @private\n * @memberof Messages\n * @param {Object} event\n * @param {Object} event.data contains the data of the event\n * @param {Object} event.data.activity the activity that triggered the event\n * @returns {void}\n */\n onWebexApiEvent({data: {activity}}) {\n const type = verbToType[activity.verb];\n\n if (!type) {\n return;\n }\n\n this.getMessageEvent(activity, type)\n .then(this.fire(type));\n },\n\n /**\n * Constructs the data object for an event on the messages resource,\n * adhering to Hydra's Webhook data structure messages.\n * External users of the SDK should not call this function\n * @private\n * @memberof Messages\n * @param {Object} activity from mercury\n * @param {String} type the type of event\n * @returns {Object} constructed event\n */\n getMessageEvent(activity, type) {\n const {\n id,\n actor: {entryUUID: actorId, emailAddress},\n object: {id: objectId},\n target: {id: roomId, url: roomUrl, tags: roomTags}\n } = activity;\n\n const cluster = getHydraClusterString(this.webex, roomUrl);\n const combinedEvent = cloneDeep(this.eventEnvelope);\n\n combinedEvent.event = type;\n if (type === SDK_EVENT.EXTERNAL.EVENT_TYPE.DELETED) {\n // Cannot fetch since the message is deleted\n // Convert the Mercury event to a Hydra event\n const personId = buildHydraPersonId(actorId, cluster);\n\n return Promise.resolve({\n ...combinedEvent,\n actorId: personId,\n data: {\n id: buildHydraMessageId(objectId, cluster),\n personEmail: emailAddress || actorId,\n personId,\n roomId: buildHydraRoomId(roomId, cluster),\n roomType: getRoomType(roomTags)\n }\n });\n }\n\n return this.get(buildHydraMessageId(id, cluster))\n .then((data) => ({\n ...combinedEvent,\n actorId: data.personId,\n data\n }));\n }\n});\n\nexport default Messages;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA;;AAQA;;;;;;;;AAMA,IAAMA,UAAU,iEACbC,iBAAA,CAAUC,QAAV,CAAmBC,aAAnB,CAAiCC,KADpB,EAEZH,iBAAA,CAAUI,QAAV,CAAmBC,UAAnB,CAA8BC,OAFlB,8CAGbN,iBAAA,CAAUC,QAAV,CAAmBC,aAAnB,CAAiCK,IAHpB,EAIZP,iBAAA,CAAUI,QAAV,CAAmBC,UAAnB,CAA8BC,OAJlB,8CAKbN,iBAAA,CAAUC,QAAV,CAAmBC,a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AJ3C,oBAIqCqE,IAJrC;IAOA,IAAMC,OAAO,GAAG,IAAAC,6BAAA,EAAsB,KAAKxD,KAA3B,EAAkCoD,OAAlC,CAAhB;IACA,IAAMK,aAAa,GAAG,yBAAU,KAAKpD,aAAf,CAAtB;IAEAoD,aAAa,CAAC9C,KAAd,GAAsBU,IAAtB;;IACA,IAAIA,IAAI,KAAK/C,iBAAA,CAAUI,QAAV,CAAmBC,UAAnB,CAA8BI,OAA3C,EAAoD;MAClD;MACA;MACA,IAAM2E,QAAQ,GAAG,IAAAC,0BAAA,EAAmBd,OAAnB,EAA4BU,OAA5B,CAAjB;MAEA,OAAO,iBAAQK,OAAR,iCACFH,aADE;QAELZ,OAAO,EAAEa,QAFJ;QAGLjB,IAAI,EAAE;UACJX,EAAE,EAAE,IAAA+B,2BAAA,EAAoBb,QAApB,EAA8BO,OAA9B,CADA;UAEJO,WAAW,EAAEf,YAAY,IAAIF,OAFzB;UAGJa,QAAQ,EAARA,QAHI;UAIJP,MAAM,EAAE,IAAAY,wBAAA,EAAiBZ,MAAjB,EAAyBI,OAAzB,CAJJ;UAKJS,QAAQ,EAAEhF,WAAW,CAACC,QAAD;QALjB;MAHD,GAAP;IAWD;;IAED,OAAO,KAAK4C,GAAL,CAAS,IAAAgC,2BAAA,EAAoB/B,EAApB,EAAwByB,OAAxB,CAAT,EACJpD,IADI,CACC,UAACsC,IAAD;MAAA,uCACDgB,aADC;QAEJZ,OAAO,EAAEJ,IAAI,CAACiB,QAFV;QAGJjB,IAAI,EAAJA;MAHI;IAAA,CADD,CAAP;EAMD,CA7UiC;EAAA;AAAA,CAAnB,CAAjB;;eAgVejD,Q"}
|
|
1
|
+
{"version":3,"names":["verbToType","SDK_EVENT","INTERNAL","ACTIVITY_VERB","SHARE","EXTERNAL","EVENT_TYPE","CREATED","POST","DELETE","DELETED","getRoomType","roomTags","includes","ACTIVITY_TAG","ONE_ON_ONE","SPACE_TYPE","DIRECT","GROUP","Messages","WebexPlugin","extend","initialize","args","prototype","listen","createEventEnvelope","webex","RESOURCE","MESSAGES","then","envelope","eventEnvelope","internal","mercury","connect","listenTo","WEBEX_ACTIVITY","event","onWebexApiEvent","create","message","key","file","logger","warn","files","reduce","type","options","method","service","resource","request","res","body","get","id","items","list","qs","Page","remove","statusCode","undefined","fire","trigger","activity","data","verb","getMessageEvent","actor","actorId","entryUUID","emailAddress","objectId","object","target","roomId","roomUrl","url","tags","cluster","getHydraClusterString","combinedEvent","personId","buildHydraPersonId","resolve","buildHydraMessageId","personEmail","buildHydraRoomId","roomType"],"sources":["messages.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {\n SDK_EVENT,\n buildHydraMessageId,\n buildHydraPersonId,\n buildHydraRoomId,\n createEventEnvelope,\n getHydraClusterString,\n} from '@webex/common';\nimport {Page, WebexPlugin} from '@webex/webex-core';\nimport {cloneDeep, isArray} from 'lodash';\n\nconst verbToType = {\n [SDK_EVENT.INTERNAL.ACTIVITY_VERB.SHARE]: SDK_EVENT.EXTERNAL.EVENT_TYPE.CREATED,\n [SDK_EVENT.INTERNAL.ACTIVITY_VERB.POST]: SDK_EVENT.EXTERNAL.EVENT_TYPE.CREATED,\n [SDK_EVENT.INTERNAL.ACTIVITY_VERB.DELETE]: SDK_EVENT.EXTERNAL.EVENT_TYPE.DELETED,\n};\n\nconst getRoomType = (roomTags) =>\n roomTags.includes(SDK_EVENT.INTERNAL.ACTIVITY_TAG.ONE_ON_ONE)\n ? SDK_EVENT.EXTERNAL.SPACE_TYPE.DIRECT\n : SDK_EVENT.EXTERNAL.SPACE_TYPE.GROUP;\n\n/**\n * @typedef {Object} MessageObject\n * @property {string} id - (server generated) Unique identifier for the message\n * @property {string} personId - The ID for the author of the message\n * @property {email} personEmail - The email for the author of the message\n * @property {string} roomId - The ID for the room of the message\n * @property {string} text - The message posted to the room in plain text\n * @property {string} markdown - The message posted to the room in markdown\n * @property {Array<string>} files - The source URL(s) for the message attachment(s).\n * See the {@link https://developer.webex.com/docs/api/basics#message-attachments|Message Attachments}\n * Guide for a list of supported media types.\n * @property {isoDate} created - (server generated) The date and time that the message was created\n */\n\n/**\n * Messages are how people communicate in rooms. Each message timestamped and\n * represented in Webex as a distinct block of content. Messages can contain\n * plain text and a single file attachment. See the\n * {@link https://developer.webex.com/docs/api/basics#message-attachments|Message Attachments} Guide\n * for a list of supported media types.\n * @class\n */\nconst Messages = WebexPlugin.extend({\n /**\n * Initializer used to generate Messages\n * as a plugin wrapped around the provided arguments.\n * @private\n * @see WebexPlugin.initialize\n * @param {...any} args\n * @returns {undefined}\n */\n initialize(...args) {\n Reflect.apply(WebexPlugin.prototype.initialize, this, args);\n },\n\n /**\n * Register to listen for incoming messages events\n * This is an alternate approach to registering for messages webhooks.\n * The events passed to any registered handlers will be similar to the webhook JSON,\n * but will omit webhook specific fields such as name, secret, url, etc.\n * The messages.listen() event objects can also include additional fields not\n * available in the webhook's JSON payload: `text`, `markdown`, and `files`.\n * These fields are available when their details are included in the web socket's\n * `activity` object. Retrieving other fields, such as the `html` field,\n * will require a manual request to get the corresponding message object.\n * To utilize the `listen()` method, the authorization token used\n * will need to have `spark:all` and `spark:kms` scopes enabled.\n * Note that by configuring your application to enable or disable `spark:all`\n * via its configuration page will also enable or disable `spark:kms`.\n * See the <a href=\"https://webex.github.io/webex-js-sdk/samples/browser-socket/\">Sample App</a>\n * for more details.\n * @instance\n * @memberof Messages\n * @returns {Promise}\n * @example\n * webex.messages.listen()\n * .then(() => {\n * console.log('listening to message events');\n * webex.messages.on('created', (event) => console.log(`Got a message:created event:\\n${event}`));\n * webex.messages.on('deleted', (event) => console.log(`Got a message:deleted event:\\n${event}`));\n * })\n * .catch((e) => console.error(`Unable to register for message events: ${e}`));\n * // Some app logic...\n * // When it is time to cleanup\n * webex.messages.stopListening();\n * webex.messages.off('created');\n * webex.messages.off('deleted');\n */\n listen() {\n // Create a common envelope that we will wrap all events in\n return createEventEnvelope(this.webex, SDK_EVENT.EXTERNAL.RESOURCE.MESSAGES).then(\n (envelope) => {\n this.eventEnvelope = envelope;\n\n // Register to listen to events\n return this.webex.internal.mercury.connect().then(() => {\n this.listenTo(this.webex.internal.mercury, SDK_EVENT.INTERNAL.WEBEX_ACTIVITY, (event) =>\n this.onWebexApiEvent(event)\n );\n });\n }\n );\n },\n\n /**\n * Post a new message and/or media content into a room.\n * @instance\n * @memberof Messages\n * @param {MessageObject} message\n * @returns {Promise<MessageObject>}\n * @example\n * webex.rooms.create({title: 'Create Message Example'})\n * .then(function(room) {\n * return webex.messages.create({\n * text: 'Howdy!',\n * roomId: room.id\n * });\n * })\n * .then(function(message) {\n * var assert = require('assert');\n * assert(message.id);\n * assert(message.personId);\n * assert(message.personEmail);\n * assert(message.roomId);\n * assert(message.created);\n * return 'success';\n * });\n * // => success\n */\n create(message) {\n let key = 'body';\n\n if (message.file) {\n this.logger.warn(\n 'Supplying a single `file` property is deprecated; please supply a `files` array'\n );\n message.files = [message.file];\n Reflect.deleteProperty(message, 'file');\n }\n\n if (\n isArray(message.files) &&\n message.files.reduce((type, file) => type || typeof file !== 'string', false)\n ) {\n key = 'formData';\n }\n\n const options = {\n method: 'POST',\n service: 'hydra',\n resource: 'messages',\n [key]: message,\n };\n\n return this.request(options).then((res) => res.body);\n },\n\n /**\n * Returns a single message.\n * @instance\n * @memberof Messages\n * @param {RoomObject|string} message\n * @returns {Promise<MessageObject>}\n * @example\n * var message;\n * webex.rooms.create({title: 'Get Message Example'})\n * .then(function(room) {\n * return webex.messages.create({\n * text: 'Howdy!',\n * roomId: room.id\n * });\n * })\n * .then(function(m) {\n * message = m;\n * return webex.messages.get(message.id);\n * })\n * .then(function(message2) {\n * var assert = require('assert');\n * assert.deepEqual(message2, message);\n * return 'success';\n * });\n * // => success\n */\n get(message) {\n const id = message.id || message;\n\n return this.request({\n service: 'hydra',\n resource: `messages/${id}`,\n }).then((res) => res.body.items || res.body);\n },\n\n /**\n * Returns a list of messages. In most cases the results will only contain\n * messages posted in rooms that the authenticated user is a member of.\n * @instance\n * @memberof Messages\n * @param {Object} options\n * @param {string} options.roomId\n * @param {number} options.max\n * @returns {Promise<Page<MessageObject>>}\n * @example\n * var message1, message2, room;\n * webex.rooms.create({title: 'List Messages Example'})\n * .then(function(r) {\n * room = r;\n * return webex.messages.create({\n * text: 'Howdy!',\n * roomId: room.id\n * });\n * })\n * .then(function(m) {\n * message1 = m;\n * return webex.messages.create({\n * text: 'How are you?',\n * roomId: room.id\n * });\n * })\n * .then(function(m) {\n * message2 = m;\n * return webex.messages.list({roomId: room.id});\n * })\n * .then(function(messages) {\n * var assert = require('assert');\n * assert.equal(messages.length, 2);\n * assert.equal(messages.items[0].id, message2.id);\n * assert.equal(messages.items[1].id, message1.id);\n * return 'success';\n * });\n * // => success\n */\n list(options) {\n return this.request({\n service: 'hydra',\n resource: 'messages',\n qs: options,\n }).then((res) => new Page(res, this.webex));\n },\n\n /**\n * Deletes a single message. Deleting a message will notify all members of the\n * room that the authenticated user deleted the message. Generally, users can\n * only delete their own messages except for the case of Moderated Rooms and\n * Org Administrators.\n * @instance\n * @memberof Messages\n * @param {MessageObject|uuid} message\n * @returns {Promise}}\n * @example\n * var message1, room;\n * webex.rooms.create({title: 'Messages Example'})\n * .then(function(r) {\n * room = r;\n * return webex.messages.create({\n * text: 'Howdy!',\n * roomId: room.id\n * });\n * })\n * .then(function(m) {\n * message1 = m;\n * return webex.messages.create({\n * text: 'How are you?',\n * roomId: room.id\n * });\n * })\n * .then(function() {\n * return webex.messages.remove(message1);\n * })\n * .then(function() {\n * return webex.messages.list({roomId: room.id});\n * })\n * .then(function(messages) {\n * var assert = require('assert');\n * assert.equal(messages.items.length, 1);\n * assert(messages.items[0].id !== message1.id);\n * return 'success';\n * });\n * // => success\n */\n remove(message) {\n const id = message.id || message;\n\n return this.request({\n method: 'DELETE',\n service: 'hydra',\n resource: `messages/${id}`,\n }).then((res) => {\n // Firefox has some issues with 204s and/or DELETE. This should move to\n // http-core\n if (res.statusCode === 204) {\n return undefined;\n }\n\n return res.body;\n });\n },\n\n /**\n * Curry the 'trigger' method\n * @private\n * @memberof Messages\n * @param {string} type the type of event to fire\n * @returns {function} takes event and triggers it\n */\n fire(type) {\n return (event) => this.trigger(type, event);\n },\n\n /**\n * This function is called when an internal membership events fires,\n * if the user registered for these events with the listen() function.\n * External users of the SDK should not call this function\n * @private\n * @memberof Messages\n * @param {Object} event\n * @param {Object} event.data contains the data of the event\n * @param {Object} event.data.activity the activity that triggered the event\n * @returns {void}\n */\n onWebexApiEvent({data: {activity}}) {\n const type = verbToType[activity.verb];\n\n if (!type) {\n return;\n }\n\n this.getMessageEvent(activity, type).then(this.fire(type));\n },\n\n /**\n * Constructs the data object for an event on the messages resource,\n * adhering to Hydra's Webhook data structure messages.\n * External users of the SDK should not call this function\n * @private\n * @memberof Messages\n * @param {Object} activity from mercury\n * @param {String} type the type of event\n * @returns {Object} constructed event\n */\n getMessageEvent(activity, type) {\n const {\n id,\n actor: {entryUUID: actorId, emailAddress},\n object: {id: objectId},\n target: {id: roomId, url: roomUrl, tags: roomTags},\n } = activity;\n\n const cluster = getHydraClusterString(this.webex, roomUrl);\n const combinedEvent = cloneDeep(this.eventEnvelope);\n\n combinedEvent.event = type;\n if (type === SDK_EVENT.EXTERNAL.EVENT_TYPE.DELETED) {\n // Cannot fetch since the message is deleted\n // Convert the Mercury event to a Hydra event\n const personId = buildHydraPersonId(actorId, cluster);\n\n return Promise.resolve({\n ...combinedEvent,\n actorId: personId,\n data: {\n id: buildHydraMessageId(objectId, cluster),\n personEmail: emailAddress || actorId,\n personId,\n roomId: buildHydraRoomId(roomId, cluster),\n roomType: getRoomType(roomTags),\n },\n });\n }\n\n return this.get(buildHydraMessageId(id, cluster)).then((data) => ({\n ...combinedEvent,\n actorId: data.personId,\n data,\n }));\n },\n});\n\nexport default Messages;\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAIA;AAQA;AAAoD;AAAA;AAAA;AAGpD,IAAMA,UAAU,iEACbC,iB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GAAG,CAACC,IAAI;IAAA,EAAC;EACtD,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEC,GAAG,eAACf,OAAO,EAAE;IACX,IAAMgB,EAAE,GAAGhB,OAAO,CAACgB,EAAE,IAAIhB,OAAO;IAEhC,OAAO,IAAI,CAACY,OAAO,CAAC;MAClBF,OAAO,EAAE,OAAO;MAChBC,QAAQ,qBAAcK,EAAE;IAC1B,CAAC,CAAC,CAAC3B,IAAI,CAAC,UAACwB,GAAG;MAAA,OAAKA,GAAG,CAACC,IAAI,CAACG,KAAK,IAAIJ,GAAG,CAACC,IAAI;IAAA,EAAC;EAC9C,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEI,IAAI,gBAACV,OAAO,EAAE;IAAA;IACZ,OAAO,IAAI,CAACI,OAAO,CAAC;MAClBF,OAAO,EAAE,OAAO;MAChBC,QAAQ,EAAE,UAAU;MACpBQ,EAAE,EAAEX;IACN,CAAC,CAAC,CAACnB,IAAI,CAAC,UAACwB,GAAG;MAAA,OAAK,IAAIO,eAAI,CAACP,GAAG,EAAE,MAAI,CAAC3B,KAAK,CAAC;IAAA,EAAC;EAC7C,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEmC,MAAM,kBAACrB,OAAO,EAAE;IACd,IAAMgB,EAAE,GAAGhB,O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"3.0.0-beta.400",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -20,22 +20,22 @@
|
|
|
20
20
|
]
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@webex/test-helper-chai": "3.0.0-beta.
|
|
24
|
-
"@webex/test-helper-file": "3.0.0-beta.
|
|
25
|
-
"@webex/test-helper-mocha": "3.0.0-beta.
|
|
26
|
-
"@webex/test-helper-test-users": "3.0.0-beta.
|
|
23
|
+
"@webex/test-helper-chai": "3.0.0-beta.400",
|
|
24
|
+
"@webex/test-helper-file": "3.0.0-beta.400",
|
|
25
|
+
"@webex/test-helper-mocha": "3.0.0-beta.400",
|
|
26
|
+
"@webex/test-helper-test-users": "3.0.0-beta.400",
|
|
27
27
|
"sinon": "^9.2.4"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@webex/common": "3.0.0-beta.
|
|
31
|
-
"@webex/internal-plugin-conversation": "3.0.0-beta.
|
|
32
|
-
"@webex/internal-plugin-device": "3.0.0-beta.
|
|
33
|
-
"@webex/internal-plugin-mercury": "3.0.0-beta.
|
|
34
|
-
"@webex/plugin-logger": "3.0.0-beta.
|
|
35
|
-
"@webex/plugin-messages": "3.0.0-beta.
|
|
36
|
-
"@webex/plugin-people": "3.0.0-beta.
|
|
37
|
-
"@webex/plugin-rooms": "3.0.0-beta.
|
|
38
|
-
"@webex/webex-core": "3.0.0-beta.
|
|
30
|
+
"@webex/common": "3.0.0-beta.400",
|
|
31
|
+
"@webex/internal-plugin-conversation": "3.0.0-beta.400",
|
|
32
|
+
"@webex/internal-plugin-device": "3.0.0-beta.400",
|
|
33
|
+
"@webex/internal-plugin-mercury": "3.0.0-beta.400",
|
|
34
|
+
"@webex/plugin-logger": "3.0.0-beta.400",
|
|
35
|
+
"@webex/plugin-messages": "3.0.0-beta.400",
|
|
36
|
+
"@webex/plugin-people": "3.0.0-beta.400",
|
|
37
|
+
"@webex/plugin-rooms": "3.0.0-beta.400",
|
|
38
|
+
"@webex/webex-core": "3.0.0-beta.400",
|
|
39
39
|
"debug": "^4.3.4",
|
|
40
40
|
"lodash": "^4.17.21"
|
|
41
41
|
}
|
package/src/messages.js
CHANGED
|
@@ -8,27 +8,21 @@ import {
|
|
|
8
8
|
buildHydraPersonId,
|
|
9
9
|
buildHydraRoomId,
|
|
10
10
|
createEventEnvelope,
|
|
11
|
-
getHydraClusterString
|
|
11
|
+
getHydraClusterString,
|
|
12
12
|
} from '@webex/common';
|
|
13
|
-
import {
|
|
14
|
-
Page,
|
|
15
|
-
WebexPlugin
|
|
16
|
-
} from '@webex/webex-core';
|
|
13
|
+
import {Page, WebexPlugin} from '@webex/webex-core';
|
|
17
14
|
import {cloneDeep, isArray} from 'lodash';
|
|
18
15
|
|
|
19
16
|
const verbToType = {
|
|
20
|
-
[SDK_EVENT.INTERNAL.ACTIVITY_VERB.SHARE]:
|
|
21
|
-
|
|
22
|
-
[SDK_EVENT.INTERNAL.ACTIVITY_VERB.
|
|
23
|
-
SDK_EVENT.EXTERNAL.EVENT_TYPE.CREATED,
|
|
24
|
-
[SDK_EVENT.INTERNAL.ACTIVITY_VERB.DELETE]:
|
|
25
|
-
SDK_EVENT.EXTERNAL.EVENT_TYPE.DELETED
|
|
17
|
+
[SDK_EVENT.INTERNAL.ACTIVITY_VERB.SHARE]: SDK_EVENT.EXTERNAL.EVENT_TYPE.CREATED,
|
|
18
|
+
[SDK_EVENT.INTERNAL.ACTIVITY_VERB.POST]: SDK_EVENT.EXTERNAL.EVENT_TYPE.CREATED,
|
|
19
|
+
[SDK_EVENT.INTERNAL.ACTIVITY_VERB.DELETE]: SDK_EVENT.EXTERNAL.EVENT_TYPE.DELETED,
|
|
26
20
|
};
|
|
27
21
|
|
|
28
22
|
const getRoomType = (roomTags) =>
|
|
29
|
-
|
|
30
|
-
SDK_EVENT.EXTERNAL.SPACE_TYPE.DIRECT
|
|
31
|
-
SDK_EVENT.EXTERNAL.SPACE_TYPE.GROUP
|
|
23
|
+
roomTags.includes(SDK_EVENT.INTERNAL.ACTIVITY_TAG.ONE_ON_ONE)
|
|
24
|
+
? SDK_EVENT.EXTERNAL.SPACE_TYPE.DIRECT
|
|
25
|
+
: SDK_EVENT.EXTERNAL.SPACE_TYPE.GROUP;
|
|
32
26
|
|
|
33
27
|
/**
|
|
34
28
|
* @typedef {Object} MessageObject
|
|
@@ -100,18 +94,18 @@ const Messages = WebexPlugin.extend({
|
|
|
100
94
|
*/
|
|
101
95
|
listen() {
|
|
102
96
|
// Create a common envelope that we will wrap all events in
|
|
103
|
-
return createEventEnvelope(this.webex,
|
|
104
|
-
|
|
105
|
-
.then((envelope) => {
|
|
97
|
+
return createEventEnvelope(this.webex, SDK_EVENT.EXTERNAL.RESOURCE.MESSAGES).then(
|
|
98
|
+
(envelope) => {
|
|
106
99
|
this.eventEnvelope = envelope;
|
|
107
100
|
|
|
108
101
|
// Register to listen to events
|
|
109
102
|
return this.webex.internal.mercury.connect().then(() => {
|
|
110
|
-
this.listenTo(this.webex.internal.mercury,
|
|
111
|
-
|
|
112
|
-
|
|
103
|
+
this.listenTo(this.webex.internal.mercury, SDK_EVENT.INTERNAL.WEBEX_ACTIVITY, (event) =>
|
|
104
|
+
this.onWebexApiEvent(event)
|
|
105
|
+
);
|
|
113
106
|
});
|
|
114
|
-
}
|
|
107
|
+
}
|
|
108
|
+
);
|
|
115
109
|
},
|
|
116
110
|
|
|
117
111
|
/**
|
|
@@ -143,12 +137,17 @@ const Messages = WebexPlugin.extend({
|
|
|
143
137
|
let key = 'body';
|
|
144
138
|
|
|
145
139
|
if (message.file) {
|
|
146
|
-
this.logger.warn(
|
|
140
|
+
this.logger.warn(
|
|
141
|
+
'Supplying a single `file` property is deprecated; please supply a `files` array'
|
|
142
|
+
);
|
|
147
143
|
message.files = [message.file];
|
|
148
144
|
Reflect.deleteProperty(message, 'file');
|
|
149
145
|
}
|
|
150
146
|
|
|
151
|
-
if (
|
|
147
|
+
if (
|
|
148
|
+
isArray(message.files) &&
|
|
149
|
+
message.files.reduce((type, file) => type || typeof file !== 'string', false)
|
|
150
|
+
) {
|
|
152
151
|
key = 'formData';
|
|
153
152
|
}
|
|
154
153
|
|
|
@@ -156,11 +155,10 @@ const Messages = WebexPlugin.extend({
|
|
|
156
155
|
method: 'POST',
|
|
157
156
|
service: 'hydra',
|
|
158
157
|
resource: 'messages',
|
|
159
|
-
[key]: message
|
|
158
|
+
[key]: message,
|
|
160
159
|
};
|
|
161
160
|
|
|
162
|
-
return this.request(options)
|
|
163
|
-
.then((res) => res.body);
|
|
161
|
+
return this.request(options).then((res) => res.body);
|
|
164
162
|
},
|
|
165
163
|
|
|
166
164
|
/**
|
|
@@ -194,9 +192,8 @@ const Messages = WebexPlugin.extend({
|
|
|
194
192
|
|
|
195
193
|
return this.request({
|
|
196
194
|
service: 'hydra',
|
|
197
|
-
resource: `messages/${id}
|
|
198
|
-
})
|
|
199
|
-
.then((res) => res.body.items || res.body);
|
|
195
|
+
resource: `messages/${id}`,
|
|
196
|
+
}).then((res) => res.body.items || res.body);
|
|
200
197
|
},
|
|
201
198
|
|
|
202
199
|
/**
|
|
@@ -242,9 +239,8 @@ const Messages = WebexPlugin.extend({
|
|
|
242
239
|
return this.request({
|
|
243
240
|
service: 'hydra',
|
|
244
241
|
resource: 'messages',
|
|
245
|
-
qs: options
|
|
246
|
-
})
|
|
247
|
-
.then((res) => new Page(res, this.webex));
|
|
242
|
+
qs: options,
|
|
243
|
+
}).then((res) => new Page(res, this.webex));
|
|
248
244
|
},
|
|
249
245
|
|
|
250
246
|
/**
|
|
@@ -293,17 +289,16 @@ const Messages = WebexPlugin.extend({
|
|
|
293
289
|
return this.request({
|
|
294
290
|
method: 'DELETE',
|
|
295
291
|
service: 'hydra',
|
|
296
|
-
resource: `messages/${id}
|
|
297
|
-
})
|
|
298
|
-
.
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
}
|
|
292
|
+
resource: `messages/${id}`,
|
|
293
|
+
}).then((res) => {
|
|
294
|
+
// Firefox has some issues with 204s and/or DELETE. This should move to
|
|
295
|
+
// http-core
|
|
296
|
+
if (res.statusCode === 204) {
|
|
297
|
+
return undefined;
|
|
298
|
+
}
|
|
304
299
|
|
|
305
|
-
|
|
306
|
-
|
|
300
|
+
return res.body;
|
|
301
|
+
});
|
|
307
302
|
},
|
|
308
303
|
|
|
309
304
|
/**
|
|
@@ -335,8 +330,7 @@ const Messages = WebexPlugin.extend({
|
|
|
335
330
|
return;
|
|
336
331
|
}
|
|
337
332
|
|
|
338
|
-
this.getMessageEvent(activity, type)
|
|
339
|
-
.then(this.fire(type));
|
|
333
|
+
this.getMessageEvent(activity, type).then(this.fire(type));
|
|
340
334
|
},
|
|
341
335
|
|
|
342
336
|
/**
|
|
@@ -354,7 +348,7 @@ const Messages = WebexPlugin.extend({
|
|
|
354
348
|
id,
|
|
355
349
|
actor: {entryUUID: actorId, emailAddress},
|
|
356
350
|
object: {id: objectId},
|
|
357
|
-
target: {id: roomId, url: roomUrl, tags: roomTags}
|
|
351
|
+
target: {id: roomId, url: roomUrl, tags: roomTags},
|
|
358
352
|
} = activity;
|
|
359
353
|
|
|
360
354
|
const cluster = getHydraClusterString(this.webex, roomUrl);
|
|
@@ -374,18 +368,17 @@ const Messages = WebexPlugin.extend({
|
|
|
374
368
|
personEmail: emailAddress || actorId,
|
|
375
369
|
personId,
|
|
376
370
|
roomId: buildHydraRoomId(roomId, cluster),
|
|
377
|
-
roomType: getRoomType(roomTags)
|
|
378
|
-
}
|
|
371
|
+
roomType: getRoomType(roomTags),
|
|
372
|
+
},
|
|
379
373
|
});
|
|
380
374
|
}
|
|
381
375
|
|
|
382
|
-
return this.get(buildHydraMessageId(id, cluster))
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
}
|
|
376
|
+
return this.get(buildHydraMessageId(id, cluster)).then((data) => ({
|
|
377
|
+
...combinedEvent,
|
|
378
|
+
actorId: data.personId,
|
|
379
|
+
data,
|
|
380
|
+
}));
|
|
381
|
+
},
|
|
389
382
|
});
|
|
390
383
|
|
|
391
384
|
export default Messages;
|
|
@@ -19,7 +19,8 @@ const debug = require('debug')('messages');
|
|
|
19
19
|
|
|
20
20
|
const KNOWN_HOSTED_IMAGE_URL = 'https://download.ciscospark.com/test/photo.png';
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
// SPARK-413317
|
|
23
|
+
describe.skip('plugin-messages', function () {
|
|
23
24
|
this.timeout(60000);
|
|
24
25
|
|
|
25
26
|
let webex;
|
|
@@ -27,64 +28,62 @@ describe('plugin-messages', function () {
|
|
|
27
28
|
let actor;
|
|
28
29
|
let actorEU;
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
.then(([user, usersEU]) => {
|
|
31
|
+
before(() =>
|
|
32
|
+
Promise.all([
|
|
33
|
+
testUsers.create({count: 1}),
|
|
34
|
+
testUsers.create({count: 1, config: {orgId: process.env.EU_PRIMARY_ORG_ID}}),
|
|
35
|
+
]).then(([user, usersEU]) => {
|
|
36
36
|
[actor] = user;
|
|
37
37
|
[actorEU] = usersEU;
|
|
38
38
|
|
|
39
39
|
webex = new WebexCore({credentials: actor.token});
|
|
40
40
|
webexEU = new WebexCore({credentials: actorEU.token});
|
|
41
41
|
|
|
42
|
-
webex.people.get('me')
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
});
|
|
42
|
+
webex.people.get('me').then((person) => {
|
|
43
|
+
actor = person;
|
|
44
|
+
});
|
|
46
45
|
|
|
47
|
-
webexEU.people.get('me')
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
webexEU.people.get('me').then((person) => {
|
|
47
|
+
actorEU = person;
|
|
48
|
+
});
|
|
49
|
+
})
|
|
50
|
+
);
|
|
52
51
|
|
|
53
52
|
describe('#messages', () => {
|
|
54
53
|
let room;
|
|
55
54
|
let roomEU;
|
|
56
55
|
|
|
57
|
-
before(() =>
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
.then(([r, rEU]) => {
|
|
56
|
+
before(() =>
|
|
57
|
+
Promise.all([
|
|
58
|
+
webex.rooms.create({title: 'Webex Test Room'}),
|
|
59
|
+
webexEU.rooms.create({title: 'Webex Test Room for EU'}),
|
|
60
|
+
]).then(([r, rEU]) => {
|
|
62
61
|
room = r;
|
|
63
62
|
roomEU = rEU;
|
|
64
63
|
const text = 'First Message';
|
|
65
64
|
|
|
66
|
-
webex.messages
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
65
|
+
webex.messages
|
|
66
|
+
.create({
|
|
67
|
+
roomId: room.id,
|
|
68
|
+
text,
|
|
69
|
+
})
|
|
70
70
|
.then((message) => {
|
|
71
71
|
validateMessage(message, text);
|
|
72
72
|
});
|
|
73
73
|
|
|
74
|
-
webexEU.messages
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
74
|
+
webexEU.messages
|
|
75
|
+
.create({
|
|
76
|
+
roomId: roomEU.id,
|
|
77
|
+
text,
|
|
78
|
+
})
|
|
78
79
|
.then((message) => {
|
|
79
80
|
validateMessage(message, text);
|
|
80
81
|
});
|
|
81
|
-
})
|
|
82
|
+
})
|
|
83
|
+
);
|
|
82
84
|
|
|
83
85
|
// eslint-disable-next-line consistent-return
|
|
84
|
-
after(() => Promise.all([
|
|
85
|
-
webex.rooms.remove(room),
|
|
86
|
-
webexEU.rooms.remove(roomEU)
|
|
87
|
-
]));
|
|
86
|
+
after(() => Promise.all([webex.rooms.remove(room), webexEU.rooms.remove(roomEU)]));
|
|
88
87
|
|
|
89
88
|
afterEach(() => webex.messages.stopListening());
|
|
90
89
|
|
|
@@ -103,18 +102,20 @@ describe('plugin-messages', function () {
|
|
|
103
102
|
|
|
104
103
|
const text = 'A test message';
|
|
105
104
|
|
|
106
|
-
return webex.messages.listen()
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
105
|
+
return webex.messages.listen().then(() =>
|
|
106
|
+
webex.messages
|
|
107
|
+
.create({
|
|
108
|
+
roomId: room.id,
|
|
109
|
+
text,
|
|
110
|
+
})
|
|
111
111
|
.then(async (m) => {
|
|
112
112
|
message = m;
|
|
113
113
|
validateMessage(message, text);
|
|
114
114
|
const event = await created;
|
|
115
115
|
|
|
116
116
|
validateMessageEvent(event, message, actor);
|
|
117
|
-
})
|
|
117
|
+
})
|
|
118
|
+
);
|
|
118
119
|
});
|
|
119
120
|
|
|
120
121
|
it('posts a message by an EU user in a room and validates the messages:created event', () => {
|
|
@@ -131,21 +132,23 @@ describe('plugin-messages', function () {
|
|
|
131
132
|
|
|
132
133
|
const text = 'A test message';
|
|
133
134
|
|
|
134
|
-
return webexEU.messages.listen()
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
135
|
+
return webexEU.messages.listen().then(() =>
|
|
136
|
+
webexEU.messages
|
|
137
|
+
.create({
|
|
138
|
+
roomId: roomEU.id,
|
|
139
|
+
text,
|
|
140
|
+
})
|
|
139
141
|
.then(async (m) => {
|
|
140
142
|
message = m;
|
|
141
143
|
validateMessage(message, text);
|
|
142
144
|
const event = await created;
|
|
143
145
|
|
|
144
146
|
validateMessageEvent(event, message, actorEU);
|
|
145
|
-
})
|
|
147
|
+
})
|
|
148
|
+
);
|
|
146
149
|
});
|
|
147
150
|
|
|
148
|
-
it(
|
|
151
|
+
it("posts a file to a room by specifying the file's url and validates the event", () => {
|
|
149
152
|
const created = new Promise((resolve) => {
|
|
150
153
|
webex.messages.on('created', (event) => {
|
|
151
154
|
debug('message created event called');
|
|
@@ -153,24 +156,26 @@ describe('plugin-messages', function () {
|
|
|
153
156
|
});
|
|
154
157
|
});
|
|
155
158
|
|
|
156
|
-
return webex.messages.listen()
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
159
|
+
return webex.messages.listen().then(() =>
|
|
160
|
+
webex.messages
|
|
161
|
+
.create({
|
|
162
|
+
roomId: room.id,
|
|
163
|
+
files: [KNOWN_HOSTED_IMAGE_URL],
|
|
164
|
+
})
|
|
161
165
|
.then(async (message) => {
|
|
162
166
|
validateMessage(message);
|
|
163
167
|
const event = await created;
|
|
164
168
|
|
|
165
169
|
validateMessageEvent(event, message, actor);
|
|
166
|
-
})
|
|
170
|
+
})
|
|
171
|
+
);
|
|
167
172
|
});
|
|
168
173
|
|
|
169
174
|
let blob, buffer;
|
|
170
175
|
const text = 'A File';
|
|
171
176
|
|
|
172
|
-
browserOnly(before)(() =>
|
|
173
|
-
.then((file) => {
|
|
177
|
+
browserOnly(before)(() =>
|
|
178
|
+
fh.fetch('sample-image-small-one.png').then((file) => {
|
|
174
179
|
blob = file;
|
|
175
180
|
|
|
176
181
|
return new Promise((resolve) => {
|
|
@@ -183,46 +188,58 @@ describe('plugin-messages', function () {
|
|
|
183
188
|
};
|
|
184
189
|
fileReader.readAsArrayBuffer(blob);
|
|
185
190
|
});
|
|
186
|
-
})
|
|
191
|
+
})
|
|
192
|
+
);
|
|
187
193
|
|
|
188
|
-
nodeOnly(before)(() =>
|
|
189
|
-
.then((file) => {
|
|
194
|
+
nodeOnly(before)(() =>
|
|
195
|
+
fh.fetchWithoutMagic('sample-image-small-one.png').then((file) => {
|
|
190
196
|
buffer = file;
|
|
191
|
-
})
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
197
|
+
})
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
browserOnly(it)(
|
|
201
|
+
'posts a file to a room by directly supplying its blob and validates the event',
|
|
202
|
+
() => {
|
|
203
|
+
const created = new Promise((resolve) => {
|
|
204
|
+
webex.messages.on('created', (event) => {
|
|
205
|
+
debug('message created event called');
|
|
206
|
+
resolve(event);
|
|
207
|
+
});
|
|
198
208
|
});
|
|
199
|
-
});
|
|
200
209
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
+
return webex.messages.listen().then(() =>
|
|
211
|
+
webex.messages
|
|
212
|
+
.create({
|
|
213
|
+
roomId: room.id,
|
|
214
|
+
files: [blob],
|
|
215
|
+
text,
|
|
216
|
+
})
|
|
217
|
+
.then(async (message) => {
|
|
218
|
+
validateMessage(message);
|
|
219
|
+
const event = await created;
|
|
210
220
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
221
|
+
validateMessageEvent(event, message, actor);
|
|
222
|
+
})
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
);
|
|
214
226
|
|
|
215
227
|
// Disabling it gating pipelines because it failes a lot and we get
|
|
216
228
|
// mostly adequate coverage via blob upload
|
|
217
|
-
flaky(it, process.env.SKIP_FLAKY_TESTS)(
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
229
|
+
flaky(it, process.env.SKIP_FLAKY_TESTS)(
|
|
230
|
+
'posts a file to a room by directly supplying its buffer and validates the event',
|
|
231
|
+
() =>
|
|
232
|
+
webex.messages
|
|
233
|
+
.create({
|
|
234
|
+
roomId: room.id,
|
|
235
|
+
files: [buffer],
|
|
236
|
+
})
|
|
237
|
+
.then((message) => {
|
|
238
|
+
validateMessage(message, '', 1);
|
|
239
|
+
})
|
|
240
|
+
);
|
|
224
241
|
|
|
225
|
-
it(
|
|
242
|
+
it("posts a file with a message to a room by specifying the file's url and validates the event", () => {
|
|
226
243
|
const created = new Promise((resolve) => {
|
|
227
244
|
webex.messages.on('created', (event) => {
|
|
228
245
|
debug('message created event called');
|
|
@@ -230,12 +247,13 @@ describe('plugin-messages', function () {
|
|
|
230
247
|
});
|
|
231
248
|
});
|
|
232
249
|
|
|
233
|
-
return webex.messages.listen()
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
250
|
+
return webex.messages.listen().then(() =>
|
|
251
|
+
webex.messages
|
|
252
|
+
.create({
|
|
253
|
+
roomId: room.id,
|
|
254
|
+
files: [KNOWN_HOSTED_IMAGE_URL],
|
|
255
|
+
text,
|
|
256
|
+
})
|
|
239
257
|
.then(async (message) => {
|
|
240
258
|
validateMessage(message);
|
|
241
259
|
let event = await created;
|
|
@@ -257,7 +275,8 @@ describe('plugin-messages', function () {
|
|
|
257
275
|
}
|
|
258
276
|
|
|
259
277
|
validateMessageEvent(event, message, actor);
|
|
260
|
-
})
|
|
278
|
+
})
|
|
279
|
+
);
|
|
261
280
|
});
|
|
262
281
|
|
|
263
282
|
it('posts a message to a card to a room validates the event', () => {
|
|
@@ -275,23 +294,24 @@ describe('plugin-messages', function () {
|
|
|
275
294
|
body: [
|
|
276
295
|
{
|
|
277
296
|
type: 'TextBlock',
|
|
278
|
-
text: 'Here is an image'
|
|
297
|
+
text: 'Here is an image',
|
|
279
298
|
},
|
|
280
299
|
{
|
|
281
300
|
type: 'Image',
|
|
282
301
|
url: KNOWN_HOSTED_IMAGE_URL,
|
|
283
|
-
size: 'small'
|
|
284
|
-
}
|
|
285
|
-
]
|
|
286
|
-
}
|
|
302
|
+
size: 'small',
|
|
303
|
+
},
|
|
304
|
+
],
|
|
305
|
+
},
|
|
287
306
|
};
|
|
288
307
|
|
|
289
|
-
return webex.messages.listen()
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
308
|
+
return webex.messages.listen().then(() =>
|
|
309
|
+
webex.messages
|
|
310
|
+
.create({
|
|
311
|
+
roomId: room.id,
|
|
312
|
+
text,
|
|
313
|
+
attachments: [attachment],
|
|
314
|
+
})
|
|
295
315
|
.then(async (message) => {
|
|
296
316
|
// // Assert that the message shape is valid and contains attachment data.
|
|
297
317
|
validateMessage(message, text, 0, attachment);
|
|
@@ -314,7 +334,8 @@ describe('plugin-messages', function () {
|
|
|
314
334
|
}
|
|
315
335
|
|
|
316
336
|
validateMessageEvent(event, message, actor);
|
|
317
|
-
})
|
|
337
|
+
})
|
|
338
|
+
);
|
|
318
339
|
});
|
|
319
340
|
});
|
|
320
341
|
|
|
@@ -322,14 +343,17 @@ describe('plugin-messages', function () {
|
|
|
322
343
|
let message;
|
|
323
344
|
const text = 'This message will be deleted';
|
|
324
345
|
|
|
325
|
-
beforeEach(() =>
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
346
|
+
beforeEach(() =>
|
|
347
|
+
webex.messages
|
|
348
|
+
.create({
|
|
349
|
+
roomId: room.id,
|
|
350
|
+
text,
|
|
351
|
+
})
|
|
352
|
+
.then((m) => {
|
|
353
|
+
message = m;
|
|
354
|
+
validateMessage(m, text);
|
|
355
|
+
})
|
|
356
|
+
);
|
|
333
357
|
|
|
334
358
|
it('deletes a single message and validates the message:deleted event', () => {
|
|
335
359
|
const deleted = new Promise((resolve) => {
|
|
@@ -339,8 +363,9 @@ describe('plugin-messages', function () {
|
|
|
339
363
|
});
|
|
340
364
|
});
|
|
341
365
|
|
|
342
|
-
return webex.messages.listen()
|
|
343
|
-
|
|
366
|
+
return webex.messages.listen().then(() =>
|
|
367
|
+
webex.messages
|
|
368
|
+
.remove(message)
|
|
344
369
|
.then((body) => {
|
|
345
370
|
assert.notOk(body);
|
|
346
371
|
|
|
@@ -351,7 +376,8 @@ describe('plugin-messages', function () {
|
|
|
351
376
|
const event = await deleted;
|
|
352
377
|
|
|
353
378
|
validateMessageEvent(event, message, actor);
|
|
354
|
-
})
|
|
379
|
+
})
|
|
380
|
+
);
|
|
355
381
|
});
|
|
356
382
|
});
|
|
357
383
|
|
|
@@ -365,39 +391,50 @@ describe('plugin-messages', function () {
|
|
|
365
391
|
webex.messages.off('created');
|
|
366
392
|
webex.messages.off('deleted');
|
|
367
393
|
|
|
368
|
-
return webex.messages
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
394
|
+
return webex.messages
|
|
395
|
+
.create({
|
|
396
|
+
roomId: room.id,
|
|
397
|
+
text,
|
|
398
|
+
})
|
|
372
399
|
.then((m) => {
|
|
373
400
|
message = m;
|
|
374
401
|
validateMessage(message, text);
|
|
375
402
|
});
|
|
376
403
|
});
|
|
377
404
|
|
|
378
|
-
it('returns a single message', () =>
|
|
379
|
-
.then((m) => {
|
|
405
|
+
it('returns a single message', () =>
|
|
406
|
+
webex.messages.get(message).then((m) => {
|
|
380
407
|
assert.isMessage(m);
|
|
381
408
|
assert.deepEqual(m, message);
|
|
382
409
|
}));
|
|
383
410
|
});
|
|
384
411
|
|
|
385
|
-
|
|
386
412
|
describe('#list()', () => {
|
|
387
|
-
before(() =>
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
413
|
+
before(() =>
|
|
414
|
+
webex.rooms
|
|
415
|
+
.create({
|
|
416
|
+
title: 'Room List Test',
|
|
417
|
+
})
|
|
418
|
+
.then((r) => {
|
|
419
|
+
room = r;
|
|
420
|
+
})
|
|
421
|
+
);
|
|
422
|
+
|
|
423
|
+
before(() =>
|
|
424
|
+
[1, 2, 3].reduce(
|
|
425
|
+
(promise, value) =>
|
|
426
|
+
promise.then(() =>
|
|
427
|
+
webex.messages.create({
|
|
428
|
+
roomId: room.id,
|
|
429
|
+
text: `message: ${value}`,
|
|
430
|
+
})
|
|
431
|
+
),
|
|
432
|
+
Promise.resolve()
|
|
433
|
+
)
|
|
434
|
+
);
|
|
435
|
+
|
|
436
|
+
it('returns all messages for a room', () =>
|
|
437
|
+
webex.messages.list({roomId: room.id}).then((messages) => {
|
|
401
438
|
assert.isDefined(messages);
|
|
402
439
|
assert.lengthOf(messages, 3);
|
|
403
440
|
for (const message of messages) {
|
|
@@ -408,7 +445,8 @@ describe('plugin-messages', function () {
|
|
|
408
445
|
it('returns a bounded set of messages for a room', () => {
|
|
409
446
|
const spy = sinon.spy();
|
|
410
447
|
|
|
411
|
-
return webex.messages
|
|
448
|
+
return webex.messages
|
|
449
|
+
.list({roomId: room.id, max: 2})
|
|
412
450
|
.then((messages) => {
|
|
413
451
|
assert.lengthOf(messages, 2);
|
|
414
452
|
|
|
@@ -422,7 +460,7 @@ describe('plugin-messages', function () {
|
|
|
422
460
|
}
|
|
423
461
|
|
|
424
462
|
return Promise.resolve();
|
|
425
|
-
}(messages)
|
|
463
|
+
})(messages);
|
|
426
464
|
})
|
|
427
465
|
.then(() => {
|
|
428
466
|
assert.calledThrice(spy);
|
|
@@ -432,12 +470,15 @@ describe('plugin-messages', function () {
|
|
|
432
470
|
describe('when a message is threaded', () => {
|
|
433
471
|
let parentId;
|
|
434
472
|
|
|
435
|
-
before(() =>
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
473
|
+
before(() =>
|
|
474
|
+
webex.rooms
|
|
475
|
+
.create({
|
|
476
|
+
title: 'Room List Test',
|
|
477
|
+
})
|
|
478
|
+
.then((r) => {
|
|
479
|
+
room = r;
|
|
480
|
+
})
|
|
481
|
+
);
|
|
441
482
|
|
|
442
483
|
before(() => {
|
|
443
484
|
const createdParent = new Promise((resolve) => {
|
|
@@ -447,11 +488,12 @@ describe('plugin-messages', function () {
|
|
|
447
488
|
});
|
|
448
489
|
});
|
|
449
490
|
|
|
450
|
-
return webex.messages.listen()
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
491
|
+
return webex.messages.listen().then(() =>
|
|
492
|
+
webex.messages
|
|
493
|
+
.create({
|
|
494
|
+
roomId: room.id,
|
|
495
|
+
text: 'This is the parent message',
|
|
496
|
+
})
|
|
455
497
|
.then(async (message) => {
|
|
456
498
|
parentId = message.id;
|
|
457
499
|
|
|
@@ -466,22 +508,24 @@ describe('plugin-messages', function () {
|
|
|
466
508
|
});
|
|
467
509
|
});
|
|
468
510
|
|
|
469
|
-
return webex.messages
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
511
|
+
return webex.messages
|
|
512
|
+
.create({
|
|
513
|
+
roomId: room.id,
|
|
514
|
+
text: 'This is the reply',
|
|
515
|
+
parentId,
|
|
516
|
+
})
|
|
474
517
|
.then(async (message2) => {
|
|
475
518
|
validateMessage(message2);
|
|
476
519
|
const event2 = await createdReply;
|
|
477
520
|
|
|
478
521
|
return Promise.resolve(validateMessageEvent(event2, message2, actor));
|
|
479
522
|
});
|
|
480
|
-
})
|
|
523
|
+
})
|
|
524
|
+
);
|
|
481
525
|
});
|
|
482
526
|
|
|
483
|
-
it('returns all messages for a room', () =>
|
|
484
|
-
.then((messages) => {
|
|
527
|
+
it('returns all messages for a room', () =>
|
|
528
|
+
webex.messages.list({roomId: room.id}).then((messages) => {
|
|
485
529
|
assert.isDefined(messages);
|
|
486
530
|
assert.lengthOf(messages.items, 2);
|
|
487
531
|
for (const message of messages.items) {
|
|
@@ -492,8 +536,8 @@ describe('plugin-messages', function () {
|
|
|
492
536
|
}
|
|
493
537
|
}));
|
|
494
538
|
|
|
495
|
-
it('returns only the replies for particular message thread', () =>
|
|
496
|
-
.then((messages) => {
|
|
539
|
+
it('returns only the replies for particular message thread', () =>
|
|
540
|
+
webex.messages.list({roomId: room.id, parentId}).then((messages) => {
|
|
497
541
|
assert.lengthOf(messages.items, 1);
|
|
498
542
|
const message = messages.items[0];
|
|
499
543
|
|
|
@@ -505,7 +549,6 @@ describe('plugin-messages', function () {
|
|
|
505
549
|
});
|
|
506
550
|
});
|
|
507
551
|
|
|
508
|
-
|
|
509
552
|
/**
|
|
510
553
|
* Validate a Message object.
|
|
511
554
|
* @param {Object} message
|
|
@@ -572,30 +615,21 @@ function validateAdaptiveCard(message, attachment) {
|
|
|
572
615
|
* @returns {void}
|
|
573
616
|
*/
|
|
574
617
|
function validateMessageEvent(event, message, actor) {
|
|
575
|
-
assert.equal(event.resource, SDK_EVENT.EXTERNAL.RESOURCE.MESSAGES,
|
|
576
|
-
'not a message event');
|
|
618
|
+
assert.equal(event.resource, SDK_EVENT.EXTERNAL.RESOURCE.MESSAGES, 'not a message event');
|
|
577
619
|
assert.isDefined(event.event, 'message event type not set');
|
|
578
620
|
assert.isDefined(event.created, 'event listener created date not set');
|
|
579
|
-
assert.equal(event.createdBy, actor.id,
|
|
580
|
-
|
|
581
|
-
assert.equal(event.orgId, actor.orgId,
|
|
582
|
-
'event listener orgId not === to our actor\'s');
|
|
621
|
+
assert.equal(event.createdBy, actor.id, 'event listener createdBy not set to our actor');
|
|
622
|
+
assert.equal(event.orgId, actor.orgId, "event listener orgId not === to our actor's");
|
|
583
623
|
assert.equal(event.ownedBy, 'creator', 'event listener not owned by creator');
|
|
584
624
|
assert.equal(event.status, 'active', 'event listener status not active');
|
|
585
|
-
assert.equal(event.actorId, actor.id,
|
|
586
|
-
'event actorId not equal to our actor\'s id');
|
|
625
|
+
assert.equal(event.actorId, actor.id, "event actorId not equal to our actor's id");
|
|
587
626
|
|
|
588
627
|
// Ensure event data matches data returned from function call
|
|
589
|
-
assert.equal(event.data.id, message.id,
|
|
590
|
-
|
|
591
|
-
assert.equal(event.data.
|
|
592
|
-
|
|
593
|
-
assert.equal(event.data.
|
|
594
|
-
'event/message.personId not equal');
|
|
595
|
-
assert.equal(event.data.personEmail, message.personEmail,
|
|
596
|
-
'event/message.personEmail not equal');
|
|
597
|
-
assert.equal(event.data.roomType, message.roomType,
|
|
598
|
-
'event/message.roomType not equal');
|
|
628
|
+
assert.equal(event.data.id, message.id, 'event/message.id not equal');
|
|
629
|
+
assert.equal(event.data.roomId, message.roomId, 'event/message.roomId not equal');
|
|
630
|
+
assert.equal(event.data.personId, message.personId, 'event/message.personId not equal');
|
|
631
|
+
assert.equal(event.data.personEmail, message.personEmail, 'event/message.personEmail not equal');
|
|
632
|
+
assert.equal(event.data.roomType, message.roomType, 'event/message.roomType not equal');
|
|
599
633
|
if (event.event === SDK_EVENT.EXTERNAL.EVENT_TYPE.DELETED) {
|
|
600
634
|
return;
|
|
601
635
|
}
|
|
@@ -605,14 +639,19 @@ function validateMessageEvent(event, message, actor) {
|
|
|
605
639
|
if (message.files) {
|
|
606
640
|
assert.isArray(event.data.files, 'event.data.files is not array');
|
|
607
641
|
assert.isArray(message.files, 'message.files is not array');
|
|
608
|
-
assert.equal(
|
|
609
|
-
|
|
642
|
+
assert.equal(
|
|
643
|
+
event.data.files.length,
|
|
644
|
+
message.files.length,
|
|
645
|
+
'event/message file arrays are different lengths'
|
|
646
|
+
);
|
|
610
647
|
for (let i = 0; i < message.files.length; i += 1) {
|
|
611
648
|
// The gateway returned by the API is apialpha.ciscospark.com
|
|
612
649
|
// The gateway returned in the event is api.ciscospark.com -- expected?
|
|
613
|
-
assert.equal(
|
|
650
|
+
assert.equal(
|
|
651
|
+
event.data.files[i].substr(event.data.files[i].lastIndexOf('/') + 1),
|
|
614
652
|
message.files[i].substr(message.files[i].lastIndexOf('/') + 1),
|
|
615
|
-
'event/message file urls do not match'
|
|
653
|
+
'event/message file urls do not match'
|
|
654
|
+
);
|
|
616
655
|
}
|
|
617
656
|
}
|
|
618
657
|
if (message.attachments) {
|