@webex/plugin-messages 3.0.0-beta.8 → 3.0.0-beta.80

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 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
- .then((message) => {
38
- console.log(message);
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":";;;;;;;;;;;;AAIA;;AACA;;AAEA;;AAEA;;AATA;AACA;AACA;AAE8C;AAO9C,IAAAA,yBAAA,EAAe,UAAf,EAA2BC,iBAA3B;eAEeA,iB"}
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; // Register to listen to events
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
- _activity$actor = activity.actor,
383
- actorId = _activity$actor.entryUUID,
384
- emailAddress = _activity$actor.emailAddress,
385
- objectId = activity.object.id,
386
- _activity$target = activity.target,
387
- roomId = _activity$target.id,
388
- roomUrl = _activity$target.url,
389
- roomTags = _activity$target.tags;
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.8"
376
+ version: "3.0.0-beta.80"
418
377
  });
419
-
420
378
  var _default = Messages;
421
379
  exports.default = _default;
422
380
  //# sourceMappingURL=messages.js.map
@@ -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,aAAnB,CAAiCM,MALpB,EAMZR,iBAAA,CAAUI,QAAV,CAAmBC,UAAnB,CAA8BI,OANlB,eAAhB;;AASA,IAAMC,WAAW,GAAG,SAAdA,WAAc,CAACC,QAAD;EAAA,OACjBA,QAAQ,CAACC,QAAT,CAAkBZ,iBAAA,CAAUC,QAAV,CAAmBY,YAAnB,CAAgCC,UAAlD,IACCd,iBAAA,CAAUI,QAAV,CAAmBW,UAAnB,CAA8BC,MAD/B,GAEChB,iBAAA,CAAUI,QAAV,CAAmBW,UAAnB,CAA8BE,KAHd;AAAA,CAApB;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,IAAMC,QAAQ,GAAGC,sBAAA,CAAYC,MAAZ,CAAmB;EAClC;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BO,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,iBAAS,CAACC,QAAQ,CAACC,aAAa,CAACC,KAAK,EAAGH,iBAAS,CAACI,QAAQ,CAACC,UAAU,CAACC,OAAO,8CAC9EN,iBAAS,CAACC,QAAQ,CAACC,aAAa,CAACK,IAAI,EAAGP,iBAAS,CAACI,QAAQ,CAACC,UAAU,CAACC,OAAO,8CAC7EN,iBAAS,CAACC,QAAQ,CAACC,aAAa,CAACM,MAAM,EAAGR,iBAAS,CAACI,QAAQ,CAACC,UAAU,CAACI,OAAO,eACjF;AAED,IAAMC,WAAW,GAAG,SAAdA,WAAW,CAAIC,QAAQ;EAAA,OAC3BA,QAAQ,CAACC,QAAQ,CAACZ,iBAAS,CAACC,QAAQ,CAACY,YAAY,CAACC,UAAU,CAAC,GACzDd,iBAAS,CAACI,QAAQ,CAACW,UAAU,CAACC,MAAM,GACpChB,iBAAS,CAACI,QAAQ,CAACW,UAAU,CAACE,KAAK;AAAA;;AAEzC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAMC,QAAQ,GAAGC,sBAAW,CAACC,MAAM,CAAC;EAClC;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACEC,UAAU,wBAAU;IAAA,kCAANC,IAAI;MAAJA,IAAI;IAAA;IAChB,oBAAcH,sBAAW,CAACI,SAAS,CAACF,UAAU,EAAE,IAAI,EAAEC,IAAI,CAAC;EAC7D,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;EACEE,MAAM,oBAAG;IAAA;IACP;IACA,OAAO,IAAAC,2BAAmB,EAAC,IAAI,CAACC,KAAK,EAAE1B,iBAAS,CAACI,QAAQ,CAACuB,QAAQ,CAACC,QAAQ,CAAC,CAACC,IAAI,CAC/E,UAACC,QAAQ,EAAK;MACZ,KAAI,CAACC,aAAa,GAAGD,QAAQ;;MAE7B;MACA,OAAO,KAAI,CAACJ,KAAK,CAACM,QAAQ,CAACC,OAAO,CAACC,OAAO,EAAE,CAACL,IAAI,CAAC,YAAM;QACtD,KAAI,CAACM,QAAQ,CAAC,KAAI,CAACT,KAAK,CAACM,QAAQ,CAACC,OAAO,EAAEjC,iBAAS,CAACC,QAAQ,CAACmC,cAAc,EAAE,UAACC,KAAK;UAAA,OAClF,KAAI,CAACC,eAAe,CAACD,KAAK,CAAC;QAAA,EAC5B;MACH,CAAC,CAAC;IACJ,CAAC,CACF;EACH,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;EACEE,M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ACA;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,OAAO,CAACgB,EAAE,IAAIhB,OAAO;IAEhC,OAAO,IAAI,CAACY,OAAO,CAAC;MAClBH,MAAM,EAAE,QAAQ;MAChBC,OAAO,EAAE,OAAO;MAChBC,QAAQ,qBAAcK,EAAE;IAC1B,CAAC,CAAC,CAAC3B,IAAI,CAAC,UAACwB,GAAG,EAAK;MACf;MACA;MACA,IAAIA,GAAG,CAACS,UAAU,KAAK,GAAG,EAAE;QAC1B,OAAOC,SAAS;MAClB;MAEA,OAAOV,GAAG,CAACC,IAAI;IACjB,CAAC,CAAC;EACJ,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;AACA;EACEU,IAAI,gBAACjB,IAAI,EAAE;IAAA;IACT,OAAO,UAACV,KAAK;MAAA,OAAK,MAAI,CAAC4B,OAAO,CAAClB,IAAI,EAAEV,KAAK,CAAC;IAAA;EAC7C,CAAC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JX,EAAE,EAAE,IAAA+B,2BAAmB,EAACb,QAAQ,EAAEO,OAAO,CAAC;UAC1CO,WAAW,EAAEf,YAAY,IAAIF,OAAO;UACpCa,QAAQ,EAARA,QAAQ;UACRP,MAAM,EAAE,IAAAY,wBAAgB,EAACZ,MAAM,EAAEI,OAAO,CAAC;UACzCS,QAAQ,EAAEhF,WAAW,CAACC,QAAQ;QAChC;MAAC,GACD;IACJ;IAEA,OAAO,IAAI,CAAC4C,GAAG,CAAC,IAAAgC,2BAAmB,EAAC/B,EAAE,EAAEyB,OAAO,CAAC,CAAC,CAACpD,IAAI,CAAC,UAACsC,IAAI;MAAA,uCACvDgB,aAAa;QAChBZ,OAAO,EAAEJ,IAAI,CAACiB,QAAQ;QACtBjB,IAAI,EAAJA;MAAI;IAAA,CACJ,CAAC;EACL,CAAC;EAAA;AACH,CAAC,CAAC;AAAC,eAEYjD,QAAQ;AAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webex/plugin-messages",
3
- "version": "3.0.0-beta.8",
3
+ "version": "3.0.0-beta.80",
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.8",
24
- "@webex/test-helper-file": "3.0.0-beta.8",
25
- "@webex/test-helper-mocha": "3.0.0-beta.8",
26
- "@webex/test-helper-test-users": "3.0.0-beta.8",
23
+ "@webex/test-helper-chai": "3.0.0-beta.80",
24
+ "@webex/test-helper-file": "3.0.0-beta.80",
25
+ "@webex/test-helper-mocha": "3.0.0-beta.80",
26
+ "@webex/test-helper-test-users": "3.0.0-beta.80",
27
27
  "sinon": "^9.2.4"
