@webex/plugin-attachment-actions 3.0.0-beta.8 → 3.0.0-bnr.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/README.md CHANGED
@@ -28,7 +28,6 @@ npm install --save @webex/plugin-attachment-actions
28
28
 
29
29
  ## Usage
30
30
 
31
-
32
31
  ## Maintainers
33
32
 
34
33
  This package is maintained by [Cisco Webex for Developers](https://developer.webex.com/).
@@ -1,29 +1,22 @@
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
  var _apply = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/reflect/apply"));
14
-
15
10
  var _stringify = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/json/stringify"));
16
-
17
11
  var _cloneDeep2 = _interopRequireDefault(require("lodash/cloneDeep"));
18
-
19
12
  var _webexCore = require("@webex/webex-core");
20
-
21
13
  var _common = require("@webex/common");
22
-
23
14
  /*!
24
15
  * Copyright (c) 2015-2017 Cisco Systems, Inc. See LICENSE file.
25
16
  */
17
+
26
18
  var debug = require('debug')('attachmentActions');
19
+
27
20
  /**
28
21
  * @typedef {Object} AttachmentActionObject
29
22
  * @property {string} id - (server generated) Unique identifier for the attachment action
@@ -44,8 +37,6 @@ var debug = require('debug')('attachmentActions');
44
37
  * for more details
45
38
  * @class
46
39
  */
47
-
48
-
49
40
  var AttachmentActions = _webexCore.WebexPlugin.extend({
50
41
  /**
51
42
  * Initializer used to generate AttachmentActions
@@ -59,10 +50,8 @@ var AttachmentActions = _webexCore.WebexPlugin.extend({
59
50
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
60
51
  args[_key] = arguments[_key];
61
52
  }
62
-
63
53
  (0, _apply.default)(_webexCore.WebexPlugin.prototype.initialize, this, args);
64
54
  },
65
-
66
55
  /**
67
56
  * Register to listen for incoming attachmentAction events
68
57
  * This is an alternate approach to registering for attachmentAction webhooks.
@@ -93,11 +82,11 @@ var AttachmentActions = _webexCore.WebexPlugin.extend({
93
82
  */
94
83
  listen: function listen() {
95
84
  var _this = this;
96
-
97
85
  // Create a common envelope that we will wrap all events in
98
86
  return (0, _common.createEventEnvelope)(this.webex, _common.SDK_EVENT.EXTERNAL.RESOURCE.ATTACHMENT_ACTIONS).then(function (envelope) {
99
- _this.eventEnvelope = envelope; // Register to listen to events
87
+ _this.eventEnvelope = envelope;
100
88
 
89
+ // Register to listen to events
101
90
  return _this.webex.internal.mercury.connect().then(function () {
102
91
  _this.listenTo(_this.webex.internal.mercury, _common.SDK_EVENT.INTERNAL.WEBEX_ACTIVITY, function (event) {
103
92
  return _this.onWebexApiEvent(event);
@@ -105,72 +94,71 @@ var AttachmentActions = _webexCore.WebexPlugin.extend({
105
94
  });
106
95
  });
107
96
  },
108
-
109
97
  /**
110
- * Post a new attachment action for a message with attachment.
111
- * @instance
112
- * @memberof AttachmentActions
113
- * @param {AttachmentActionObject} attachmentAction
114
- * @returns {Promise<AttachmentActionObject>}
115
- * @example
116
- * webex.rooms.create({title: 'Create Message with card Example'})
117
- * .then(function(room) {
118
- * return webex.messages.create({
119
- * text: 'Howdy!',
120
- * roomId: room.id,
121
- * attachments:[ {
122
- * contentType: 'application/vnd.microsoft.card.adaptive',
123
- * content: {
124
- * type: 'AdaptiveCard',
125
- * version: '1.0',
126
- * body: [
127
- * {
128
- * type: 'TextBlock',
129
- * text: '',
130
- * size: 'large'
131
- * },
132
- * {
133
- * type: 'TextBlock',
134
- * text: 'Adaptive Cards',
135
- * separation: 'none'
136
- * }
137
- * {
138
- * type: 'Input.Date',
139
- * id: 'dueDate'
140
- * }
141
- * ],
142
- * actions: [
143
- * {
144
- * type: 'Action.Submit',
145
- * title: 'Due Date'
146
- * }
147
- * ]
148
- * }
149
- * }]
150
- * });
151
- * })
152
- * .then(function(message) {
153
- * return webex.attachmentActions.create({
154
- * type: 'submit',
155
- * messageId: message.id,
156
- * inputs:{
157
- * dueDate: '26/06/1995'
158
- * }
159
- * })
160
- * .then(function(attachmentAction)){
161
- * var assert = require('assert');
162
- * assert(attachmentAction.id);
163
- * assert(attachmentAction.type);
164
- * assert(attachmentAction.personId);
165
- * assert(attachmentAction.inputs);
166
- * assert(attachmentAction.messageId);
167
- * assert(attachmentAction.roomId);
168
- * assert(attachmentAction.created);
169
- * return 'success';
170
- * }
171
- * });
172
- * // => success
173
- */
98
+ * Post a new attachment action for a message with attachment.
99
+ * @instance
100
+ * @memberof AttachmentActions
101
+ * @param {AttachmentActionObject} attachmentAction
102
+ * @returns {Promise<AttachmentActionObject>}
103
+ * @example
104
+ * webex.rooms.create({title: 'Create Message with card Example'})
105
+ * .then(function(room) {
106
+ * return webex.messages.create({
107
+ * text: 'Howdy!',
108
+ * roomId: room.id,
109
+ * attachments:[ {
110
+ * contentType: 'application/vnd.microsoft.card.adaptive',
111
+ * content: {
112
+ * type: 'AdaptiveCard',
113
+ * version: '1.0',
114
+ * body: [
115
+ * {
116
+ * type: 'TextBlock',
117
+ * text: '',
118
+ * size: 'large'
119
+ * },
120
+ * {
121
+ * type: 'TextBlock',
122
+ * text: 'Adaptive Cards',
123
+ * separation: 'none'
124
+ * }
125
+ * {
126
+ * type: 'Input.Date',
127
+ * id: 'dueDate'
128
+ * }
129
+ * ],
130
+ * actions: [
131
+ * {
132
+ * type: 'Action.Submit',
133
+ * title: 'Due Date'
134
+ * }
135
+ * ]
136
+ * }
137
+ * }]
138
+ * });
139
+ * })
140
+ * .then(function(message) {
141
+ * return webex.attachmentActions.create({
142
+ * type: 'submit',
143
+ * messageId: message.id,
144
+ * inputs:{
145
+ * dueDate: '26/06/1995'
146
+ * }
147
+ * })
148
+ * .then(function(attachmentAction)){
149
+ * var assert = require('assert');
150
+ * assert(attachmentAction.id);
151
+ * assert(attachmentAction.type);
152
+ * assert(attachmentAction.personId);
153
+ * assert(attachmentAction.inputs);
154
+ * assert(attachmentAction.messageId);
155
+ * assert(attachmentAction.roomId);
156
+ * assert(attachmentAction.created);
157
+ * return 'success';
158
+ * }
159
+ * });
160
+ * // => success
161
+ */
174
162
  create: function create(attachmentAction) {
175
163
  return this.request({
176
164
  method: 'POST',
@@ -181,7 +169,6 @@ var AttachmentActions = _webexCore.WebexPlugin.extend({
181
169
  return res.body;
182
170
  });
183
171
  },
184
-
185
172
  /**
186
173
  * Returns a single attachment action.
187
174
  * @instance
@@ -253,7 +240,6 @@ var AttachmentActions = _webexCore.WebexPlugin.extend({
253
240
  return res.body.items || res.body;
254
241
  });
255
242
  },
256
-
257
243
  /**
258
244
  * This function is called when an internal mercury events fires,
259
245
  * if the user registered for these events with the listen() function.
@@ -265,26 +251,22 @@ var AttachmentActions = _webexCore.WebexPlugin.extend({
265
251
  */
266
252
  onWebexApiEvent: function onWebexApiEvent(event) {
267
253
  var activity = event.data.activity;
268
- /* eslint-disable no-case-declarations */
269
254
 
255
+ /* eslint-disable no-case-declarations */
270
256
  switch (activity.verb) {
271
257
  case _common.SDK_EVENT.INTERNAL.ACTIVITY_VERB.CARD_ACTION:
272
258
  var createdEvent = this.getattachmentActionEvent(activity, _common.SDK_EVENT.EXTERNAL.EVENT_TYPE.CREATED);
273
-
274
259
  if (createdEvent) {
275
260
  debug("attachmentAction \"created\" payload: ".concat((0, _stringify.default)(createdEvent)));
276
261
  this.trigger(_common.SDK_EVENT.EXTERNAL.EVENT_TYPE.CREATED, createdEvent);
277
262
  }
278
-
279
263
  break;
280
-
281
264
  default:
282
265
  {
283
266
  break;
284
267
  }
285
268
  }
286
269
  },
287
-
288
270
  /**
289
271
  * Constructs the data object for an event on the attachmentAction resource,
290
272
  * adhering to Hydra's Webhook data structure messages.
@@ -304,16 +286,15 @@ var AttachmentActions = _webexCore.WebexPlugin.extend({
304
286
  sdkEvent.actorId = (0, _common.constructHydraId)(_common.hydraTypes.PEOPLE, activity.actor.entryUUID, cluster);
305
287
  sdkEvent.data.roomId = (0, _common.constructHydraId)(_common.hydraTypes.ROOM, activity.target.id, cluster);
306
288
  sdkEvent.data.messageId = (0, _common.constructHydraId)(_common.hydraTypes.MESSAGE, activity.parent.id, cluster);
307
- sdkEvent.data.personId = (0, _common.constructHydraId)(_common.hydraTypes.PEOPLE, activity.actor.entryUUID, cluster); // Seems like it would be nice to have this, but its not in the hydra webhook
289
+ sdkEvent.data.personId = (0, _common.constructHydraId)(_common.hydraTypes.PEOPLE, activity.actor.entryUUID, cluster);
290
+ // Seems like it would be nice to have this, but its not in the hydra webhook
308
291
  // sdkEvent.data.personEmail =
309
292
  // activity.actor.emailAddress || activity.actor.entryEmail;
310
293
 
311
294
  sdkEvent.data.id = (0, _common.constructHydraId)(_common.hydraTypes.ATTACHMENT_ACTION, activity.id, cluster);
312
-
313
295
  if (activity.object.inputs) {
314
296
  sdkEvent.data.inputs = activity.object.inputs;
315
297
  }
316
-
317
298
  sdkEvent.data.type = activity.object.objectType;
318
299
  return sdkEvent;
319
300
  } catch (e) {
@@ -321,9 +302,8 @@ var AttachmentActions = _webexCore.WebexPlugin.extend({
321
302
  return null;
322
303
  }
323
304
  },
324
- version: "3.0.0-beta.8"
305
+ version: "3.0.0-bnr.0"
325
306
  });
326
-
327
307
  var _default = AttachmentActions;
328
308
  exports.default = _default;
329
309
  //# sourceMappingURL=attachmentActions.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["debug","require","AttachmentActions","WebexPlugin","extend","initialize","args","prototype","listen","createEventEnvelope","webex","SDK_EVENT","EXTERNAL","RESOURCE","ATTACHMENT_ACTIONS","then","envelope","eventEnvelope","internal","mercury","connect","listenTo","INTERNAL","WEBEX_ACTIVITY","event","onWebexApiEvent","create","attachmentAction","request","method","service","resource","body","res","get","id","items","activity","data","verb","ACTIVITY_VERB","CARD_ACTION","createdEvent","getattachmentActionEvent","EVENT_TYPE","CREATED","trigger","sdkEvent","cluster","getHydraClusterString","target","url","created","published","actorId","constructHydraId","hydraTypes","PEOPLE","actor","entryUUID","roomId","ROOM","messageId","MESSAGE","parent","personId","ATTACHMENT_ACTION","object","inputs","type","objectType","e","logger","error","message"],"sources":["attachmentActions.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2017 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {\n WebexPlugin\n} from '@webex/webex-core';\nimport {\n SDK_EVENT,\n createEventEnvelope,\n constructHydraId,\n getHydraClusterString,\n hydraTypes\n} from '@webex/common';\nimport {cloneDeep} from 'lodash';\n\nconst debug = require('debug')('attachmentActions');\n\n\n/**\n * @typedef {Object} AttachmentActionObject\n * @property {string} id - (server generated) Unique identifier for the attachment action\n * @property {string} messageId - The ID of the message in which attachment action is to be performed\n * @property {string} type - The type of attachment action eg., submit\n * @property {Object} inputs - The inputs for form fields in attachment message\n * @property {string} personId - (server generated) The ID for the author of the attachment action\n * @property {string} roomId - (server generated) The ID for the room of the message\n * @property {isoDate} created - (server generated) The date and time that the message was created\n */\n\n/**\n * AttachmentActions are events that communicate information when a user clicks on an\n * Action.Submit button in a card displayed in Webex\n * Information conveyed in an AttachmentAction includes details about the user that\n * clicked the button along with any card specific inputs. See the\n * {@link https://developer.webex.com/docs/api/v1/attachment-actions|Attachments Actions API Documentation}\n * for more details\n * @class\n */\nconst AttachmentActions = WebexPlugin.extend({\n /**\n * Initializer used to generate AttachmentActions\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 attachmentAction events\n * This is an alternate approach to registering for attachmentAction 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 attachmentActions.listen() event objects can also include additional fields not\n * available in the webhook's JSON payload, specifically: `inputs`.\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.attachmentActions.listen()\n * .then(() => {\n * console.log('listening to attachmentActions events');\n * webex.attachmentActions.on('created', (event) => console.log(`Got an attachmentActions:created event:\\n${event}`));\n * })\n * .catch((e) => console.error(`Unable to register for attachmentAction events: ${e}`));\n * // Some app logic...\n * // WHen it is time to cleanup\n * webex.attachmentActions.stopListening();\n * webex.attachmentActions.off('created');\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.ATTACHMENT_ACTIONS)\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 attachment action for a message with attachment.\n * @instance\n * @memberof AttachmentActions\n * @param {AttachmentActionObject} attachmentAction\n * @returns {Promise<AttachmentActionObject>}\n * @example\n * webex.rooms.create({title: 'Create Message with card Example'})\n * .then(function(room) {\n * return webex.messages.create({\n * text: 'Howdy!',\n * roomId: room.id,\n * attachments:[ {\n * contentType: 'application/vnd.microsoft.card.adaptive',\n * content: {\n * type: 'AdaptiveCard',\n * version: '1.0',\n * body: [\n * {\n * type: 'TextBlock',\n * text: '',\n * size: 'large'\n * },\n * {\n * type: 'TextBlock',\n * text: 'Adaptive Cards',\n * separation: 'none'\n * }\n * {\n * type: 'Input.Date',\n * id: 'dueDate'\n * }\n * ],\n * actions: [\n * {\n * type: 'Action.Submit',\n * title: 'Due Date'\n * }\n * ]\n * }\n * }]\n * });\n * })\n * .then(function(message) {\n * return webex.attachmentActions.create({\n * type: 'submit',\n * messageId: message.id,\n * inputs:{\n * dueDate: '26/06/1995'\n * }\n * })\n * .then(function(attachmentAction)){\n * var assert = require('assert');\n * assert(attachmentAction.id);\n * assert(attachmentAction.type);\n * assert(attachmentAction.personId);\n * assert(attachmentAction.inputs);\n * assert(attachmentAction.messageId);\n * assert(attachmentAction.roomId);\n * assert(attachmentAction.created);\n * return 'success';\n * }\n * });\n * // => success\n */\n create(attachmentAction) {\n return this.request({\n method: 'POST',\n service: 'hydra',\n resource: 'attachment/actions',\n body: attachmentAction\n })\n .then((res) => res.body);\n },\n\n /**\n * Returns a single attachment action.\n * @instance\n * @memberof AttachmentActions\n * @param {string} attachmentAction\n * @returns {Promise<AttachmentActionObject>}\n * @example\n * var attachmentAction;\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 * attachments:[ {\n * contentType: 'application/vnd.microsoft.card.adaptive',\n * content: {\n * type: 'AdaptiveCard',\n * version: '1.0',\n * body: [\n * {\n * type: 'TextBlock',\n * text: '',\n * size: 'large'\n * },\n * {\n * type: 'TextBlock',\n * text: 'Adaptive Cards',\n * separation: 'none'\n * },\n * {\n * type: 'Input.Date',\n * id: 'dueDate'\n * }\n * ],\n * actions: [\n * {\n * type: 'Action.Submit',\n * title: 'Due Date'\n * }\n * ]\n * }\n * }]\n * });\n * })\n * .then(function(message) {\n * return webex.attachmentActions.create({\n * type: 'submit',\n * messageId: message.id,\n * inputs:{\n * dueDate: '26/06/1995'\n * });\n * })\n * .then(function(attachmentAction) {\n * return webex.attachmentActions.get(attachmentAction.id)\n * })\n * .then(function(attachmentAction){\n * var assert = require('assert');\n * assert.deepEqual(attachmentAction, attachmentAction);\n * return 'success';\n * })\n * // => success\n */\n get(attachmentAction) {\n const id = attachmentAction.id || attachmentAction;\n\n return this.request({\n service: 'hydra',\n resource: `attachment/actions/${id}`\n })\n .then((res) => res.body.items || res.body);\n },\n\n /**\n * This function is called when an internal mercury 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 AttachmentAction\n * @param {Object} event\n * @returns {void}\n */\n onWebexApiEvent(event) {\n const {activity} = event.data;\n\n /* eslint-disable no-case-declarations */\n switch (activity.verb) {\n case SDK_EVENT.INTERNAL.ACTIVITY_VERB.CARD_ACTION:\n const createdEvent =\n this.getattachmentActionEvent(activity,\n SDK_EVENT.EXTERNAL.EVENT_TYPE.CREATED);\n\n if (createdEvent) {\n debug(`attachmentAction \"created\" payload: \\\n ${JSON.stringify(createdEvent)}`);\n this.trigger(SDK_EVENT.EXTERNAL.EVENT_TYPE.CREATED, createdEvent);\n }\n break;\n\n default: {\n break;\n }\n }\n },\n\n /**\n * Constructs the data object for an event on the attachmentAction 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 AttachmentAction\n * @param {Object} activity from mercury\n * @param {Object} event type of \"webhook\" event\n * @returns {Object} constructed event\n */\n getattachmentActionEvent(activity, event) {\n try {\n const sdkEvent = cloneDeep(this.eventEnvelope);\n const cluster = getHydraClusterString(this.webex, activity.target.url);\n\n sdkEvent.event = event;\n sdkEvent.data.created = activity.published;\n sdkEvent.actorId =\n constructHydraId(hydraTypes.PEOPLE, activity.actor.entryUUID, cluster);\n sdkEvent.data.roomId =\n constructHydraId(hydraTypes.ROOM, activity.target.id, cluster);\n sdkEvent.data.messageId =\n constructHydraId(hydraTypes.MESSAGE, activity.parent.id, cluster);\n sdkEvent.data.personId =\n constructHydraId(hydraTypes.PEOPLE, activity.actor.entryUUID, cluster);\n // Seems like it would be nice to have this, but its not in the hydra webhook\n // sdkEvent.data.personEmail =\n // activity.actor.emailAddress || activity.actor.entryEmail;\n\n sdkEvent.data.id =\n constructHydraId(hydraTypes.ATTACHMENT_ACTION, activity.id, cluster);\n if (activity.object.inputs) {\n sdkEvent.data.inputs = activity.object.inputs;\n }\n sdkEvent.data.type = activity.object.objectType;\n\n return sdkEvent;\n }\n catch (e) {\n this.webex.logger.error(`Unable to generate SDK event from mercury \\\n'socket activity for attachmentAction:${event} event: ${e.message}`);\n\n return null;\n }\n }\n\n});\n\nexport default AttachmentActions;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAIA;;AAGA;;AAPA;AACA;AACA;AAcA,IAAMA,KAAK,GAAGC,OAAO,CAAC,OAAD,CAAP,CAAiB,mBAAjB,CAAd;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,IAAMC,iBAAiB,GAAGC,sBAAA,CAAYC,MAAZ,CAAmB;EAC3C;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACEC,UAT2C,wBASvB;IAAA,kCAANC,IAAM;MAANA,IAAM;IAAA;;IAClB,oBAAcH,sBAAA,CAAYI,SAAZ,CAAsBF,UAApC,EAAgD,IAAhD,EAAsDC,IAAtD;EACD,CAX0C;;EAa3C;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;EACEE,MAzC2C,oBAyClC;IAAA;;IACP;IACA,OAAO,IAAAC,2BAAA,EAAoB,KAAKC,KAAzB,EACLC,iBAAA,CAAUC,QAAV,CAAmBC,QAAnB,CAA4BC,kBADvB,EAEJC,IAFI,CAEC,UAACC,QAAD,EAAc;MAClB,KAAI,CAACC,aAAL,GAAqBD,QAArB,CADkB,CAGlB;;MACA,OAAO,KAAI,CAACN,KAAL,CAAWQ,QAAX,CAAoBC,OAApB,CAA4BC,OAA5B,GAAsCL,IAAtC,CAA2C,YAAM;QACtD,KAAI,CAACM,QAAL,CAAc,KAAI,CAACX,KAAL,CAAWQ,QAAX,CAAoBC,OAAlC,EACER,iBAAA,CAAUW,QAAV,CAAmBC,cADrB,EAEE,UAACC,KAAD;UAAA,OAAW,KAAI,CAACC,eAAL,CAAqBD,KAArB,CAAX;QAAA,CAFF;MAGD,CAJM,CAAP;IAKD,CAXI,CAAP;EAYD,CAvD0C;;EAyD3C;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;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,MA1H2C,kBA0HpCC,gBA1HoC,EA0HlB;IACvB,OAAO,KAAKC,OAAL,CAAa;MAClBC,MAAM,EAAE,MADU;MAElBC,OAAO,EAAE,OAFS;MAGlBC,QAAQ,EAAE,oBAHQ;MAIlBC,IAAI,EAAEL;IAJY,CAAb,EAMJZ,IANI,CAMC,UAACkB,GAAD;MAAA,OAASA,GAAG,CAACD,IAAb;IAAA,CAND,CAAP;EAOD,CAlI0C;;EAoI3C;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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEE,GAlM2C,eAkMvCP,gBAlMuC,EAkMrB;IACpB,IAAMQ,EAAE,GAAGR,gBAAgB,CAACQ,EAAjB,IAAuBR,gBAAlC;IAEA,OAAO,KAAKC,OAAL,CAAa;MAClBE,OAAO,EAAE,OADS;MAElBC,QAAQ,+BAAwBI,EAAxB;IAFU,CAAb,EAIJpB,IAJI,CAIC,UAACkB,GAAD;MAAA,OAASA,GAAG,CAACD,IAAJ,CAASI,KAAT,IAAkBH,GAAG,CAACD,IAA/B;IAAA,CAJD,CAAP;EAKD,CA1M0C;;EA4M3C;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEP,eArN2C,2BAqN3BD,KArN2B,EAqNpB;IACrB,IAAOa,QAAP,GAAmBb,KAAK,CAACc,IAAzB,CAAOD,QAAP;IAEA;;IACA,QAAQA,QAAQ,CAACE,IAAjB;MACE,KAAK5B,iBAAA,CAAUW,QAAV,CAAmBkB,aAAnB,CAAiCC,WAAtC;QACE,IAAMC,YAAY,GAChB,KAAKC,wBAAL,CAA8BN,QAA9B,EACE1B,iBAAA,CAAUC,QAAV,CAAmBgC,UAAnB,CAA8BC,OADhC,CADF;;QAIA,IAAIH,YAAJ,EAAkB;UAChB1C,KAAK,6DACD,wBAAe0C,YAAf,CADC,EAAL;UAEA,KAAKI,OAAL,CAAanC,iBAAA,CAAUC,QAAV,CAAmBgC,UAAnB,CAA8BC,OAA3C,EAAoDH,YAApD;QACD;;QACD;;MAEF;QAAS;UACP;QACD;IAfH;EAiBD,CA1O0C;;EA4O3C;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEC,wBAtP2C,oCAsPlBN,QAtPkB,EAsPRb,KAtPQ,EAsPD;IACxC,IAAI;MACF,IAAMuB,QAAQ,GAAG,yBAAU,KAAK9B,aAAf,CAAjB;MACA,IAAM+B,OAAO,GAAG,IAAAC,6BAAA,EAAsB,KAAKvC,KAA3B,EAAkC2B,QAAQ,CAACa,MAAT,CAAgBC,GAAlD,CAAhB;MAEAJ,QAAQ,CAACvB,KAAT,GAAiBA,KAAjB;MACAuB,QAAQ,CAACT,IAAT,CAAcc,OAAd,GAAwBf,QAAQ,CAACgB,SAAjC;MACAN,QAAQ,CAACO,OAAT,GACE,IAAAC,wBAAA,EAAiBC,kBAAA,CAAWC,MAA5B,EAAoCpB,QAAQ,CAACqB,KAAT,CAAeC,SAAnD,EAA8DX,OAA9D,CADF;MAEAD,QAAQ,CAACT,IAAT,CAAcsB,MAAd,GACE,IAAAL,wBAAA,EAAiBC,kBAAA,CAAWK,IAA5B,EAAkCxB,QAAQ,CAACa,MAAT,CAAgBf,EAAlD,EAAsDa,OAAtD,CADF;MAEAD,QAAQ,CAACT,IAAT,CAAcwB,SAAd,GACE,IAAAP,wBAAA,EAAiBC,kBAAA,CAAWO,OAA5B,EAAqC1B,QAAQ,CAAC2B,MAAT,CAAgB7B,EAArD,EAAyDa,OAAzD,CADF;MAEAD,QAAQ,CAACT,IAAT,CAAc2B,QAAd,GACE,IAAAV,wBAAA,EAAiBC,kBAAA,CAAWC,MAA5B,EAAoCpB,QAAQ,CAACqB,KAAT,CAAeC,SAAnD,EAA8DX,OAA9D,CADF,CAZE,CAcF;MACA;MACA;;MAEAD,QAAQ,CAACT,IAAT,CAAcH,EAAd,GACE,IAAAoB,wBAAA,EAAiBC,kBAAA,CAAWU,iBAA5B,EAA+C7B,QAAQ,CAACF,EAAxD,EAA4Da,OAA5D,CADF;;MAEA,IAAIX,QAAQ,CAAC8B,MAAT,CAAgBC,MAApB,EAA4B;QAC1BrB,QAAQ,CAACT,IAAT,CAAc8B,MAAd,GAAuB/B,QAAQ,CAAC8B,MAAT,CAAgBC,MAAvC;MACD;;MACDrB,QAAQ,CAACT,IAAT,CAAc+B,IAAd,GAAqBhC,QAAQ,CAAC8B,MAAT,CAAgBG,UAArC;MAEA,OAAOvB,QAAP;IACD,CA1BD,CA2BA,OAAOwB,CAAP,EAAU;MACR,KAAK7D,KAAL,CAAW8D,MAAX,CAAkBC,KAAlB,2FACkCjD,KADlC,qBACkD+C,CAAC,CAACG,OADpD;MAGA,OAAO,IAAP;IACD;EACF,CAxR0C;EAAA;AAAA,CAAnB,CAA1B;;eA4RexE,iB"}
1
+ {"version":3,"names":["debug","require","AttachmentActions","WebexPlugin","extend","initialize","args","prototype","listen","createEventEnvelope","webex","SDK_EVENT","EXTERNAL","RESOURCE","ATTACHMENT_ACTIONS","then","envelope","eventEnvelope","internal","mercury","connect","listenTo","INTERNAL","WEBEX_ACTIVITY","event","onWebexApiEvent","create","attachmentAction","request","method","service","resource","body","res","get","id","items","activity","data","verb","ACTIVITY_VERB","CARD_ACTION","createdEvent","getattachmentActionEvent","EVENT_TYPE","CREATED","trigger","sdkEvent","cluster","getHydraClusterString","target","url","created","published","actorId","constructHydraId","hydraTypes","PEOPLE","actor","entryUUID","roomId","ROOM","messageId","MESSAGE","parent","personId","ATTACHMENT_ACTION","object","inputs","type","objectType","e","logger","error","message"],"sources":["attachmentActions.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2017 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {WebexPlugin} from '@webex/webex-core';\nimport {\n SDK_EVENT,\n createEventEnvelope,\n constructHydraId,\n getHydraClusterString,\n hydraTypes,\n} from '@webex/common';\nimport {cloneDeep} from 'lodash';\n\nconst debug = require('debug')('attachmentActions');\n\n/**\n * @typedef {Object} AttachmentActionObject\n * @property {string} id - (server generated) Unique identifier for the attachment action\n * @property {string} messageId - The ID of the message in which attachment action is to be performed\n * @property {string} type - The type of attachment action eg., submit\n * @property {Object} inputs - The inputs for form fields in attachment message\n * @property {string} personId - (server generated) The ID for the author of the attachment action\n * @property {string} roomId - (server generated) The ID for the room of the message\n * @property {isoDate} created - (server generated) The date and time that the message was created\n */\n\n/**\n * AttachmentActions are events that communicate information when a user clicks on an\n * Action.Submit button in a card displayed in Webex\n * Information conveyed in an AttachmentAction includes details about the user that\n * clicked the button along with any card specific inputs. See the\n * {@link https://developer.webex.com/docs/api/v1/attachment-actions|Attachments Actions API Documentation}\n * for more details\n * @class\n */\nconst AttachmentActions = WebexPlugin.extend({\n /**\n * Initializer used to generate AttachmentActions\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 attachmentAction events\n * This is an alternate approach to registering for attachmentAction 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 attachmentActions.listen() event objects can also include additional fields not\n * available in the webhook's JSON payload, specifically: `inputs`.\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.attachmentActions.listen()\n * .then(() => {\n * console.log('listening to attachmentActions events');\n * webex.attachmentActions.on('created', (event) => console.log(`Got an attachmentActions:created event:\\n${event}`));\n * })\n * .catch((e) => console.error(`Unable to register for attachmentAction events: ${e}`));\n * // Some app logic...\n * // WHen it is time to cleanup\n * webex.attachmentActions.stopListening();\n * webex.attachmentActions.off('created');\n */\n listen() {\n // Create a common envelope that we will wrap all events in\n return createEventEnvelope(this.webex, SDK_EVENT.EXTERNAL.RESOURCE.ATTACHMENT_ACTIONS).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 attachment action for a message with attachment.\n * @instance\n * @memberof AttachmentActions\n * @param {AttachmentActionObject} attachmentAction\n * @returns {Promise<AttachmentActionObject>}\n * @example\n * webex.rooms.create({title: 'Create Message with card Example'})\n * .then(function(room) {\n * return webex.messages.create({\n * text: 'Howdy!',\n * roomId: room.id,\n * attachments:[ {\n * contentType: 'application/vnd.microsoft.card.adaptive',\n * content: {\n * type: 'AdaptiveCard',\n * version: '1.0',\n * body: [\n * {\n * type: 'TextBlock',\n * text: '',\n * size: 'large'\n * },\n * {\n * type: 'TextBlock',\n * text: 'Adaptive Cards',\n * separation: 'none'\n * }\n * {\n * type: 'Input.Date',\n * id: 'dueDate'\n * }\n * ],\n * actions: [\n * {\n * type: 'Action.Submit',\n * title: 'Due Date'\n * }\n * ]\n * }\n * }]\n * });\n * })\n * .then(function(message) {\n * return webex.attachmentActions.create({\n * type: 'submit',\n * messageId: message.id,\n * inputs:{\n * dueDate: '26/06/1995'\n * }\n * })\n * .then(function(attachmentAction)){\n * var assert = require('assert');\n * assert(attachmentAction.id);\n * assert(attachmentAction.type);\n * assert(attachmentAction.personId);\n * assert(attachmentAction.inputs);\n * assert(attachmentAction.messageId);\n * assert(attachmentAction.roomId);\n * assert(attachmentAction.created);\n * return 'success';\n * }\n * });\n * // => success\n */\n create(attachmentAction) {\n return this.request({\n method: 'POST',\n service: 'hydra',\n resource: 'attachment/actions',\n body: attachmentAction,\n }).then((res) => res.body);\n },\n\n /**\n * Returns a single attachment action.\n * @instance\n * @memberof AttachmentActions\n * @param {string} attachmentAction\n * @returns {Promise<AttachmentActionObject>}\n * @example\n * var attachmentAction;\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 * attachments:[ {\n * contentType: 'application/vnd.microsoft.card.adaptive',\n * content: {\n * type: 'AdaptiveCard',\n * version: '1.0',\n * body: [\n * {\n * type: 'TextBlock',\n * text: '',\n * size: 'large'\n * },\n * {\n * type: 'TextBlock',\n * text: 'Adaptive Cards',\n * separation: 'none'\n * },\n * {\n * type: 'Input.Date',\n * id: 'dueDate'\n * }\n * ],\n * actions: [\n * {\n * type: 'Action.Submit',\n * title: 'Due Date'\n * }\n * ]\n * }\n * }]\n * });\n * })\n * .then(function(message) {\n * return webex.attachmentActions.create({\n * type: 'submit',\n * messageId: message.id,\n * inputs:{\n * dueDate: '26/06/1995'\n * });\n * })\n * .then(function(attachmentAction) {\n * return webex.attachmentActions.get(attachmentAction.id)\n * })\n * .then(function(attachmentAction){\n * var assert = require('assert');\n * assert.deepEqual(attachmentAction, attachmentAction);\n * return 'success';\n * })\n * // => success\n */\n get(attachmentAction) {\n const id = attachmentAction.id || attachmentAction;\n\n return this.request({\n service: 'hydra',\n resource: `attachment/actions/${id}`,\n }).then((res) => res.body.items || res.body);\n },\n\n /**\n * This function is called when an internal mercury 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 AttachmentAction\n * @param {Object} event\n * @returns {void}\n */\n onWebexApiEvent(event) {\n const {activity} = event.data;\n\n /* eslint-disable no-case-declarations */\n switch (activity.verb) {\n case SDK_EVENT.INTERNAL.ACTIVITY_VERB.CARD_ACTION:\n const createdEvent = this.getattachmentActionEvent(\n activity,\n SDK_EVENT.EXTERNAL.EVENT_TYPE.CREATED\n );\n\n if (createdEvent) {\n debug(`attachmentAction \"created\" payload: \\\n ${JSON.stringify(createdEvent)}`);\n this.trigger(SDK_EVENT.EXTERNAL.EVENT_TYPE.CREATED, createdEvent);\n }\n break;\n\n default: {\n break;\n }\n }\n },\n\n /**\n * Constructs the data object for an event on the attachmentAction 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 AttachmentAction\n * @param {Object} activity from mercury\n * @param {Object} event type of \"webhook\" event\n * @returns {Object} constructed event\n */\n getattachmentActionEvent(activity, event) {\n try {\n const sdkEvent = cloneDeep(this.eventEnvelope);\n const cluster = getHydraClusterString(this.webex, activity.target.url);\n\n sdkEvent.event = event;\n sdkEvent.data.created = activity.published;\n sdkEvent.actorId = constructHydraId(hydraTypes.PEOPLE, activity.actor.entryUUID, cluster);\n sdkEvent.data.roomId = constructHydraId(hydraTypes.ROOM, activity.target.id, cluster);\n sdkEvent.data.messageId = constructHydraId(hydraTypes.MESSAGE, activity.parent.id, cluster);\n sdkEvent.data.personId = constructHydraId(\n hydraTypes.PEOPLE,\n activity.actor.entryUUID,\n cluster\n );\n // Seems like it would be nice to have this, but its not in the hydra webhook\n // sdkEvent.data.personEmail =\n // activity.actor.emailAddress || activity.actor.entryEmail;\n\n sdkEvent.data.id = constructHydraId(hydraTypes.ATTACHMENT_ACTION, activity.id, cluster);\n if (activity.object.inputs) {\n sdkEvent.data.inputs = activity.object.inputs;\n }\n sdkEvent.data.type = activity.object.objectType;\n\n return sdkEvent;\n } catch (e) {\n this.webex.logger.error(`Unable to generate SDK event from mercury \\\n'socket activity for attachmentAction:${event} event: ${e.message}`);\n\n return null;\n }\n },\n});\n\nexport default AttachmentActions;\n"],"mappings":";;;;;;;;;;;AAIA;AACA;AALA;AACA;AACA;;AAYA,IAAMA,KAAK,GAAGC,OAAO,CAAC,OAAO,CAAC,CAAC,mBAAmB,CAAC;;AAEnD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAMC,iBAAiB,GAAGC,sBAAW,CAACC,MAAM,CAAC;EAC3C;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;EACEE,MAAM,oBAAG;IAAA;IACP;IACA,OAAO,IAAAC,2BAAmB,EAAC,IAAI,CAACC,KAAK,EAAEC,iBAAS,CAACC,QAAQ,CAACC,QAAQ,CAACC,kBAAkB,CAAC,CAACC,IAAI,CACzF,UAACC,QAAQ,EAAK;MACZ,KAAI,CAACC,aAAa,GAAGD,QAAQ;;MAE7B;MACA,OAAO,KAAI,CAACN,KAAK,CAACQ,QAAQ,CAACC,OAAO,CAACC,OAAO,EAAE,CAACL,IAAI,CAAC,YAAM;QACtD,KAAI,CAACM,QAAQ,CAAC,KAAI,CAACX,KAAK,CAACQ,QAAQ,CAACC,OAAO,EAAER,iBAAS,CAACW,QAAQ,CAACC,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;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;AACA;AACA;EACEE,MAAM,kBAACC,gBAAgB,EAAE;IACvB,OAAO,IAAI,CAACC,OAAO,CAAC;MAClBC,MAAM,EAAE,MAAM;MACdC,OAAO,EAAE,OAAO;MAChBC,QAAQ,EAAE,oBAAoB;MAC9BC,IAAI,EAAEL;IACR,CAAC,CAAC,CAACZ,IAAI,CAAC,UAACkB,GAAG;MAAA,OAAKA,GAAG,CAACD,IAAI;IAAA,EAAC;EAC5B,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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEE,GAAG,eAACP,gBAAgB,EAAE;IACpB,IAAMQ,EAAE,GAAGR,gBAAgB,CAACQ,EAAE,IAAIR,gBAAgB;IAElD,OAAO,IAAI,CAACC,OAAO,CAAC;MAClBE,OAAO,EAAE,OAAO;MAChBC,QAAQ,+BAAwBI,EAAE;IACpC,CAAC,CAAC,CAACpB,IAAI,CAAC,UAACkB,GAAG;MAAA,OAAKA,GAAG,CAACD,IAAI,CAACI,KAAK,IAAIH,GAAG,CAACD,IAAI;IAAA,EAAC;EAC9C,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEP,eAAe,2BAACD,KAAK,EAAE;IACrB,IAAOa,QAAQ,GAAIb,KAAK,CAACc,IAAI,CAAtBD,QAAQ;;IAEf;IACA,QAAQA,QAAQ,CAACE,IAAI;MACnB,KAAK5B,iBAAS,CAACW,QAAQ,CAACkB,aAAa,CAACC,WAAW;QAC/C,IAAMC,YAAY,GAAG,IAAI,CAACC,wBAAwB,CAChDN,QAAQ,EACR1B,iBAAS,CAACC,QAAQ,CAACgC,UAAU,CAACC,OAAO,CACtC;QAED,IAAIH,YAAY,EAAE;UAChB1C,KAAK,6DACD,wBAAe0C,YAAY,CAAC,EAAG;UACnC,IAAI,CAACI,OAAO,CAACnC,iBAAS,CAACC,QAAQ,CAACgC,UAAU,CAACC,OAAO,EAAEH,YAAY,CAAC;QACnE;QACA;MAEF;QAAS;UACP;QACF;IAAC;EAEL,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEC,wBAAwB,oCAACN,QAAQ,EAAEb,KAAK,EAAE;IACxC,IAAI;MACF,IAAMuB,QAAQ,GAAG,yBAAU,IAAI,CAAC9B,aAAa,CAAC;MAC9C,IAAM+B,OAAO,GAAG,IAAAC,6BAAqB,EAAC,IAAI,CAACvC,KAAK,EAAE2B,QAAQ,CAACa,MAAM,CAACC,GAAG,CAAC;MAEtEJ,QAAQ,CAACvB,KAAK,GAAGA,KAAK;MACtBuB,QAAQ,CAACT,IAAI,CAACc,OAAO,GAAGf,QAAQ,CAACgB,SAAS;MAC1CN,QAAQ,CAACO,OAAO,GAAG,IAAAC,wBAAgB,EAACC,kBAAU,CAACC,MAAM,EAAEpB,QAAQ,CAACqB,KAAK,CAACC,SAAS,EAAEX,OAAO,CAAC;MACzFD,QAAQ,CAACT,IAAI,CAACsB,MAAM,GAAG,IAAAL,wBAAgB,EAACC,kBAAU,CAACK,IAAI,EAAExB,QAAQ,CAACa,MAAM,CAACf,EAAE,EAAEa,OAAO,CAAC;MACrFD,QAAQ,CAACT,IAAI,CAACwB,SAAS,GAAG,IAAAP,wBAAgB,EAACC,kBAAU,CAACO,OAAO,EAAE1B,QAAQ,CAAC2B,MAAM,CAAC7B,EAAE,EAAEa,OAAO,CAAC;MAC3FD,QAAQ,CAACT,IAAI,CAAC2B,QAAQ,GAAG,IAAAV,wBAAgB,EACvCC,kBAAU,CAACC,MAAM,EACjBpB,QAAQ,CAACqB,KAAK,CAACC,SAAS,EACxBX,OAAO,CACR;MACD;MACA;MACA;;MAEAD,QAAQ,CAACT,IAAI,CAACH,EAAE,GAAG,IAAAoB,wBAAgB,EAACC,kBAAU,CAACU,iBAAiB,EAAE7B,QAAQ,CAACF,EAAE,EAAEa,OAAO,CAAC;MACvF,IAAIX,QAAQ,CAAC8B,MAAM,CAACC,MAAM,EAAE;QAC1BrB,QAAQ,CAACT,IAAI,CAAC8B,MAAM,GAAG/B,QAAQ,CAAC8B,MAAM,CAACC,MAAM;MAC/C;MACArB,QAAQ,CAACT,IAAI,CAAC+B,IAAI,GAAGhC,QAAQ,CAAC8B,MAAM,CAACG,UAAU;MAE/C,OAAOvB,QAAQ;IACjB,CAAC,CAAC,OAAOwB,CAAC,EAAE;MACV,IAAI,CAAC7D,KAAK,CAAC8D,MAAM,CAACC,KAAK,2FACWjD,KAAK,qBAAW+C,CAAC,CAACG,OAAO,EAAG;MAE9D,OAAO,IAAI;IACb;EACF,CAAC;EAAA;AACH,CAAC,CAAC;AAAC,eAEYxE,iBAAiB;AAAA"}
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 _attachmentActions = _interopRequireDefault(require("./attachmentActions"));
20
-
21
13
  /*!
22
14
  * Copyright (c) 2015-2017 Cisco Systems, Inc. See LICENSE file.
23
15
  */
16
+
24
17
  // decrypt mercury activities
18
+
25
19
  (0, _webexCore.registerPlugin)('attachmentActions', _attachmentActions.default);
26
20
  var _default = _attachmentActions.default;
27
21
  exports.default = _default;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["registerPlugin","AttachmentActions"],"sources":["index.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2017 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 AttachmentActions from './attachmentActions';\n\nregisterPlugin('attachmentActions', AttachmentActions);\n\nexport default AttachmentActions;\n"],"mappings":";;;;;;;;;;;;AAIA;;AACA;;AAEA;;AAEA;;AATA;AACA;AACA;AAE8C;AAO9C,IAAAA,yBAAA,EAAe,mBAAf,EAAoCC,0BAApC;eAEeA,0B"}
1
+ {"version":3,"names":["registerPlugin","AttachmentActions"],"sources":["index.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2017 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 AttachmentActions from './attachmentActions';\n\nregisterPlugin('attachmentActions', AttachmentActions);\n\nexport default AttachmentActions;\n"],"mappings":";;;;;;;;AAIA;AACA;AAEA;AAEA;AATA;AACA;AACA;;AAE8C;;AAO9C,IAAAA,yBAAc,EAAC,mBAAmB,EAAEC,0BAAiB,CAAC;AAAC,eAExCA,0BAAiB;AAAA"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * AttachmentActions are events that communicate information when a user clicks on an
3
+ * Action.Submit button in a card displayed in Webex
4
+ * Information conveyed in an AttachmentAction includes details about the user that
5
+ * clicked the button along with any card specific inputs. See the
6
+ * {@link https://developer.webex.com/docs/api/v1/attachment-actions|Attachments Actions API Documentation}
7
+ * for more details
8
+ * @class
9
+ */
10
+ declare const AttachmentActions: any;
11
+ export default AttachmentActions;
12
+
13
+ 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,51 @@
1
+ export default AttachmentActions;
2
+ export type AttachmentActionObject = {
3
+ /**
4
+ * - (server generated) Unique identifier for the attachment action
5
+ */
6
+ id: string;
7
+ /**
8
+ * - The ID of the message in which attachment action is to be performed
9
+ */
10
+ messageId: string;
11
+ /**
12
+ * - The type of attachment action eg., submit
13
+ */
14
+ type: string;
15
+ /**
16
+ * - The inputs for form fields in attachment message
17
+ */
18
+ inputs: any;
19
+ /**
20
+ * - (server generated) The ID for the author of the attachment action
21
+ */
22
+ personId: string;
23
+ /**
24
+ * - (server generated) The ID for the room of the message
25
+ */
26
+ roomId: string;
27
+ /**
28
+ * - (server generated) The date and time that the message was created
29
+ */
30
+ created: isoDate;
31
+ };
32
+ /**
33
+ * @typedef {Object} AttachmentActionObject
34
+ * @property {string} id - (server generated) Unique identifier for the attachment action
35
+ * @property {string} messageId - The ID of the message in which attachment action is to be performed
36
+ * @property {string} type - The type of attachment action eg., submit
37
+ * @property {Object} inputs - The inputs for form fields in attachment message
38
+ * @property {string} personId - (server generated) The ID for the author of the attachment action
39
+ * @property {string} roomId - (server generated) The ID for the room of the message
40
+ * @property {isoDate} created - (server generated) The date and time that the message was created
41
+ */
42
+ /**
43
+ * AttachmentActions are events that communicate information when a user clicks on an
44
+ * Action.Submit button in a card displayed in Webex
45
+ * Information conveyed in an AttachmentAction includes details about the user that
46
+ * clicked the button along with any card specific inputs. See the
47
+ * {@link https://developer.webex.com/docs/api/v1/attachment-actions|Attachments Actions API Documentation}
48
+ * for more details
49
+ * @class
50
+ */
51
+ declare const AttachmentActions: any;
@@ -0,0 +1,2 @@
1
+ export default AttachmentActions;
2
+ import AttachmentActions from "./attachmentActions";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webex/plugin-attachment-actions",
3
- "version": "3.0.0-beta.8",
3
+ "version": "3.0.0-bnr.0",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "contributors": [
@@ -23,16 +23,16 @@
23
23
  ]
24
24
  },
25
25
  "dependencies": {
26
- "@webex/common": "3.0.0-beta.8",
27
- "@webex/internal-plugin-conversation": "3.0.0-beta.8",
28
- "@webex/internal-plugin-mercury": "3.0.0-beta.8",
29
- "@webex/plugin-attachment-actions": "3.0.0-beta.8",
30
- "@webex/plugin-logger": "3.0.0-beta.8",
31
- "@webex/plugin-messages": "3.0.0-beta.8",
32
- "@webex/plugin-people": "3.0.0-beta.8",
33
- "@webex/test-helper-chai": "3.0.0-beta.8",
34
- "@webex/test-helper-test-users": "3.0.0-beta.8",
35
- "@webex/webex-core": "3.0.0-beta.8",
26
+ "@webex/common": "3.0.0-bnr.0",
27
+ "@webex/internal-plugin-conversation": "3.0.0-bnr.0",
28
+ "@webex/internal-plugin-mercury": "3.0.0-bnr.0",
29
+ "@webex/plugin-attachment-actions": "3.0.0-bnr.0",
30
+ "@webex/plugin-logger": "3.0.0-bnr.0",
31
+ "@webex/plugin-messages": "3.0.0-bnr.0",
32
+ "@webex/plugin-people": "3.0.0-bnr.0",
33
+ "@webex/test-helper-chai": "3.0.0-bnr.0",
34
+ "@webex/test-helper-test-users": "3.0.0-bnr.0",
35
+ "@webex/webex-core": "3.0.0-bnr.0",
36
36
  "debug": "^4.3.4",
37
37
  "lodash": "^4.17.21"
38
38
  }
@@ -2,21 +2,18 @@
2
2
  * Copyright (c) 2015-2017 Cisco Systems, Inc. See LICENSE file.
3
3
  */
4
4
 
5
- import {
6
- WebexPlugin
7
- } from '@webex/webex-core';
5
+ import {WebexPlugin} from '@webex/webex-core';
8
6
  import {
9
7
  SDK_EVENT,
10
8
  createEventEnvelope,
11
9
  constructHydraId,
12
10
  getHydraClusterString,
13
- hydraTypes
11
+ hydraTypes,
14
12
  } from '@webex/common';
15
13
  import {cloneDeep} from 'lodash';
16
14
 
17
15
  const debug = require('debug')('attachmentActions');
18
16
 
19
-
20
17
  /**
21
18
  * @typedef {Object} AttachmentActionObject
22
19
  * @property {string} id - (server generated) Unique identifier for the attachment action
@@ -80,93 +77,92 @@ const AttachmentActions = WebexPlugin.extend({
80
77
  */
81
78
  listen() {
82
79
  // Create a common envelope that we will wrap all events in
83
- return createEventEnvelope(this.webex,
84
- SDK_EVENT.EXTERNAL.RESOURCE.ATTACHMENT_ACTIONS)
85
- .then((envelope) => {
80
+ return createEventEnvelope(this.webex, SDK_EVENT.EXTERNAL.RESOURCE.ATTACHMENT_ACTIONS).then(
81
+ (envelope) => {
86
82
  this.eventEnvelope = envelope;
87
83
 
88
84
  // Register to listen to events
89
85
  return this.webex.internal.mercury.connect().then(() => {
90
- this.listenTo(this.webex.internal.mercury,
91
- SDK_EVENT.INTERNAL.WEBEX_ACTIVITY,
92
- (event) => this.onWebexApiEvent(event));
86
+ this.listenTo(this.webex.internal.mercury, SDK_EVENT.INTERNAL.WEBEX_ACTIVITY, (event) =>
87
+ this.onWebexApiEvent(event)
88
+ );
93
89
  });
94
- });
90
+ }
91
+ );
95
92
  },
96
93
 
97
94
  /**
98
- * Post a new attachment action for a message with attachment.
99
- * @instance
100
- * @memberof AttachmentActions
101
- * @param {AttachmentActionObject} attachmentAction
102
- * @returns {Promise<AttachmentActionObject>}
103
- * @example
104
- * webex.rooms.create({title: 'Create Message with card Example'})
105
- * .then(function(room) {
106
- * return webex.messages.create({
107
- * text: 'Howdy!',
108
- * roomId: room.id,
109
- * attachments:[ {
110
- * contentType: 'application/vnd.microsoft.card.adaptive',
111
- * content: {
112
- * type: 'AdaptiveCard',
113
- * version: '1.0',
114
- * body: [
115
- * {
116
- * type: 'TextBlock',
117
- * text: '',
118
- * size: 'large'
119
- * },
120
- * {
121
- * type: 'TextBlock',
122
- * text: 'Adaptive Cards',
123
- * separation: 'none'
124
- * }
125
- * {
126
- * type: 'Input.Date',
127
- * id: 'dueDate'
128
- * }
129
- * ],
130
- * actions: [
131
- * {
132
- * type: 'Action.Submit',
133
- * title: 'Due Date'
134
- * }
135
- * ]
136
- * }
137
- * }]
138
- * });
139
- * })
140
- * .then(function(message) {
141
- * return webex.attachmentActions.create({
142
- * type: 'submit',
143
- * messageId: message.id,
144
- * inputs:{
145
- * dueDate: '26/06/1995'
146
- * }
147
- * })
148
- * .then(function(attachmentAction)){
149
- * var assert = require('assert');
150
- * assert(attachmentAction.id);
151
- * assert(attachmentAction.type);
152
- * assert(attachmentAction.personId);
153
- * assert(attachmentAction.inputs);
154
- * assert(attachmentAction.messageId);
155
- * assert(attachmentAction.roomId);
156
- * assert(attachmentAction.created);
157
- * return 'success';
158
- * }
159
- * });
160
- * // => success
161
- */
95
+ * Post a new attachment action for a message with attachment.
96
+ * @instance
97
+ * @memberof AttachmentActions
98
+ * @param {AttachmentActionObject} attachmentAction
99
+ * @returns {Promise<AttachmentActionObject>}
100
+ * @example
101
+ * webex.rooms.create({title: 'Create Message with card Example'})
102
+ * .then(function(room) {
103
+ * return webex.messages.create({
104
+ * text: 'Howdy!',
105
+ * roomId: room.id,
106
+ * attachments:[ {
107
+ * contentType: 'application/vnd.microsoft.card.adaptive',
108
+ * content: {
109
+ * type: 'AdaptiveCard',
110
+ * version: '1.0',
111
+ * body: [
112
+ * {
113
+ * type: 'TextBlock',
114
+ * text: '',
115
+ * size: 'large'
116
+ * },
117
+ * {
118
+ * type: 'TextBlock',
119
+ * text: 'Adaptive Cards',
120
+ * separation: 'none'
121
+ * }
122
+ * {
123
+ * type: 'Input.Date',
124
+ * id: 'dueDate'
125
+ * }
126
+ * ],
127
+ * actions: [
128
+ * {
129
+ * type: 'Action.Submit',
130
+ * title: 'Due Date'
131
+ * }
132
+ * ]
133
+ * }
134
+ * }]
135
+ * });
136
+ * })
137
+ * .then(function(message) {
138
+ * return webex.attachmentActions.create({
139
+ * type: 'submit',
140
+ * messageId: message.id,
141
+ * inputs:{
142
+ * dueDate: '26/06/1995'
143
+ * }
144
+ * })
145
+ * .then(function(attachmentAction)){
146
+ * var assert = require('assert');
147
+ * assert(attachmentAction.id);
148
+ * assert(attachmentAction.type);
149
+ * assert(attachmentAction.personId);
150
+ * assert(attachmentAction.inputs);
151
+ * assert(attachmentAction.messageId);
152
+ * assert(attachmentAction.roomId);
153
+ * assert(attachmentAction.created);
154
+ * return 'success';
155
+ * }
156
+ * });
157
+ * // => success
158
+ */
162
159
  create(attachmentAction) {
163
160
  return this.request({
164
161
  method: 'POST',
165
162
  service: 'hydra',
166
163
  resource: 'attachment/actions',
167
- body: attachmentAction
168
- })
169
- .then((res) => res.body);
164
+ body: attachmentAction,
165
+ }).then((res) => res.body);
170
166
  },
171
167
 
172
168
  /**
@@ -236,9 +232,8 @@ const AttachmentActions = WebexPlugin.extend({
236
232
 
237
233
  return this.request({
238
234
  service: 'hydra',
239
- resource: `attachment/actions/${id}`
240
- })
241
- .then((res) => res.body.items || res.body);
235
+ resource: `attachment/actions/${id}`,
236
+ }).then((res) => res.body.items || res.body);
242
237
  },
243
238
 
244
239
  /**
@@ -256,9 +251,10 @@ const AttachmentActions = WebexPlugin.extend({
256
251
  /* eslint-disable no-case-declarations */
257
252
  switch (activity.verb) {
258
253
  case SDK_EVENT.INTERNAL.ACTIVITY_VERB.CARD_ACTION:
259
- const createdEvent =
260
- this.getattachmentActionEvent(activity,
261
- SDK_EVENT.EXTERNAL.EVENT_TYPE.CREATED);
254
+ const createdEvent = this.getattachmentActionEvent(
255
+ activity,
256
+ SDK_EVENT.EXTERNAL.EVENT_TYPE.CREATED
257
+ );
262
258
 
263
259
  if (createdEvent) {
264
260
  debug(`attachmentAction "created" payload: \
@@ -290,35 +286,32 @@ const AttachmentActions = WebexPlugin.extend({
290
286
 
291
287
  sdkEvent.event = event;
292
288
  sdkEvent.data.created = activity.published;
293
- sdkEvent.actorId =
294
- constructHydraId(hydraTypes.PEOPLE, activity.actor.entryUUID, cluster);
295
- sdkEvent.data.roomId =
296
- constructHydraId(hydraTypes.ROOM, activity.target.id, cluster);
297
- sdkEvent.data.messageId =
298
- constructHydraId(hydraTypes.MESSAGE, activity.parent.id, cluster);
299
- sdkEvent.data.personId =
300
- constructHydraId(hydraTypes.PEOPLE, activity.actor.entryUUID, cluster);
289
+ sdkEvent.actorId = constructHydraId(hydraTypes.PEOPLE, activity.actor.entryUUID, cluster);
290
+ sdkEvent.data.roomId = constructHydraId(hydraTypes.ROOM, activity.target.id, cluster);
291
+ sdkEvent.data.messageId = constructHydraId(hydraTypes.MESSAGE, activity.parent.id, cluster);
292
+ sdkEvent.data.personId = constructHydraId(
293
+ hydraTypes.PEOPLE,
294
+ activity.actor.entryUUID,
295
+ cluster
296
+ );
301
297
  // Seems like it would be nice to have this, but its not in the hydra webhook
302
298
  // sdkEvent.data.personEmail =
303
299
  // activity.actor.emailAddress || activity.actor.entryEmail;
304
300
 
305
- sdkEvent.data.id =
306
- constructHydraId(hydraTypes.ATTACHMENT_ACTION, activity.id, cluster);
301
+ sdkEvent.data.id = constructHydraId(hydraTypes.ATTACHMENT_ACTION, activity.id, cluster);
307
302
  if (activity.object.inputs) {
308
303
  sdkEvent.data.inputs = activity.object.inputs;
309
304
  }
310
305
  sdkEvent.data.type = activity.object.objectType;
311
306
 
312
307
  return sdkEvent;
313
- }
314
- catch (e) {
308
+ } catch (e) {
315
309
  this.webex.logger.error(`Unable to generate SDK event from mercury \
316
310
  'socket activity for attachmentAction:${event} event: ${e.message}`);
317
311
 
318
312
  return null;
319
313
  }
320
- }
321
-
314
+ },
322
315
  });
323
316
 
324
317
  export default AttachmentActions;
@@ -19,24 +19,25 @@ describe('plugin-attachment-actions', function () {
19
19
  let creator, spock;
20
20
  let messageSender, buttonPusher;
21
21
 
22
- before(() => testUsers.create({count: 2})
23
- .then((users) => {
22
+ before(() =>
23
+ testUsers.create({count: 2}).then((users) => {
24
24
  [creator, spock] = users;
25
25
 
26
26
  // Creator will create the cards
27
27
  creator.webex = new WebexCore({
28
28
  credentials: {
29
- authorization: users[0].token
30
- }
29
+ authorization: users[0].token,
30
+ },
31
31
  });
32
32
 
33
33
  // Spock is the actor who will hit the Action.Submit button
34
34
  spock.webex = new WebexCore({
35
35
  credentials: {
36
- authorization: users[1].token
37
- }
36
+ authorization: users[1].token,
37
+ },
38
38
  });
39
- spock.webex.people.get('me')
39
+ spock.webex.people
40
+ .get('me')
40
41
  .then((person) => {
41
42
  buttonPusher = person;
42
43
 
@@ -45,7 +46,8 @@ describe('plugin-attachment-actions', function () {
45
46
  .then((person) => {
46
47
  messageSender = person;
47
48
  });
48
- }));
49
+ })
50
+ );
49
51
 
50
52
  // Stop listening for websocket events
51
53
  afterEach(() => {
@@ -58,7 +60,7 @@ describe('plugin-attachment-actions', function () {
58
60
  it('creates an attachment action and validates the attachment action created', () => {
59
61
  let message;
60
62
  const inputs = {
61
- formInput: 'test'
63
+ formInput: 'test',
62
64
  };
63
65
 
64
66
  // "Block" this test with a promise that will
@@ -70,67 +72,75 @@ describe('plugin-attachment-actions', function () {
70
72
  });
71
73
  });
72
74
 
73
- return creator.webex.attachmentActions.listen()
74
- // As the creator, send the card
75
- .then(() => creator.webex.messages.create({
76
- toPersonId: spock.id,
77
- text: 'Message',
78
- attachments: [
79
- {
80
- contentType: 'application/vnd.microsoft.card.adaptive',
81
- content: {
82
- type: 'AdaptiveCard',
83
- version: '1.0',
84
- body: [
75
+ return (
76
+ creator.webex.attachmentActions
77
+ .listen()
78
+ // As the creator, send the card
79
+ .then(() =>
80
+ creator.webex.messages
81
+ .create({
82
+ toPersonId: spock.id,
83
+ text: 'Message',
84
+ attachments: [
85
85
  {
86
- type: 'Input.Text',
87
- id: 'formInput',
88
- title: 'New Input.Toggle',
89
- placeholder: 'Placeholder text'
86
+ contentType: 'application/vnd.microsoft.card.adaptive',
87
+ content: {
88
+ type: 'AdaptiveCard',
89
+ version: '1.0',
90
+ body: [
91
+ {
92
+ type: 'Input.Text',
93
+ id: 'formInput',
94
+ title: 'New Input.Toggle',
95
+ placeholder: 'Placeholder text',
96
+ },
97
+ {
98
+ type: 'TextBlock',
99
+ text: 'Adaptive Cards',
100
+ separation: 'none',
101
+ },
102
+ ],
103
+ actions: [
104
+ {
105
+ type: 'Action.OpenUrl',
106
+ url: 'http://adaptivecards.io',
107
+ title: 'Learn More',
108
+ },
109
+ ],
110
+ },
90
111
  },
91
- {
92
- type: 'TextBlock',
93
- text: 'Adaptive Cards',
94
- separation: 'none'
95
- }
96
112
  ],
97
- actions: [
98
- {
99
- type: 'Action.OpenUrl',
100
- url: 'http://adaptivecards.io',
101
- title: 'Learn More'
102
- }
103
- ]
104
- }
105
- }
106
- ]
107
- })
108
- .then((m) => {
109
- message = m;
113
+ })
114
+ .then((m) => {
115
+ message = m;
110
116
 
111
- return spock.webex.attachmentActions.create({
112
- // As the other user emulate an Action.Submit button press
113
- type: 'submit',
114
- messageId: message.id,
115
- inputs
116
- });
117
- })
118
- .then(async (attachmentAction) => {
119
- try {
120
- validateAttachmentAction(attachmentAction, message,
121
- buttonPusher, inputs);
122
- const event = await created;
117
+ return spock.webex.attachmentActions.create({
118
+ // As the other user emulate an Action.Submit button press
119
+ type: 'submit',
120
+ messageId: message.id,
121
+ inputs,
122
+ });
123
+ })
124
+ .then(async (attachmentAction) => {
125
+ try {
126
+ validateAttachmentAction(attachmentAction, message, buttonPusher, inputs);
127
+ const event = await created;
123
128
 
124
- return validateAttachmentActionEvent(event, attachmentAction,
125
- messageSender, buttonPusher);
126
- }
127
- catch (e) {
128
- // eslint-disable-next-line no-console
129
- console.error(`Failed validating attachmentAction: ${e.message}`);
129
+ return validateAttachmentActionEvent(
130
+ event,
131
+ attachmentAction,
132
+ messageSender,
133
+ buttonPusher
134
+ );
135
+ } catch (e) {
136
+ // eslint-disable-next-line no-console
137
+ console.error(`Failed validating attachmentAction: ${e.message}`);
130
138
 
131
- return Promise.reject(e);
132
- }
133
- }));
139
+ return Promise.reject(e);
140
+ }
141
+ })
142
+ )
143
+ );
134
144
  });
135
145
  });
136
146
  });
@@ -139,7 +149,7 @@ describe('plugin-attachment-actions', function () {
139
149
  let attachmentAction0;
140
150
  let message;
141
151
  const inputs = {
142
- formInput: 'test'
152
+ formInput: 'test',
143
153
  };
144
154
 
145
155
  beforeEach(() => {
@@ -152,71 +162,79 @@ describe('plugin-attachment-actions', function () {
152
162
  });
153
163
  });
154
164
 
155
- return creator.webex.attachmentActions.listen()
156
- // As the creator, send the card
157
- .then(() => creator.webex.messages.create({
158
- toPersonId: spock.id,
159
- text: 'Message',
160
- attachments: [
161
- {
162
- contentType: 'application/vnd.microsoft.card.adaptive',
163
- content: {
164
- type: 'AdaptiveCard',
165
- version: '1.0',
166
- body: [
165
+ return (
166
+ creator.webex.attachmentActions
167
+ .listen()
168
+ // As the creator, send the card
169
+ .then(() =>
170
+ creator.webex.messages
171
+ .create({
172
+ toPersonId: spock.id,
173
+ text: 'Message',
174
+ attachments: [
167
175
  {
168
- type: 'Input.Text',
169
- id: 'formInput',
170
- title: 'New Input.Toggle',
171
- placeholder: 'Placeholder text'
176
+ contentType: 'application/vnd.microsoft.card.adaptive',
177
+ content: {
178
+ type: 'AdaptiveCard',
179
+ version: '1.0',
180
+ body: [
181
+ {
182
+ type: 'Input.Text',
183
+ id: 'formInput',
184
+ title: 'New Input.Toggle',
185
+ placeholder: 'Placeholder text',
186
+ },
187
+ {
188
+ type: 'TextBlock',
189
+ text: 'Adaptive Cards',
190
+ separation: 'none',
191
+ },
192
+ ],
193
+ actions: [
194
+ {
195
+ type: 'Action.OpenUrl',
196
+ url: 'http://adaptivecards.io',
197
+ title: 'Learn More',
198
+ },
199
+ ],
200
+ },
172
201
  },
173
- {
174
- type: 'TextBlock',
175
- text: 'Adaptive Cards',
176
- separation: 'none'
177
- }
178
202
  ],
179
- actions: [
180
- {
181
- type: 'Action.OpenUrl',
182
- url: 'http://adaptivecards.io',
183
- title: 'Learn More'
184
- }
185
- ]
186
- }
187
- }
188
- ]
189
- })
190
- .then((m) => {
191
- message = m;
203
+ })
204
+ .then((m) => {
205
+ message = m;
192
206
 
193
- return spock.webex.attachmentActions.create({
194
- type: 'submit',
195
- messageId: message.id,
196
- inputs
197
- });
198
- })
199
- .then(async (attachmentAction) => {
200
- try {
201
- attachmentAction0 = attachmentAction;
202
- validateAttachmentAction(attachmentAction, message,
203
- buttonPusher, inputs);
204
- const event = await created;
207
+ return spock.webex.attachmentActions.create({
208
+ type: 'submit',
209
+ messageId: message.id,
210
+ inputs,
211
+ });
212
+ })
213
+ .then(async (attachmentAction) => {
214
+ try {
215
+ attachmentAction0 = attachmentAction;
216
+ validateAttachmentAction(attachmentAction, message, buttonPusher, inputs);
217
+ const event = await created;
205
218
 
206
- return validateAttachmentActionEvent(event, attachmentAction,
207
- messageSender, buttonPusher);
208
- }
209
- catch (e) {
210
- // eslint-disable-next-line no-console
211
- console.error(`Failed validating attachmentAction: ${e.message}`);
219
+ return validateAttachmentActionEvent(
220
+ event,
221
+ attachmentAction,
222
+ messageSender,
223
+ buttonPusher
224
+ );
225
+ } catch (e) {
226
+ // eslint-disable-next-line no-console
227
+ console.error(`Failed validating attachmentAction: ${e.message}`);
212
228
 
213
- return Promise.reject(e);
214
- }
215
- }));
229
+ return Promise.reject(e);
230
+ }
231
+ })
232
+ )
233
+ );
216
234
  });
217
235
 
218
- it('retrieves a specific attachment action', () => spock.webex.attachmentActions.get(attachmentAction0)
219
- .then((attachmentAction) => {
236
+ it('retrieves a specific attachment action', () =>
237
+ spock.webex.attachmentActions.get(attachmentAction0).then((attachmentAction) => {
220
238
  validateAttachmentAction(attachmentAction, message, buttonPusher, inputs);
221
239
  }));
222
240
  });
@@ -238,14 +256,13 @@ function validateAttachmentAction(attachmentAction, message, actor, data) {
238
256
  assert.isObject(attachmentAction.inputs);
239
257
  assert.equal(attachmentAction.personId, actor.id);
240
258
 
241
- if ((data) && (typeof data === 'object')) {
259
+ if (data && typeof data === 'object') {
242
260
  Object.entries(data).forEach((entry) => {
243
261
  assert.propertyVal(attachmentAction.inputs, entry[0], entry[1]);
244
262
  });
245
263
  }
246
264
  }
247
265
 
248
-
249
266
  /**
250
267
  * Validate an AttachmentAction event.
251
268
  * @param {Object} event - attachmentAction event
@@ -255,37 +272,53 @@ function validateAttachmentAction(attachmentAction, message, actor, data) {
255
272
  * @returns {void}
256
273
  */
257
274
  function validateAttachmentActionEvent(event, attachmentAction, messageSender, buttonPusher) {
258
- assert.isTrue(event.resource ===
259
- SDK_EVENT.EXTERNAL.RESOURCE.ATTACHMENT_ACTIONS,
260
- 'not an attachmentAction event');
275
+ assert.isTrue(
276
+ event.resource === SDK_EVENT.EXTERNAL.RESOURCE.ATTACHMENT_ACTIONS,
277
+ 'not an attachmentAction event'
278
+ );
261
279
  assert.isDefined(event.event, 'attachmentAction event type not set');
262
280
  assert.isDefined(event.created, 'event listener created date not set');
263
- assert.equal(event.createdBy, messageSender.id,
264
- 'event listener createdBy not set to our messageSender');
265
- assert.equal(event.orgId, messageSender.orgId,
266
- 'event listener orgId not === to our messageSender\'s');
281
+ assert.equal(
282
+ event.createdBy,
283
+ messageSender.id,
284
+ 'event listener createdBy not set to our messageSender'
285
+ );
286
+ assert.equal(
287
+ event.orgId,
288
+ messageSender.orgId,
289
+ "event listener orgId not === to our messageSender's"
290
+ );
267
291
  assert.equal(event.ownedBy, 'creator', 'event listener not owned by creator');
268
292
  assert.equal(event.status, 'active', 'event listener status not active');
269
- assert.equal(event.actorId, buttonPusher.id,
270
- 'event actorId not equal to our buttonPusher\'s id');
293
+ assert.equal(event.actorId, buttonPusher.id, "event actorId not equal to our buttonPusher's id");
271
294
 
272
295
  // Ensure event data matches data returned from function call
273
- assert.equal(event.data.id, attachmentAction.id,
274
- 'event/attachmentAction.id not equal');
275
- assert.equal(event.data.roomId, attachmentAction.roomId,
276
- 'event/attachmentAction.roomId not equal');
277
- assert.equal(event.data.personId, attachmentAction.personId,
278
- 'event/attachmentAction.personId not equal');
279
- assert.equal(event.data.personEmail, attachmentAction.personEmail,
280
- 'event/attachmentAction.personEmail not equal');
281
- assert.equal(event.data.roomType, attachmentAction.roomType,
282
- 'event/attachmentAction.roomType not equal');
296
+ assert.equal(event.data.id, attachmentAction.id, 'event/attachmentAction.id not equal');
297
+ assert.equal(
298
+ event.data.roomId,
299
+ attachmentAction.roomId,
300
+ 'event/attachmentAction.roomId not equal'
301
+ );
302
+ assert.equal(
303
+ event.data.personId,
304
+ attachmentAction.personId,
305
+ 'event/attachmentAction.personId not equal'
306
+ );
307
+ assert.equal(
308
+ event.data.personEmail,
309
+ attachmentAction.personEmail,
310
+ 'event/attachmentAction.personEmail not equal'
311
+ );
312
+ assert.equal(
313
+ event.data.roomType,
314
+ attachmentAction.roomType,
315
+ 'event/attachmentAction.roomType not equal'
316
+ );
283
317
 
284
- if ((event.data.inputs) && (typeof event.data.inputs === 'object')) {
318
+ if (event.data.inputs && typeof event.data.inputs === 'object') {
285
319
  assert.isObject(attachmentAction.inputs);
286
320
  Object.entries(event.data.inputs).forEach((entry) => {
287
321
  assert.propertyVal(attachmentAction.inputs, entry[0], entry[1]);
288
322
  });
289
323
  }
290
324
  }
291
-