@webex/plugin-messages 3.0.0-bnr.5 → 3.0.0
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/.eslintrc.js +6 -0
- package/babel.config.js +3 -0
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/messages.js +76 -11
- package/dist/messages.js.map +1 -1
- package/jest.config.js +3 -0
- package/package.json +32 -16
- package/process +1 -0
- package/src/messages.js +77 -0
- package/test/integration/spec/messages.js +104 -15
- package/dist/plugin-messages.d.ts +0 -12
- package/dist/tsdoc-metadata.json +0 -11
- package/dist/types/index.d.ts +0 -2
- package/dist/types/messages.d.ts +0 -58
package/.eslintrc.js
ADDED
package/babel.config.js
ADDED
package/dist/index.js
CHANGED
|
@@ -17,6 +17,5 @@ var _messages = _interopRequireDefault(require("./messages"));
|
|
|
17
17
|
// decrypt mercury activities
|
|
18
18
|
|
|
19
19
|
(0, _webexCore.registerPlugin)('messages', _messages.default);
|
|
20
|
-
var _default = _messages.default;
|
|
21
|
-
exports.default = _default;
|
|
20
|
+
var _default = exports.default = _messages.default;
|
|
22
21
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["registerPlugin","Messages"],"sources":["index.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport '@webex/internal-plugin-conversation'; // decrypt mercury activities\nimport '@webex/internal-plugin-mercury';\n\nimport {registerPlugin} from '@webex/webex-core';\n\nimport Messages from './messages';\n\nregisterPlugin('messages', Messages);\n\nexport default Messages;\n"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"names":["require","_webexCore","_messages","_interopRequireDefault","registerPlugin","Messages","_default","exports","default"],"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":";;;;;;;;AAIAA,OAAA;AACAA,OAAA;AAEA,IAAAC,UAAA,GAAAD,OAAA;AAEA,IAAAE,SAAA,GAAAC,sBAAA,CAAAH,OAAA;AATA;AACA;AACA;;AAE8C;;AAO9C,IAAAI,yBAAc,EAAC,UAAU,EAAEC,iBAAQ,CAAC;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEtBH,iBAAQ"}
|
package/dist/messages.js
CHANGED
|
@@ -15,14 +15,14 @@ var _apply = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/refl
|
|
|
15
15
|
var _deleteProperty = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/reflect/delete-property"));
|
|
16
16
|
var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
|
|
17
17
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty"));
|
|
18
|
-
var _isArray2 = _interopRequireDefault(require("lodash/isArray"));
|
|
19
|
-
var _cloneDeep2 = _interopRequireDefault(require("lodash/cloneDeep"));
|
|
20
18
|
var _common = require("@webex/common");
|
|
21
19
|
var _webexCore = require("@webex/webex-core");
|
|
22
|
-
var
|
|
23
|
-
function ownKeys(
|
|
24
|
-
function _objectSpread(
|
|
25
|
-
|
|
20
|
+
var _lodash = require("lodash");
|
|
21
|
+
function ownKeys(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
22
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; } /*!
|
|
23
|
+
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
24
|
+
*/
|
|
25
|
+
var verbToType = (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({}, _common.SDK_EVENT.INTERNAL.ACTIVITY_VERB.SHARE, _common.SDK_EVENT.EXTERNAL.EVENT_TYPE.CREATED), _common.SDK_EVENT.INTERNAL.ACTIVITY_VERB.POST, _common.SDK_EVENT.EXTERNAL.EVENT_TYPE.CREATED), _common.SDK_EVENT.INTERNAL.ACTIVITY_VERB.DELETE, _common.SDK_EVENT.EXTERNAL.EVENT_TYPE.DELETED);
|
|
26
26
|
var getRoomType = function getRoomType(roomTags) {
|
|
27
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;
|
|
28
28
|
};
|
|
@@ -143,7 +143,7 @@ var Messages = _webexCore.WebexPlugin.extend({
|
|
|
143
143
|
message.files = [message.file];
|
|
144
144
|
(0, _deleteProperty.default)(message, 'file');
|
|
145
145
|
}
|
|
146
|
-
if ((0,
|
|
146
|
+
if ((0, _lodash.isArray)(message.files) && message.files.reduce(function (type, file) {
|
|
147
147
|
return type || typeof file !== 'string';
|
|
148
148
|
}, false)) {
|
|
149
149
|
key = 'formData';
|
|
@@ -157,6 +157,72 @@ var Messages = _webexCore.WebexPlugin.extend({
|
|
|
157
157
|
return res.body;
|
|
158
158
|
});
|
|
159
159
|
},
|
|
160
|
+
/**
|
|
161
|
+
* Put an updated message and/or media content into a room instead of existing message.
|
|
162
|
+
* @instance
|
|
163
|
+
* @memberof Messages
|
|
164
|
+
* @param {MessageObject} message
|
|
165
|
+
* @param {MessageObject} altMessage
|
|
166
|
+
* @returns {Promise<MessageObject>}
|
|
167
|
+
* @example
|
|
168
|
+
* webex.rooms.create({title: 'Create Message Example'})
|
|
169
|
+
* .then(function(room) {
|
|
170
|
+
* return webex.messages.create({
|
|
171
|
+
* text: 'Howdy!',
|
|
172
|
+
* roomId: room.id
|
|
173
|
+
* });
|
|
174
|
+
* })
|
|
175
|
+
* .then(function(m) {
|
|
176
|
+
* message = m;
|
|
177
|
+
* return webex.messages.update(message,{markdown:`**What up**`});
|
|
178
|
+
* })
|
|
179
|
+
* .then(function(m) {
|
|
180
|
+
* message = m;
|
|
181
|
+
* return webex.messages.update(message.id,{roomId:message.roomId,text:'Howdy!'});
|
|
182
|
+
* })
|
|
183
|
+
* .then(function(message) {
|
|
184
|
+
* var assert = require('assert');
|
|
185
|
+
* assert(message.id);
|
|
186
|
+
* assert(message.personId);
|
|
187
|
+
* assert(message.personEmail);
|
|
188
|
+
* assert(message.roomId);
|
|
189
|
+
* assert(message.created);
|
|
190
|
+
* return 'success';
|
|
191
|
+
* });
|
|
192
|
+
* // => success
|
|
193
|
+
*/
|
|
194
|
+
update: function update(message, altMessage) {
|
|
195
|
+
var id = message.id || message;
|
|
196
|
+
var key = 'body';
|
|
197
|
+
if (message.file) {
|
|
198
|
+
this.logger.warn('Supplying a single `file` property is deprecated; please supply a `files` array');
|
|
199
|
+
message.files = [message.file];
|
|
200
|
+
(0, _deleteProperty.default)(message, 'file');
|
|
201
|
+
}
|
|
202
|
+
if (message.files && (0, _lodash.isArray)(message.files) && message.files.reduce(function (type, file) {
|
|
203
|
+
return type || typeof file !== 'string';
|
|
204
|
+
}, false)) {
|
|
205
|
+
key = 'formData';
|
|
206
|
+
}
|
|
207
|
+
if (!altMessage.roomId && !message.roomId) {
|
|
208
|
+
this.logger.error('Error: RoomID is mandatory for message update call in one of the parameter, message or altMessage');
|
|
209
|
+
} else {
|
|
210
|
+
/* if altMessage doesnt contain RoomId use roomId from message object.
|
|
211
|
+
I dont understand why RESTAPI call has RoomId Mandatory in body something webex Developers to clarity.
|
|
212
|
+
In my opinion messageId provided in REST URL call should be enough to get roomID at serverside
|
|
213
|
+
*/
|
|
214
|
+
altMessage.roomId = altMessage.roomId ? altMessage.roomId : message.roomId;
|
|
215
|
+
var options = (0, _defineProperty2.default)({
|
|
216
|
+
method: 'PUT',
|
|
217
|
+
service: 'hydra',
|
|
218
|
+
resource: 'messages/'.concat(id)
|
|
219
|
+
}, key, altMessage);
|
|
220
|
+
return this.request(options).then(function (res) {
|
|
221
|
+
return res.body;
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
return null;
|
|
225
|
+
},
|
|
160
226
|
/**
|
|
161
227
|
* Returns a single message.
|
|
162
228
|
* @instance
|
|
@@ -349,7 +415,7 @@ var Messages = _webexCore.WebexPlugin.extend({
|
|
|
349
415
|
roomUrl = _activity$target.url,
|
|
350
416
|
roomTags = _activity$target.tags;
|
|
351
417
|
var cluster = (0, _common.getHydraClusterString)(this.webex, roomUrl);
|
|
352
|
-
var combinedEvent = (0,
|
|
418
|
+
var combinedEvent = (0, _lodash.cloneDeep)(this.eventEnvelope);
|
|
353
419
|
combinedEvent.event = type;
|
|
354
420
|
if (type === _common.SDK_EVENT.EXTERNAL.EVENT_TYPE.DELETED) {
|
|
355
421
|
// Cannot fetch since the message is deleted
|
|
@@ -373,8 +439,7 @@ var Messages = _webexCore.WebexPlugin.extend({
|
|
|
373
439
|
});
|
|
374
440
|
});
|
|
375
441
|
},
|
|
376
|
-
version: "3.0.0
|
|
442
|
+
version: "3.0.0"
|
|
377
443
|
});
|
|
378
|
-
var _default = Messages;
|
|
379
|
-
exports.default = _default;
|
|
444
|
+
var _default = exports.default = Messages;
|
|
380
445
|
//# sourceMappingURL=messages.js.map
|
package/dist/messages.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["verbToType","SDK_EVENT","INTERNAL","ACTIVITY_VERB","SHARE","EXTERNAL","EVENT_TYPE","CREATED","POST","DELETE","DELETED","getRoomType","roomTags","includes","ACTIVITY_TAG","ONE_ON_ONE","SPACE_TYPE","DIRECT","GROUP","Messages","WebexPlugin","extend","initialize","args","prototype","listen","createEventEnvelope","webex","RESOURCE","MESSAGES","then","envelope","eventEnvelope","internal","mercury","connect","listenTo","WEBEX_ACTIVITY","event","onWebexApiEvent","create","message","key","file","logger","warn","files","reduce","type","options","method","service","resource","request","res","body","get","id","items","list","qs","Page","remove","statusCode","undefined","fire","trigger","activity","data","verb","getMessageEvent","actor","actorId","entryUUID","emailAddress","objectId","object","target","roomId","roomUrl","url","tags","cluster","getHydraClusterString","combinedEvent","personId","buildHydraPersonId","resolve","buildHydraMessageId","personEmail","buildHydraRoomId","roomType"],"sources":["messages.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {\n SDK_EVENT,\n buildHydraMessageId,\n buildHydraPersonId,\n buildHydraRoomId,\n createEventEnvelope,\n getHydraClusterString,\n} from '@webex/common';\nimport {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;AAC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AAO,EAAE,OAAO;MAChBC,QAAQ,EAAE;IAAU,GACnBV,GAAG,EAAGD,OAAO,CACf;IAED,OAAO,IAAI,CAACY,OAAO,CAACJ,OAAO,CAAC,CAACnB,IAAI,CAAC,UAACwB,GAAG;MAAA,OAAKA,GAAG,CAACC,IAAI;IAAA,EAAC;EACtD,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEC,GAAG,eAACf,OAAO,EAAE;IACX,IAAMgB,EAAE,GAAGhB,OAAO,CAACgB,EAAE,IAAIhB,OAAO;IAEhC,OAAO,IAAI,CAACY,OAAO,CAAC;MAClBF,OAAO,EAAE,OAAO;MAChBC,QAAQ,qBAAcK,EAAE;IAC1B,CAAC,CAAC,CAAC3B,IAAI,CAAC,UAACwB,GAAG;MAAA,OAAKA,GAAG,CAACC,IAAI,CAACG,KAAK,IAAIJ,GAAG,CAACC,IAAI;IAAA,EAAC;EAC9C,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEI,IAAI,gBAACV,OAAO,EAAE;IAAA;IACZ,OAAO,IAAI,CAACI,OAAO,CAAC;MAClBF,OAAO,EAAE,OAAO;MAChBC,QAAQ,EAAE,UAAU;MACpBQ,EAAE,EAAEX;IACN,CAAC,CAAC,CAACnB,IAAI,CAAC,UAACwB,GAAG;MAAA,OAAK,IAAIO,eAAI,CAACP,GAAG,EAAE,MAAI,CAAC3B,KAAK,CAAC;IAAA,EAAC;EAC7C,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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,CAAC;AAAC,eAEYjD,QAAQ;AAAA"}
|
|
1
|
+
{"version":3,"names":["_common","require","_webexCore","_lodash","ownKeys","e","r","t","_Object$keys","_Object$getOwnPropertySymbols","o","filter","_Object$getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","Object","forEach","_defineProperty2","default","_Object$getOwnPropertyDescriptors","_Object$defineProperties","_Object$defineProperty","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","_len","args","Array","_key","_apply","prototype","listen","_this","createEventEnvelope","webex","RESOURCE","MESSAGES","then","envelope","eventEnvelope","internal","mercury","connect","listenTo","WEBEX_ACTIVITY","event","onWebexApiEvent","create","message","key","file","logger","warn","files","_deleteProperty","isArray","reduce","type","options","method","service","resource","request","res","body","update","altMessage","id","roomId","error","concat","get","items","list","_this2","qs","Page","remove","statusCode","undefined","fire","_this3","trigger","_ref","activity","data","verb","getMessageEvent","_activity$actor","actor","actorId","entryUUID","emailAddress","objectId","object","_activity$target","target","roomUrl","url","tags","cluster","getHydraClusterString","combinedEvent","cloneDeep","personId","buildHydraPersonId","_promise","resolve","buildHydraMessageId","personEmail","buildHydraRoomId","roomType","version","_default","exports"],"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 * Put an updated message and/or media content into a room instead of existing message.\n * @instance\n * @memberof Messages\n * @param {MessageObject} message\n * @param {MessageObject} altMessage\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(m) {\n * message = m;\n * return webex.messages.update(message,{markdown:`**What up**`});\n * })\n * .then(function(m) {\n * message = m;\n * return webex.messages.update(message.id,{roomId:message.roomId,text:'Howdy!'});\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 update(message, altMessage) {\n const id = message.id || 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 message.files &&\n isArray(message.files) &&\n message.files.reduce((type, file) => type || typeof file !== 'string', false)\n ) {\n key = 'formData';\n }\n\n if (!altMessage.roomId && !message.roomId) {\n this.logger.error(\n 'Error: RoomID is mandatory for message update call in one of the parameter, message or altMessage'\n );\n } else {\n /* if altMessage doesnt contain RoomId use roomId from message object. \n I dont understand why RESTAPI call has RoomId Mandatory in body something webex Developers to clarity. \n In my opinion messageId provided in REST URL call should be enough to get roomID at serverside\n */\n altMessage.roomId = altMessage.roomId ? altMessage.roomId : message.roomId;\n\n const options = {\n method: 'PUT',\n service: 'hydra',\n resource: 'messages/'.concat(id),\n [key]: altMessage,\n };\n\n return this.request(options).then((res) => res.body);\n }\n\n return null;\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,IAAAA,OAAA,GAAAC,OAAA;AAQA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AAA0C,SAAAG,QAAAC,CAAA,EAAAC,CAAA,QAAAC,CAAA,GAAAC,YAAA,CAAAH,CAAA,OAAAI,6BAAA,QAAAC,CAAA,GAAAD,6BAAA,CAAAJ,CAAA,GAAAC,CAAA,KAAAI,CAAA,GAAAA,CAAA,CAAAC,MAAA,WAAAL,CAAA,WAAAM,gCAAA,CAAAP,CAAA,EAAAC,CAAA,EAAAO,UAAA,OAAAN,CAAA,CAAAO,IAAA,CAAAC,KAAA,CAAAR,CAAA,EAAAG,CAAA,YAAAH,CAAA;AAAA,SAAAS,cAAAX,CAAA,aAAAC,CAAA,MAAAA,CAAA,GAAAW,SAAA,CAAAC,MAAA,EAAAZ,CAAA,UAAAC,CAAA,WAAAU,SAAA,CAAAX,CAAA,IAAAW,SAAA,CAAAX,CAAA,QAAAA,CAAA,OAAAF,OAAA,CAAAe,MAAA,CAAAZ,CAAA,OAAAa,OAAA,WAAAd,CAAA,QAAAe,gBAAA,CAAAC,OAAA,EAAAjB,CAAA,EAAAC,CAAA,EAAAC,CAAA,CAAAD,CAAA,SAAAiB,iCAAA,GAAAC,wBAAA,CAAAnB,CAAA,EAAAkB,iCAAA,CAAAhB,CAAA,KAAAH,OAAA,CAAAe,MAAA,CAAAZ,CAAA,GAAAa,OAAA,WAAAd,CAAA,IAAAmB,sBAAA,CAAApB,CAAA,EAAAC,CAAA,EAAAM,g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A;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;EACES,IAAI,WAAAA,KAACf,OAAO,EAAE;IAAA,IAAAgB,MAAA;IACZ,OAAO,IAAI,CAACZ,OAAO,CAAC;MAClBF,OAAO,EAAE,OAAO;MAChBC,QAAQ,EAAE,UAAU;MACpBc,EAAE,EAAEjB;IACN,CAAC,CAAC,CAACrB,IAAI,CAAC,UAAC0B,GAAG;MAAA,OAAK,IAAIa,eAAI,CAACb,GAAG,EAAEW,MAAI,CAACxC,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;EACE2C,MAAM,WAAAA,OAAC7B,OAAO,EAAE;IACd,IAAMmB,EAAE,GAAGnB,OAAO,CAACmB,EAAE,IAAInB,OAAO;IAEhC,OAAO,IAAI,CAACc,OAAO,CAAC;MAClBH,MAAM,EAAE,QAAQ;MAChBC,OAAO,EAAE,OAAO;MAChBC,QAAQ,cAAAS,MAAA,CAAcH,EAAE;IAC1B,CAAC,CAAC,CAAC9B,IAAI,CAAC,UAAC0B,GAAG,EAAK;MACf;MACA;MACA,IAAIA,GAAG,CAACe,UAAU,KAAK,GAAG,EAAE;QAC1B,OAAOC,SAAS;MAClB;MAEA,OAAOhB,GAAG,CAACC,IAAI;IACjB,CAAC,CAAC;EACJ,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;AACA;EACEgB,IAAI,WAAAA,KAACvB,IAAI,EAAE;IAAA,IAAAwB,MAAA;IACT,OAAO,UAACpC,KAAK;MAAA,OAAKoC,MAAI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,CAACC,UAAU,CAACI,OAAO,EAAE;MAClD;MACA;MACA,IAAM4F,QAAQ,GAAG,IAAAC,0BAAkB,EAACf,OAAO,EAAEU,OAAO,CAAC;MAErD,OAAOM,QAAA,CAAA5G,OAAA,CAAQ6G,OAAO,CAAAnH,aAAA,CAAAA,aAAA,KACjB8G,aAAa;QAChBZ,OAAO,EAAEc,QAAQ;QACjBnB,IAAI,EAAE;UACJlB,EAAE,EAAE,IAAAyC,2BAAmB,EAACf,QAAQ,EAAEO,OAAO,CAAC;UAC1CS,WAAW,EAAEjB,YAAY,IAAIF,OAAO;UACpCc,QAAQ,EAARA,QAAQ;UACRpC,MAAM,EAAE,IAAA0C,wBAAgB,EAAC1C,MAAM,EAAEgC,OAAO,CAAC;UACzCW,QAAQ,EAAElG,WAAW,CAACC,QAAQ;QAChC;MAAC,EACF,CAAC;IACJ;IAEA,OAAO,IAAI,CAACyD,GAAG,CAAC,IAAAqC,2BAAmB,EAACzC,EAAE,EAAEiC,OAAO,CAAC,CAAC,CAAC/D,IAAI,CAAC,UAACgD,IAAI;MAAA,OAAA7F,aAAA,CAAAA,aAAA,KACvD8G,aAAa;QAChBZ,OAAO,EAAEL,IAAI,CAACmB,QAAQ;QACtBnB,IAAI,EAAJA;MAAI;IAAA,CACJ,CAAC;EACL,CAAC;EAAA2B,OAAA;AACH,CAAC,CAAC;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAApH,OAAA,GAEYuB,QAAQ"}
|
package/jest.config.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webex/plugin-messages",
|
|
3
|
-
"version": "3.0.0-bnr.5",
|
|
4
3
|
"description": "",
|
|
5
4
|
"license": "MIT",
|
|
6
5
|
"main": "dist/index.js",
|
|
@@ -20,23 +19,40 @@
|
|
|
20
19
|
]
|
|
21
20
|
},
|
|
22
21
|
"devDependencies": {
|
|
23
|
-
"@
|
|
24
|
-
"@webex/
|
|
25
|
-
"@webex/
|
|
26
|
-
"@webex/
|
|
22
|
+
"@babel/core": "^7.17.10",
|
|
23
|
+
"@webex/babel-config-legacy": "0.0.0",
|
|
24
|
+
"@webex/eslint-config-legacy": "0.0.0",
|
|
25
|
+
"@webex/jest-config-legacy": "0.0.0",
|
|
26
|
+
"@webex/legacy-tools": "0.0.0",
|
|
27
|
+
"@webex/test-helper-chai": "3.0.0",
|
|
28
|
+
"@webex/test-helper-file": "3.0.0",
|
|
29
|
+
"@webex/test-helper-mocha": "3.0.0",
|
|
30
|
+
"@webex/test-helper-mock-webex": "3.0.0",
|
|
31
|
+
"@webex/test-helper-test-users": "3.0.0",
|
|
32
|
+
"eslint": "^8.24.0",
|
|
33
|
+
"prettier": "^2.7.1",
|
|
27
34
|
"sinon": "^9.2.4"
|
|
28
35
|
},
|
|
29
36
|
"dependencies": {
|
|
30
|
-
"@webex/common": "3.0.0
|
|
31
|
-
"@webex/internal-plugin-conversation": "3.0.0
|
|
32
|
-
"@webex/internal-plugin-device": "3.0.0
|
|
33
|
-
"@webex/internal-plugin-mercury": "3.0.0
|
|
34
|
-
"@webex/plugin-logger": "3.0.0
|
|
35
|
-
"@webex/plugin-
|
|
36
|
-
"@webex/plugin-
|
|
37
|
-
"@webex/
|
|
38
|
-
"@webex/webex-core": "3.0.0-bnr.5",
|
|
37
|
+
"@webex/common": "3.0.0",
|
|
38
|
+
"@webex/internal-plugin-conversation": "3.0.0",
|
|
39
|
+
"@webex/internal-plugin-device": "3.0.0",
|
|
40
|
+
"@webex/internal-plugin-mercury": "3.0.0",
|
|
41
|
+
"@webex/plugin-logger": "3.0.0",
|
|
42
|
+
"@webex/plugin-people": "3.0.0",
|
|
43
|
+
"@webex/plugin-rooms": "3.0.0",
|
|
44
|
+
"@webex/webex-core": "3.0.0",
|
|
39
45
|
"debug": "^4.3.4",
|
|
40
46
|
"lodash": "^4.17.21"
|
|
41
|
-
}
|
|
42
|
-
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "yarn build:src",
|
|
50
|
+
"build:src": "webex-legacy-tools build -dest \"./dist\" -src \"./src\" -js -ts -maps",
|
|
51
|
+
"deploy:npm": "yarn npm publish",
|
|
52
|
+
"test": "yarn test:style && yarn test:unit && yarn test:integration && yarn test:browser",
|
|
53
|
+
"test:browser": "webex-legacy-tools test --integration --runner karma",
|
|
54
|
+
"test:integration": "webex-legacy-tools test --integration --runner mocha",
|
|
55
|
+
"test:style": "eslint ./src/**/*.*"
|
|
56
|
+
},
|
|
57
|
+
"version": "3.0.0"
|
|
58
|
+
}
|
package/process
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = {browser: true};
|
package/src/messages.js
CHANGED
|
@@ -160,6 +160,83 @@ const Messages = WebexPlugin.extend({
|
|
|
160
160
|
|
|
161
161
|
return this.request(options).then((res) => res.body);
|
|
162
162
|
},
|
|
163
|
+
/**
|
|
164
|
+
* Put an updated message and/or media content into a room instead of existing message.
|
|
165
|
+
* @instance
|
|
166
|
+
* @memberof Messages
|
|
167
|
+
* @param {MessageObject} message
|
|
168
|
+
* @param {MessageObject} altMessage
|
|
169
|
+
* @returns {Promise<MessageObject>}
|
|
170
|
+
* @example
|
|
171
|
+
* webex.rooms.create({title: 'Create Message Example'})
|
|
172
|
+
* .then(function(room) {
|
|
173
|
+
* return webex.messages.create({
|
|
174
|
+
* text: 'Howdy!',
|
|
175
|
+
* roomId: room.id
|
|
176
|
+
* });
|
|
177
|
+
* })
|
|
178
|
+
* .then(function(m) {
|
|
179
|
+
* message = m;
|
|
180
|
+
* return webex.messages.update(message,{markdown:`**What up**`});
|
|
181
|
+
* })
|
|
182
|
+
* .then(function(m) {
|
|
183
|
+
* message = m;
|
|
184
|
+
* return webex.messages.update(message.id,{roomId:message.roomId,text:'Howdy!'});
|
|
185
|
+
* })
|
|
186
|
+
* .then(function(message) {
|
|
187
|
+
* var assert = require('assert');
|
|
188
|
+
* assert(message.id);
|
|
189
|
+
* assert(message.personId);
|
|
190
|
+
* assert(message.personEmail);
|
|
191
|
+
* assert(message.roomId);
|
|
192
|
+
* assert(message.created);
|
|
193
|
+
* return 'success';
|
|
194
|
+
* });
|
|
195
|
+
* // => success
|
|
196
|
+
*/
|
|
197
|
+
update(message, altMessage) {
|
|
198
|
+
const id = message.id || message;
|
|
199
|
+
let key = 'body';
|
|
200
|
+
|
|
201
|
+
if (message.file) {
|
|
202
|
+
this.logger.warn(
|
|
203
|
+
'Supplying a single `file` property is deprecated; please supply a `files` array'
|
|
204
|
+
);
|
|
205
|
+
message.files = [message.file];
|
|
206
|
+
Reflect.deleteProperty(message, 'file');
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (
|
|
210
|
+
message.files &&
|
|
211
|
+
isArray(message.files) &&
|
|
212
|
+
message.files.reduce((type, file) => type || typeof file !== 'string', false)
|
|
213
|
+
) {
|
|
214
|
+
key = 'formData';
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (!altMessage.roomId && !message.roomId) {
|
|
218
|
+
this.logger.error(
|
|
219
|
+
'Error: RoomID is mandatory for message update call in one of the parameter, message or altMessage'
|
|
220
|
+
);
|
|
221
|
+
} else {
|
|
222
|
+
/* if altMessage doesnt contain RoomId use roomId from message object.
|
|
223
|
+
I dont understand why RESTAPI call has RoomId Mandatory in body something webex Developers to clarity.
|
|
224
|
+
In my opinion messageId provided in REST URL call should be enough to get roomID at serverside
|
|
225
|
+
*/
|
|
226
|
+
altMessage.roomId = altMessage.roomId ? altMessage.roomId : message.roomId;
|
|
227
|
+
|
|
228
|
+
const options = {
|
|
229
|
+
method: 'PUT',
|
|
230
|
+
service: 'hydra',
|
|
231
|
+
resource: 'messages/'.concat(id),
|
|
232
|
+
[key]: altMessage,
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
return this.request(options).then((res) => res.body);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return null;
|
|
239
|
+
},
|
|
163
240
|
|
|
164
241
|
/**
|
|
165
242
|
* Returns a single message.
|
|
@@ -7,19 +7,20 @@ import '@webex/plugin-logger';
|
|
|
7
7
|
import '@webex/plugin-rooms';
|
|
8
8
|
import '@webex/plugin-people';
|
|
9
9
|
import '@webex/plugin-messages';
|
|
10
|
-
import WebexCore, {WebexHttpError} from '@webex/webex-core';
|
|
11
|
-
import {SDK_EVENT} from '@webex/common';
|
|
12
|
-
import {assert} from '@webex/test-helper-chai';
|
|
10
|
+
import WebexCore, { WebexHttpError } from '@webex/webex-core';
|
|
11
|
+
import { SDK_EVENT } from '@webex/common';
|
|
12
|
+
import { assert } from '@webex/test-helper-chai';
|
|
13
13
|
import sinon from 'sinon';
|
|
14
14
|
import testUsers from '@webex/test-helper-test-users';
|
|
15
15
|
import fh from '@webex/test-helper-file';
|
|
16
|
-
import {browserOnly, flaky, nodeOnly} from '@webex/test-helper-mocha';
|
|
16
|
+
import { browserOnly, flaky, nodeOnly } from '@webex/test-helper-mocha';
|
|
17
17
|
|
|
18
18
|
const debug = require('debug')('messages');
|
|
19
19
|
|
|
20
20
|
const KNOWN_HOSTED_IMAGE_URL = 'https://download.ciscospark.com/test/photo.png';
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
// SPARK-413317
|
|
23
|
+
describe.skip('plugin-messages', function () {
|
|
23
24
|
this.timeout(60000);
|
|
24
25
|
|
|
25
26
|
let webex;
|
|
@@ -29,14 +30,14 @@ describe('plugin-messages', function () {
|
|
|
29
30
|
|
|
30
31
|
before(() =>
|
|
31
32
|
Promise.all([
|
|
32
|
-
testUsers.create({count: 1}),
|
|
33
|
-
testUsers.create({count: 1, config: {orgId: process.env.EU_PRIMARY_ORG_ID}}),
|
|
33
|
+
testUsers.create({ count: 1 }),
|
|
34
|
+
testUsers.create({ count: 1, config: { orgId: process.env.EU_PRIMARY_ORG_ID } }),
|
|
34
35
|
]).then(([user, usersEU]) => {
|
|
35
36
|
[actor] = user;
|
|
36
37
|
[actorEU] = usersEU;
|
|
37
38
|
|
|
38
|
-
webex = new WebexCore({credentials: actor.token});
|
|
39
|
-
webexEU = new WebexCore({credentials: actorEU.token});
|
|
39
|
+
webex = new WebexCore({ credentials: actor.token });
|
|
40
|
+
webexEU = new WebexCore({ credentials: actorEU.token });
|
|
40
41
|
|
|
41
42
|
webex.people.get('me').then((person) => {
|
|
42
43
|
actor = person;
|
|
@@ -54,8 +55,8 @@ describe('plugin-messages', function () {
|
|
|
54
55
|
|
|
55
56
|
before(() =>
|
|
56
57
|
Promise.all([
|
|
57
|
-
webex.rooms.create({title: 'Webex Test Room'}),
|
|
58
|
-
webexEU.rooms.create({title: 'Webex Test Room for EU'}),
|
|
58
|
+
webex.rooms.create({ title: 'Webex Test Room' }),
|
|
59
|
+
webexEU.rooms.create({ title: 'Webex Test Room for EU' }),
|
|
59
60
|
]).then(([r, rEU]) => {
|
|
60
61
|
room = r;
|
|
61
62
|
roomEU = rEU;
|
|
@@ -337,6 +338,94 @@ describe('plugin-messages', function () {
|
|
|
337
338
|
);
|
|
338
339
|
});
|
|
339
340
|
});
|
|
341
|
+
describe('#update()', () => {
|
|
342
|
+
it('update a message in a room and validates the messages:update event, params message and altMessage objects', () => {
|
|
343
|
+
let message;
|
|
344
|
+
const text = 'This message will be updated';
|
|
345
|
+
|
|
346
|
+
beforeEach(() =>
|
|
347
|
+
webex.messages
|
|
348
|
+
.create({
|
|
349
|
+
roomId: room.id,
|
|
350
|
+
text,
|
|
351
|
+
})
|
|
352
|
+
.then((m) => {
|
|
353
|
+
message = m;
|
|
354
|
+
validateMessage(m, text);
|
|
355
|
+
})
|
|
356
|
+
);
|
|
357
|
+
|
|
358
|
+
// "Block" this test with a promise that will
|
|
359
|
+
// resolve after the messages:created arrives.
|
|
360
|
+
const updated = new Promise((resolve) => {
|
|
361
|
+
webex.messages.on('updated', (event) => {
|
|
362
|
+
debug('message updated event called');
|
|
363
|
+
resolve(event);
|
|
364
|
+
});
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
text = 'This is updated message';
|
|
368
|
+
|
|
369
|
+
return webex.messages.listen().then(() =>
|
|
370
|
+
webex.messages
|
|
371
|
+
.update({
|
|
372
|
+
message: message,
|
|
373
|
+
altMessage: { text: text },
|
|
374
|
+
})
|
|
375
|
+
.then(async (m) => {
|
|
376
|
+
message = m;
|
|
377
|
+
validateMessage(message, text);
|
|
378
|
+
const event = await updated;
|
|
379
|
+
|
|
380
|
+
validateMessageEvent(event, message, actor);
|
|
381
|
+
})
|
|
382
|
+
);
|
|
383
|
+
});
|
|
384
|
+
it('update a message in a room and validates the messages:update event, parameter messageId, and altMessage with text and roomId', () => {
|
|
385
|
+
let message;
|
|
386
|
+
const text = 'This message will be updated';
|
|
387
|
+
|
|
388
|
+
beforeEach(() =>
|
|
389
|
+
webex.messages
|
|
390
|
+
.create({
|
|
391
|
+
roomId: room.id,
|
|
392
|
+
text,
|
|
393
|
+
})
|
|
394
|
+
.then((m) => {
|
|
395
|
+
message = m;
|
|
396
|
+
validateMessage(m, text);
|
|
397
|
+
})
|
|
398
|
+
);
|
|
399
|
+
|
|
400
|
+
// "Block" this test with a promise that will
|
|
401
|
+
// resolve after the messages:created arrives.
|
|
402
|
+
const updated = new Promise((resolve) => {
|
|
403
|
+
webex.messages.on('updated', (event) => {
|
|
404
|
+
debug('message updated event called');
|
|
405
|
+
resolve(event);
|
|
406
|
+
});
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
text = 'This is updated message';
|
|
410
|
+
|
|
411
|
+
return webex.messages.listen().then(() =>
|
|
412
|
+
webex.messages
|
|
413
|
+
.update({
|
|
414
|
+
message: message.id,
|
|
415
|
+
altMessage: {
|
|
416
|
+
roomId: room.id,
|
|
417
|
+
text: text
|
|
418
|
+
},
|
|
419
|
+
})
|
|
420
|
+
.then(async (m) => {
|
|
421
|
+
message = m;
|
|
422
|
+
validateMessage(message, text);
|
|
423
|
+
const event = await updated;
|
|
424
|
+
validateMessageEvent(event, message, actor);
|
|
425
|
+
})
|
|
426
|
+
);
|
|
427
|
+
});
|
|
428
|
+
});
|
|
340
429
|
|
|
341
430
|
describe('#remove()', () => {
|
|
342
431
|
let message;
|
|
@@ -433,7 +522,7 @@ describe('plugin-messages', function () {
|
|
|
433
522
|
);
|
|
434
523
|
|
|
435
524
|
it('returns all messages for a room', () =>
|
|
436
|
-
webex.messages.list({roomId: room.id}).then((messages) => {
|
|
525
|
+
webex.messages.list({ roomId: room.id }).then((messages) => {
|
|
437
526
|
assert.isDefined(messages);
|
|
438
527
|
assert.lengthOf(messages, 3);
|
|
439
528
|
for (const message of messages) {
|
|
@@ -445,7 +534,7 @@ describe('plugin-messages', function () {
|
|
|
445
534
|
const spy = sinon.spy();
|
|
446
535
|
|
|
447
536
|
return webex.messages
|
|
448
|
-
.list({roomId: room.id, max: 2})
|
|
537
|
+
.list({ roomId: room.id, max: 2 })
|
|
449
538
|
.then((messages) => {
|
|
450
539
|
assert.lengthOf(messages, 2);
|
|
451
540
|
|
|
@@ -524,7 +613,7 @@ describe('plugin-messages', function () {
|
|
|
524
613
|
});
|
|
525
614
|
|
|
526
615
|
it('returns all messages for a room', () =>
|
|
527
|
-
webex.messages.list({roomId: room.id}).then((messages) => {
|
|
616
|
+
webex.messages.list({ roomId: room.id }).then((messages) => {
|
|
528
617
|
assert.isDefined(messages);
|
|
529
618
|
assert.lengthOf(messages.items, 2);
|
|
530
619
|
for (const message of messages.items) {
|
|
@@ -536,7 +625,7 @@ describe('plugin-messages', function () {
|
|
|
536
625
|
}));
|
|
537
626
|
|
|
538
627
|
it('returns only the replies for particular message thread', () =>
|
|
539
|
-
webex.messages.list({roomId: room.id, parentId}).then((messages) => {
|
|
628
|
+
webex.messages.list({ roomId: room.id, parentId }).then((messages) => {
|
|
540
629
|
assert.lengthOf(messages.items, 1);
|
|
541
630
|
const message = messages.items[0];
|
|
542
631
|
|
|
@@ -1,12 +0,0 @@
|
|
|
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 { }
|
package/dist/tsdoc-metadata.json
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/types/index.d.ts
DELETED
package/dist/types/messages.d.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
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;
|