28
28
  },
29
29
  "dependencies": {
30
- "@webex/common": "3.0.0-beta.8",
31
- "@webex/internal-plugin-conversation": "3.0.0-beta.8",
32
- "@webex/internal-plugin-device": "3.0.0-beta.8",
33
- "@webex/internal-plugin-mercury": "3.0.0-beta.8",
34
- "@webex/plugin-logger": "3.0.0-beta.8",
35
- "@webex/plugin-messages": "3.0.0-beta.8",
36
- "@webex/plugin-people": "3.0.0-beta.8",
37
- "@webex/plugin-rooms": "3.0.0-beta.8",
38
- "@webex/webex-core": "3.0.0-beta.8",
30
+ "@webex/common": "3.0.0-beta.80",
31
+ "@webex/internal-plugin-conversation": "3.0.0-beta.80",
32
+ "@webex/internal-plugin-device": "3.0.0-beta.80",
33
+ "@webex/internal-plugin-mercury": "3.0.0-beta.80",
34
+ "@webex/plugin-logger": "3.0.0-beta.80",
35
+ "@webex/plugin-messages": "3.0.0-beta.80",
36
+ "@webex/plugin-people": "3.0.0-beta.80",
37
+ "@webex/plugin-rooms": "3.0.0-beta.80",
38
+ "@webex/webex-core": "3.0.0-beta.80",
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
- SDK_EVENT.EXTERNAL.EVENT_TYPE.CREATED,
22
- [SDK_EVENT.INTERNAL.ACTIVITY_VERB.POST]:
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
- (roomTags.includes(SDK_EVENT.INTERNAL.ACTIVITY_TAG.ONE_ON_ONE) ?
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
- SDK_EVENT.EXTERNAL.RESOURCE.MESSAGES)
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
- SDK_EVENT.INTERNAL.WEBEX_ACTIVITY,
112
- (event) => this.onWebexApiEvent(event));
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('Supplying a single `file` property is deprecated; please supply a `files` array');
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 (isArray(message.files) && message.files.reduce((type, file) => type || typeof file !== 'string', false)) {
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
- .then((res) => {
299
- // Firefox has some issues with 204s and/or DELETE. This should move to
300
- // http-core
301
- if (res.statusCode === 204) {
302
- return undefined;
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
- return res.body;
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
- .then((data) => ({
384
- ...combinedEvent,
385
- actorId: data.personId,
386
- data
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;
@@ -27,64 +27,62 @@ describe('plugin-messages', function () {
27
27
  let actor;
28
28
  let actorEU;
29
29
 
30
-
31
- before(() => Promise.all([
32
- testUsers.create({count: 1}),
33
- testUsers.create({count: 1, config: {orgId: process.env.EU_PRIMARY_ORG_ID}})
34
- ])
35
- .then(([user, usersEU]) => {
30
+ before(() =>
31
+ Promise.all([
32
+ testUsers.create({count: 1}),
33
+ testUsers.create({count: 1, config: {orgId: process.env.EU_PRIMARY_ORG_ID}}),
34
+ ]).then(([user, usersEU]) => {
36
35
  [actor] = user;
37
36
  [actorEU] = usersEU;
38
37
 
39
38
  webex = new WebexCore({credentials: actor.token});
40
39
  webexEU = new WebexCore({credentials: actorEU.token});
41
40
 
42
- webex.people.get('me')
43
- .then((person) => {
44
- actor = person;
45
- });
41
+ webex.people.get('me').then((person) => {
42
+ actor = person;
43
+ });
46
44
 
47
- webexEU.people.get('me')
48
- .then((person) => {
49
- actorEU = person;
50
- });
51
- }));
45
+ webexEU.people.get('me').then((person) => {
46
+ actorEU = person;
47
+ });
48
+ })
49
+ );
52
50
 
53
51
  describe('#messages', () => {
54
52
  let room;
55
53
  let roomEU;
56
54
 
57
- before(() => Promise.all([
58
- webex.rooms.create({title: 'Webex Test Room'}),
59
- webexEU.rooms.create({title: 'Webex Test Room for EU'})
60
- ])
61
- .then(([r, rEU]) => {
55
+ before(() =>
56
+ Promise.all([
57
+ webex.rooms.create({title: 'Webex Test Room'}),
58
+ webexEU.rooms.create({title: 'Webex Test Room for EU'}),
59
+ ]).then(([r, rEU]) => {
62
60
  room = r;
63
61
  roomEU = rEU;
64
62
  const text = 'First Message';
65
63
 
66
- webex.messages.create({
67
- roomId: room.id,
68
- text
69
- })
64
+ webex.messages
65
+ .create({
66
+ roomId: room.id,
67
+ text,
68
+ })
70
69
  .then((message) => {
71
70
  validateMessage(message, text);
72
71
  });
73
72
 
74
- webexEU.messages.create({
75
- roomId: roomEU.id,
76
- text
77
- })
73
+ webexEU.messages
74
+ .create({
75
+ roomId: roomEU.id,
76
+ text,
77
+ })
78
78
  .then((message) => {
79
79
  validateMessage(message, text);
80
80
  });
81
- }));
81
+ })
82
+ );
82
83
 
83
84
  // eslint-disable-next-line consistent-return
84
- after(() => Promise.all([
85
- webex.rooms.remove(room),
86
- webexEU.rooms.remove(roomEU)
87
- ]));
85
+ after(() => Promise.all([webex.rooms.remove(room), webexEU.rooms.remove(roomEU)]));
88
86
 
89
87
  afterEach(() => webex.messages.stopListening());
90
88
 
@@ -103,18 +101,20 @@ describe('plugin-messages', function () {
103
101
 
104
102
  const text = 'A test message';
105
103
 
106
- return webex.messages.listen()
107
- .then(() => webex.messages.create({
108
- roomId: room.id,
109
- text
110
- })
104
+ return webex.messages.listen().then(() =>
105
+ webex.messages
106
+ .create({
107
+ roomId: room.id,
108
+ text,
109
+ })
111
110
  .then(async (m) => {
112
111
  message = m;
113
112
  validateMessage(message, text);
114
113
  const event = await created;
115
114
 
116
115
  validateMessageEvent(event, message, actor);
117
- }));
116
+ })
117
+ );
118
118
  });
119
119
 
120
120
  it('posts a message by an EU user in a room and validates the messages:created event', () => {
@@ -131,21 +131,23 @@ describe('plugin-messages', function () {
131
131
 
132
132
  const text = 'A test message';
133
133
 
134
- return webexEU.messages.listen()
135
- .then(() => webexEU.messages.create({
136
- roomId: roomEU.id,
137
- text
138
- })
134
+ return webexEU.messages.listen().then(() =>
135
+ webexEU.messages
136
+ .create({
137
+ roomId: roomEU.id,
138
+ text,
139
+ })
139
140
  .then(async (m) => {
140
141
  message = m;
141
142
  validateMessage(message, text);
142
143
  const event = await created;
143
144
 
144
145
  validateMessageEvent(event, message, actorEU);
145
- }));
146
+ })
147
+ );
146
148
  });
147
149
 
148
- it('posts a file to a room by specifying the file\'s url and validates the event', () => {
150
+ it("posts a file to a room by specifying the file's url and validates the event", () => {
149
151
  const created = new Promise((resolve) => {
150
152
  webex.messages.on('created', (event) => {
151
153
  debug('message created event called');
@@ -153,24 +155,26 @@ describe('plugin-messages', function () {
153
155
  });
154
156
  });
155
157
 
156
- return webex.messages.listen()
157
- .then(() => webex.messages.create({
158
- roomId: room.id,
159
- files: [KNOWN_HOSTED_IMAGE_URL]
160
- })
158
+ return webex.messages.listen().then(() =>
159
+ webex.messages
160
+ .create({
161
+ roomId: room.id,
162
+ files: [KNOWN_HOSTED_IMAGE_URL],
163
+ })
161
164
  .then(async (message) => {
162
165
  validateMessage(message);
163
166
  const event = await created;
164
167
 
165
168
  validateMessageEvent(event, message, actor);
166
- }));
169
+ })
170
+ );
167
171
  });
168
172
 
169
173
  let blob, buffer;
170
174
  const text = 'A File';
171
175
 
172
- browserOnly(before)(() => fh.fetch('sample-image-small-one.png')
173
- .then((file) => {
176
+ browserOnly(before)(() =>
177
+ fh.fetch('sample-image-small-one.png').then((file) => {
174
178
  blob = file;
175
179
 
176
180
  return new Promise((resolve) => {
@@ -183,46 +187,58 @@ describe('plugin-messages', function () {
183
187
  };
184
188
  fileReader.readAsArrayBuffer(blob);
185
189
  });
186
- }));
190
+ })
191
+ );
187
192
 
188
- nodeOnly(before)(() => fh.fetchWithoutMagic('sample-image-small-one.png')
189
- .then((file) => {
193
+ nodeOnly(before)(() =>
194
+ fh.fetchWithoutMagic('sample-image-small-one.png').then((file) => {
190
195
  buffer = file;
191
- }));
192
-
193
- browserOnly(it)('posts a file to a room by directly supplying its blob and validates the event', () => {
194
- const created = new Promise((resolve) => {
195
- webex.messages.on('created', (event) => {
196
- debug('message created event called');
197
- resolve(event);
196
+ })
197
+ );
198
+
199
+ browserOnly(it)(
200
+ 'posts a file to a room by directly supplying its blob and validates the event',
201
+ () => {
202
+ const created = new Promise((resolve) => {
203
+ webex.messages.on('created', (event) => {
204
+ debug('message created event called');
205
+ resolve(event);
206
+ });
198
207
  });
199
- });
200
208
 
201
- return webex.messages.listen()
202
- .then(() => webex.messages.create({
203
- roomId: room.id,
204
- files: [blob],
205
- text
206
- })
207
- .then(async (message) => {
208
- validateMessage(message);
209
- const event = await created;
209
+ return webex.messages.listen().then(() =>
210
+ webex.messages
211
+ .create({
212
+ roomId: room.id,
213
+ files: [blob],
214
+ text,
215
+ })
216
+ .then(async (message) => {
217
+ validateMessage(message);
218
+ const event = await created;
210
219
 
211
- validateMessageEvent(event, message, actor);
212
- }));
213
- });
220
+ validateMessageEvent(event, message, actor);
221
+ })
222
+ );
223
+ }
224
+ );
214
225
 
215
226
  // Disabling it gating pipelines because it failes a lot and we get
216
227
  // mostly adequate coverage via blob upload
217
- flaky(it, process.env.SKIP_FLAKY_TESTS)('posts a file to a room by directly supplying its buffer and validates the event', () => webex.messages.create({
218
- roomId: room.id,
219
- files: [buffer]
220
- })
221
- .then((message) => {
222
- validateMessage(message, '', 1);
223
- }));
228
+ flaky(it, process.env.SKIP_FLAKY_TESTS)(
229
+ 'posts a file to a room by directly supplying its buffer and validates the event',
230
+ () =>
231
+ webex.messages
232
+ .create({
233
+ roomId: room.id,
234
+ files: [buffer],
235
+ })
236
+ .then((message) => {
237
+ validateMessage(message, '', 1);
238
+ })
239
+ );
224
240
 
225
- it('posts a file with a message to a room by specifying the file\'s url and validates the event', () => {
241
+ it("posts a file with a message to a room by specifying the file's url and validates the event", () => {
226
242
  const created = new Promise((resolve) => {
227
243
  webex.messages.on('created', (event) => {
228
244
  debug('message created event called');
@@ -230,12 +246,13 @@ describe('plugin-messages', function () {
230
246
  });
231
247
  });
232
248
 
233
- return webex.messages.listen()
234
- .then(() => webex.messages.create({
235
- roomId: room.id,
236
- files: [KNOWN_HOSTED_IMAGE_URL],
237
- text
238
- })
249
+ return webex.messages.listen().then(() =>
250
+ webex.messages
251
+ .create({
252
+ roomId: room.id,
253
+ files: [KNOWN_HOSTED_IMAGE_URL],
254
+ text,
255
+ })
239
256
  .then(async (message) => {
240
257
  validateMessage(message);
241
258
  let event = await created;
@@ -257,7 +274,8 @@ describe('plugin-messages', function () {
257
274
  }
258
275
 
259
276
  validateMessageEvent(event, message, actor);
260
- }));
277
+ })
278
+ );
261
279
  });
262
280
 
263
281
  it('posts a message to a card to a room validates the event', () => {
@@ -275,23 +293,24 @@ describe('plugin-messages', function () {
275
293
  body: [
276
294
  {
277
295
  type: 'TextBlock',
278
- text: 'Here is an image'
296
+ text: 'Here is an image',
279
297
  },
280
298
  {
281
299
  type: 'Image',
282
300
  url: KNOWN_HOSTED_IMAGE_URL,
283
- size: 'small'
284
- }
285
- ]
286
- }
301
+ size: 'small',
302
+ },
303
+ ],
304
+ },
287
305
  };
288
306
 
289
- return webex.messages.listen()
290
- .then(() => webex.messages.create({
291
- roomId: room.id,
292
- text,
293
- attachments: [attachment]
294
- })
307
+ return webex.messages.listen().then(() =>
308
+ webex.messages
309
+ .create({
310
+ roomId: room.id,
311
+ text,
312
+ attachments: [attachment],
313
+ })
295
314
  .then(async (message) => {
296
315
  // // Assert that the message shape is valid and contains attachment data.
297
316
  validateMessage(message, text, 0, attachment);
@@ -314,7 +333,8 @@ describe('plugin-messages', function () {
314
333
  }
315
334
 
316
335
  validateMessageEvent(event, message, actor);
317
- }));
336
+ })
337
+ );
318
338
  });
319
339
  });
320
340
 
@@ -322,14 +342,17 @@ describe('plugin-messages', function () {
322
342
  let message;
323
343
  const text = 'This message will be deleted';
324
344
 
325
- beforeEach(() => webex.messages.create({
326
- roomId: room.id,
327
- text
328
- })
329
- .then((m) => {
330
- message = m;
331
- validateMessage(m, text);
332
- }));
345
+ beforeEach(() =>
346
+ webex.messages
347
+ .create({
348
+ roomId: room.id,
349
+ text,
350
+ })
351
+ .then((m) => {
352
+ message = m;
353
+ validateMessage(m, text);
354
+ })
355
+ );
333
356
 
334
357
  it('deletes a single message and validates the message:deleted event', () => {
335
358
  const deleted = new Promise((resolve) => {
@@ -339,8 +362,9 @@ describe('plugin-messages', function () {
339
362
  });
340
363
  });
341
364
 
342
- return webex.messages.listen()
343
- .then(() => webex.messages.remove(message)
365
+ return webex.messages.listen().then(() =>
366
+ webex.messages
367
+ .remove(message)
344
368
  .then((body) => {
345
369
  assert.notOk(body);
346
370
 
@@ -351,7 +375,8 @@ describe('plugin-messages', function () {
351
375
  const event = await deleted;
352
376
 
353
377
  validateMessageEvent(event, message, actor);
354
- }));
378
+ })
379
+ );
355
380
  });
356
381
  });
357
382
 
@@ -365,39 +390,50 @@ describe('plugin-messages', function () {
365
390
  webex.messages.off('created');
366
391
  webex.messages.off('deleted');
367
392
 
368
- return webex.messages.create({
369
- roomId: room.id,
370
- text
371
- })
393
+ return webex.messages
394
+ .create({
395
+ roomId: room.id,
396
+ text,
397
+ })
372
398
  .then((m) => {
373
399
  message = m;
374
400
  validateMessage(message, text);
375
401
  });
376
402
  });
377
403
 
378
- it('returns a single message', () => webex.messages.get(message)
379
- .then((m) => {
404
+ it('returns a single message', () =>
405
+ webex.messages.get(message).then((m) => {
380
406
  assert.isMessage(m);
381
407
  assert.deepEqual(m, message);
382
408
  }));
383
409
  });
384
410
 
385
-
386
411
  describe('#list()', () => {
387
- before(() => webex.rooms.create({
388
- title: 'Room List Test'
389
- })
390
- .then((r) => {
391
- room = r;
392
- }));
393
-
394
- before(() => [1, 2, 3].reduce((promise, value) => promise.then(() => webex.messages.create({
395
- roomId: room.id,
396
- text: `message: ${value}`
397
- })), Promise.resolve()));
398
-
399
- it('returns all messages for a room', () => webex.messages.list({roomId: room.id})
400
- .then((messages) => {
412
+ before(() =>
413
+ webex.rooms
414
+ .create({
415
+ title: 'Room List Test',
416
+ })
417
+ .then((r) => {
418
+ room = r;
419
+ })
420
+ );
421
+
422
+ before(() =>
423
+ [1, 2, 3].reduce(
424
+ (promise, value) =>
425
+ promise.then(() =>
426
+ webex.messages.create({
427
+ roomId: room.id,
428
+ text: `message: ${value}`,
429
+ })
430
+ ),
431
+ Promise.resolve()
432
+ )
433
+ );
434
+
435
+ it('returns all messages for a room', () =>
436
+ webex.messages.list({roomId: room.id}).then((messages) => {
401
437
  assert.isDefined(messages);
402
438
  assert.lengthOf(messages, 3);
403
439
  for (const message of messages) {
@@ -408,7 +444,8 @@ describe('plugin-messages', function () {
408
444
  it('returns a bounded set of messages for a room', () => {
409
445
  const spy = sinon.spy();
410
446
 
411
- return webex.messages.list({roomId: room.id, max: 2})
447
+ return webex.messages
448
+ .list({roomId: room.id, max: 2})
412
449
  .then((messages) => {
413
450
  assert.lengthOf(messages, 2);
414
451
 
@@ -422,7 +459,7 @@ describe('plugin-messages', function () {
422
459
  }
423
460
 
424
461
  return Promise.resolve();
425
- }(messages));
462
+ })(messages);
426
463
  })
427
464
  .then(() => {
428
465
  assert.calledThrice(spy);
@@ -432,12 +469,15 @@ describe('plugin-messages', function () {
432
469
  describe('when a message is threaded', () => {
433
470
  let parentId;
434
471
 
435
- before(() => webex.rooms.create({
436
- title: 'Room List Test'
437
- })
438
- .then((r) => {
439
- room = r;
440
- }));
472
+ before(() =>
473
+ webex.rooms
474
+ .create({
475
+ title: 'Room List Test',
476
+ })
477
+ .then((r) => {
478
+ room = r;
479
+ })
480
+ );
441
481
 
442
482
  before(() => {
443
483
  const createdParent = new Promise((resolve) => {
@@ -447,11 +487,12 @@ describe('plugin-messages', function () {
447
487
  });
448
488
  });
449
489
 
450
- return webex.messages.listen()
451
- .then(() => webex.messages.create({
452
- roomId: room.id,
453
- text: 'This is the parent message'
454
- })
490
+ return webex.messages.listen().then(() =>
491
+ webex.messages
492
+ .create({
493
+ roomId: room.id,
494
+ text: 'This is the parent message',
495
+ })
455
496
  .then(async (message) => {
456
497
  parentId = message.id;
457
498
 
@@ -466,22 +507,24 @@ describe('plugin-messages', function () {
466
507
  });
467
508
  });
468
509
 
469
- return webex.messages.create({
470
- roomId: room.id,
471
- text: 'This is the reply',
472
- parentId
473
- })
510
+ return webex.messages
511
+ .create({
512
+ roomId: room.id,
513
+ text: 'This is the reply',
514
+ parentId,
515
+ })
474
516
  .then(async (message2) => {
475
517
  validateMessage(message2);
476
518
  const event2 = await createdReply;
477
519
 
478
520
  return Promise.resolve(validateMessageEvent(event2, message2, actor));
479
521
  });
480
- }));
522
+ })
523
+ );
481
524
  });
482
525
 
483
- it('returns all messages for a room', () => webex.messages.list({roomId: room.id})
484
- .then((messages) => {
526
+ it('returns all messages for a room', () =>
527
+ webex.messages.list({roomId: room.id}).then((messages) => {
485
528
  assert.isDefined(messages);
486
529
  assert.lengthOf(messages.items, 2);
487
530
  for (const message of messages.items) {
@@ -492,8 +535,8 @@ describe('plugin-messages', function () {
492
535
  }
493
536
  }));
494
537
 
495
- it('returns only the replies for particular message thread', () => webex.messages.list({roomId: room.id, parentId})
496
- .then((messages) => {
538
+ it('returns only the replies for particular message thread', () =>
539
+ webex.messages.list({roomId: room.id, parentId}).then((messages) => {
497
540
  assert.lengthOf(messages.items, 1);
498
541
  const message = messages.items[0];
499
542
 
@@ -505,7 +548,6 @@ describe('plugin-messages', function () {
505
548
  });
506
549
  });
507
550
 
508
-
509
551
  /**
510
552
  * Validate a Message object.
511
553
  * @param {Object} message
@@ -572,30 +614,21 @@ function validateAdaptiveCard(message, attachment) {
572
614
  * @returns {void}
573
615
  */
574
616
  function validateMessageEvent(event, message, actor) {
575
- assert.equal(event.resource, SDK_EVENT.EXTERNAL.RESOURCE.MESSAGES,
576
- 'not a message event');
617
+ assert.equal(event.resource, SDK_EVENT.EXTERNAL.RESOURCE.MESSAGES, 'not a message event');
577
618
  assert.isDefined(event.event, 'message event type not set');
578
619
  assert.isDefined(event.created, 'event listener created date not set');
579
- assert.equal(event.createdBy, actor.id,
580
- 'event listener createdBy not set to our actor');
581
- assert.equal(event.orgId, actor.orgId,
582
- 'event listener orgId not === to our actor\'s');
620
+ assert.equal(event.createdBy, actor.id, 'event listener createdBy not set to our actor');
621
+ assert.equal(event.orgId, actor.orgId, "event listener orgId not === to our actor's");
583
622
  assert.equal(event.ownedBy, 'creator', 'event listener not owned by creator');
584
623
  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');
624
+ assert.equal(event.actorId, actor.id, "event actorId not equal to our actor's id");
587
625
 
588
626
  // Ensure event data matches data returned from function call
589
- assert.equal(event.data.id, message.id,
590
- 'event/message.id not equal');
591
- assert.equal(event.data.roomId, message.roomId,
592
- 'event/message.roomId not equal');
593
- assert.equal(event.data.personId, message.personId,
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');
627
+ assert.equal(event.data.id, message.id, 'event/message.id not equal');
628
+ assert.equal(event.data.roomId, message.roomId, 'event/message.roomId not equal');
629
+ assert.equal(event.data.personId, message.personId, 'event/message.personId not equal');
630
+ assert.equal(event.data.personEmail, message.personEmail, 'event/message.personEmail not equal');
631
+ assert.equal(event.data.roomType, message.roomType, 'event/message.roomType not equal');
599
632
  if (event.event === SDK_EVENT.EXTERNAL.EVENT_TYPE.DELETED) {
600
633
  return;
601
634
  }
@@ -605,14 +638,19 @@ function validateMessageEvent(event, message, actor) {
605
638
  if (message.files) {
606
639
  assert.isArray(event.data.files, 'event.data.files is not array');
607
640
  assert.isArray(message.files, 'message.files is not array');
608
- assert.equal(event.data.files.length, message.files.length,
609
- 'event/message file arrays are different lengths');
641
+ assert.equal(
642
+ event.data.files.length,
643
+ message.files.length,
644
+ 'event/message file arrays are different lengths'
645
+ );
610
646
  for (let i = 0; i < message.files.length; i += 1) {
611
647
  // The gateway returned by the API is apialpha.ciscospark.com
612
648
  // The gateway returned in the event is api.ciscospark.com -- expected?
613
- assert.equal(event.data.files[i].substr(event.data.files[i].lastIndexOf('/') + 1),
649
+ assert.equal(
650
+ event.data.files[i].substr(event.data.files[i].lastIndexOf('/') + 1),
614
651
  message.files[i].substr(message.files[i].lastIndexOf('/') + 1),
615
- 'event/message file urls do not match');
652
+ 'event/message file urls do not match'
653
+ );
616
654
  }
617
655
  }
618
656
  if (message.attachments) {