@webex/plugin-messages 3.0.0-beta.9 → 3.0.0-bnr.2

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.9"
376
+ version: "3.0.0-bnr.2"
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;EACl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A8BO,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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;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,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,CA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UACJX,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"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Messages are how people communicate in rooms. Each message timestamped and
3
+ * represented in Webex as a distinct block of content. Messages can contain
4
+ * plain text and a single file attachment. See the
5
+ * {@link https://developer.webex.com/docs/api/basics#message-attachments|Message Attachments} Guide
6
+ * for a list of supported media types.
7
+ * @class
8
+ */
9
+ declare const Messages: any;
10
+ export default Messages;
11
+
12
+ export { }
@@ -0,0 +1,11 @@
1
+ // This file is read by tools that parse documentation comments conforming to the TSDoc standard.
2
+ // It should be published with your NPM package. It should not be tracked by Git.
3
+ {
4
+ "tsdocVersion": "0.12",
5
+ "toolPackages": [
6
+ {
7
+ "packageName": "@microsoft/api-extractor",
8
+ "packageVersion": "7.34.4"
9
+ }
10
+ ]
11
+ }
@@ -0,0 +1,2 @@
1
+ export default Messages;
2
+ import Messages from "./messages";
@@ -0,0 +1,58 @@
1
+ export default Messages;
2
+ export type MessageObject = {
3
+ /**
4
+ * - (server generated) Unique identifier for the message
5
+ */
6
+ id: string;
7
+ /**
8
+ * - The ID for the author of the message
9
+ */
10
+ personId: string;
11
+ /**
12
+ * - The email for the author of the message
13
+ */
14
+ personEmail: email;
15
+ /**
16
+ * - The ID for the room of the message
17
+ */
18
+ roomId: string;
19
+ /**
20
+ * - The message posted to the room in plain text
21
+ */
22
+ text: string;
23
+ /**
24
+ * - The message posted to the room in markdown
25
+ */
26
+ markdown: string;
27
+ /**
28
+ * - The source URL(s) for the message attachment(s).
29
+ * See the {@link https://developer.webex.com/docs/api/basics#message-attachments|Message Attachments}Guide for a list of supported media types.
30
+ */
31
+ files: Array<string>;
32
+ /**
33
+ * - (server generated) The date and time that the message was created
34
+ */
35
+ created: isoDate;
36
+ };
37
+ /**
38
+ * @typedef {Object} MessageObject
39
+ * @property {string} id - (server generated) Unique identifier for the message
40
+ * @property {string} personId - The ID for the author of the message
41
+ * @property {email} personEmail - The email for the author of the message
42
+ * @property {string} roomId - The ID for the room of the message
43
+ * @property {string} text - The message posted to the room in plain text
44
+ * @property {string} markdown - The message posted to the room in markdown
45
+ * @property {Array<string>} files - The source URL(s) for the message attachment(s).
46
+ * See the {@link https://developer.webex.com/docs/api/basics#message-attachments|Message Attachments}
47
+ * Guide for a list of supported media types.
48
+ * @property {isoDate} created - (server generated) The date and time that the message was created
49
+ */
50
+ /**
51
+ * Messages are how people communicate in rooms. Each message timestamped and
52
+ * represented in Webex as a distinct block of content. Messages can contain
53
+ * plain text and a single file attachment. See the
54
+ * {@link https://developer.webex.com/docs/api/basics#message-attachments|Message Attachments} Guide
55
+ * for a list of supported media types.
56
+ * @class
57
+ */
58
+ declare const Messages: any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webex/plugin-messages",
3
- "version": "3.0.0-beta.9",
3
+ "version": "3.0.0-bnr.2",
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.9",
24
- "@webex/test-helper-file": "3.0.0-beta.9",
25
- "@webex/test-helper-mocha": "3.0.0-beta.9",
26
- "@webex/test-helper-test-users": "3.0.0-beta.9",
23
+ "@webex/test-helper-chai": "3.0.0-bnr.2",
24
+ "@webex/test-helper-file": "3.0.0-bnr.2",
25
+ "@webex/test-helper-mocha": "3.0.0-bnr.2",
26
+ "@webex/test-helper-test-users": "3.0.0-bnr.2",
27
27
  "sinon": "^9.2.4"
28
28
  },
29
29
  "dependencies": {
30
- "@webex/common": "3.0.0-beta.9",
31
- "@webex/internal-plugin-conversation": "3.0.0-beta.9",
32
- "@webex/internal-plugin-device": "3.0.0-beta.9",
33
- "@webex/internal-plugin-mercury": "3.0.0-beta.9",
34
- "@webex/plugin-logger": "3.0.0-beta.9",
35
- "@webex/plugin-messages": "3.0.0-beta.9",
36
- "@webex/plugin-people": "3.0.0-beta.9",
37
- "@webex/plugin-rooms": "3.0.0-beta.9",
38
- "@webex/webex-core": "3.0.0-beta.9",
30
+ "@webex/common": "3.0.0-bnr.2",
31
+ "@webex/internal-plugin-conversation": "3.0.0-bnr.2",
32
+ "@webex/internal-plugin-device": "3.0.0-bnr.2",
33
+ "@webex/internal-plugin-mercury": "3.0.0-bnr.2",
34
+ "@webex/plugin-logger": "3.0.0-bnr.2",
35
+ "@webex/plugin-messages": "3.0.0-bnr.2",
36
+ "@webex/plugin-people": "3.0.0-bnr.2",
37
+ "@webex/plugin-rooms": "3.0.0-bnr.2",
38
+ "@webex/webex-core": "3.0.0-bnr.2",
39
39
  "debug": "^4.3.4",
40
40
  "lodash": "^4.17.21"
41
41
  }