@webex/plugin-attachment-actions 2.59.3-next.1 → 2.59.4

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.
@@ -1,317 +1,317 @@
1
- /*!
2
- * Copyright (c) 2015-2017 Cisco Systems, Inc. See LICENSE file.
3
- */
4
-
5
- import {WebexPlugin} from '@webex/webex-core';
6
- import {
7
- SDK_EVENT,
8
- createEventEnvelope,
9
- constructHydraId,
10
- getHydraClusterString,
11
- hydraTypes,
12
- } from '@webex/common';
13
- import {cloneDeep} from 'lodash';
14
-
15
- const debug = require('debug')('attachmentActions');
16
-
17
- /**
18
- * @typedef {Object} AttachmentActionObject
19
- * @property {string} id - (server generated) Unique identifier for the attachment action
20
- * @property {string} messageId - The ID of the message in which attachment action is to be performed
21
- * @property {string} type - The type of attachment action eg., submit
22
- * @property {Object} inputs - The inputs for form fields in attachment message
23
- * @property {string} personId - (server generated) The ID for the author of the attachment action
24
- * @property {string} roomId - (server generated) The ID for the room of the message
25
- * @property {isoDate} created - (server generated) The date and time that the message was created
26
- */
27
-
28
- /**
29
- * AttachmentActions are events that communicate information when a user clicks on an
30
- * Action.Submit button in a card displayed in Webex
31
- * Information conveyed in an AttachmentAction includes details about the user that
32
- * clicked the button along with any card specific inputs. See the
33
- * {@link https://developer.webex.com/docs/api/v1/attachment-actions|Attachments Actions API Documentation}
34
- * for more details
35
- * @class
36
- */
37
- const AttachmentActions = WebexPlugin.extend({
38
- /**
39
- * Initializer used to generate AttachmentActions
40
- * as a plugin wrapped around the provided arguments.
41
- * @private
42
- * @see WebexPlugin.initialize
43
- * @param {...any} args
44
- * @returns {undefined}
45
- */
46
- initialize(...args) {
47
- Reflect.apply(WebexPlugin.prototype.initialize, this, args);
48
- },
49
-
50
- /**
51
- * Register to listen for incoming attachmentAction events
52
- * This is an alternate approach to registering for attachmentAction webhooks.
53
- * The events passed to any registered handlers will be similar to the webhook JSON,
54
- * but will omit webhook specific fields such as name, secret, url, etc.
55
- * The attachmentActions.listen() event objects can also include additional fields not
56
- * available in the webhook's JSON payload, specifically: `inputs`.
57
- * To utilize the `listen()` method, the authorization token used
58
- * will need to have `spark:all` and `spark:kms` scopes enabled.
59
- * Note that by configuring your application to enable or disable `spark:all`
60
- * via its configuration page will also enable or disable `spark:kms`.
61
- * See the <a href="https://webex.github.io/webex-js-sdk/samples/browser-socket/">Sample App</a>
62
- * for more details.
63
- * @instance
64
- * @memberof Messages
65
- * @returns {Promise}
66
- * @example
67
- * webex.attachmentActions.listen()
68
- * .then(() => {
69
- * console.log('listening to attachmentActions events');
70
- * webex.attachmentActions.on('created', (event) => console.log(`Got an attachmentActions:created event:\n${event}`));
71
- * })
72
- * .catch((e) => console.error(`Unable to register for attachmentAction events: ${e}`));
73
- * // Some app logic...
74
- * // WHen it is time to cleanup
75
- * webex.attachmentActions.stopListening();
76
- * webex.attachmentActions.off('created');
77
- */
78
- listen() {
79
- // Create a common envelope that we will wrap all events in
80
- return createEventEnvelope(this.webex, SDK_EVENT.EXTERNAL.RESOURCE.ATTACHMENT_ACTIONS).then(
81
- (envelope) => {
82
- this.eventEnvelope = envelope;
83
-
84
- // Register to listen to events
85
- return this.webex.internal.mercury.connect().then(() => {
86
- this.listenTo(this.webex.internal.mercury, SDK_EVENT.INTERNAL.WEBEX_ACTIVITY, (event) =>
87
- this.onWebexApiEvent(event)
88
- );
89
- });
90
- }
91
- );
92
- },
93
-
94
- /**
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
- */
159
- create(attachmentAction) {
160
- return this.request({
161
- method: 'POST',
162
- service: 'hydra',
163
- resource: 'attachment/actions',
164
- body: attachmentAction,
165
- }).then((res) => res.body);
166
- },
167
-
168
- /**
169
- * Returns a single attachment action.
170
- * @instance
171
- * @memberof AttachmentActions
172
- * @param {string} attachmentAction
173
- * @returns {Promise<AttachmentActionObject>}
174
- * @example
175
- * var attachmentAction;
176
- * webex.rooms.create({title: 'Get Message Example'})
177
- * .then(function(room) {
178
- * return webex.messages.create({
179
- * text: 'Howdy!',
180
- * roomId: room.id,
181
- * attachments:[ {
182
- * contentType: 'application/vnd.microsoft.card.adaptive',
183
- * content: {
184
- * type: 'AdaptiveCard',
185
- * version: '1.0',
186
- * body: [
187
- * {
188
- * type: 'TextBlock',
189
- * text: '',
190
- * size: 'large'
191
- * },
192
- * {
193
- * type: 'TextBlock',
194
- * text: 'Adaptive Cards',
195
- * separation: 'none'
196
- * },
197
- * {
198
- * type: 'Input.Date',
199
- * id: 'dueDate'
200
- * }
201
- * ],
202
- * actions: [
203
- * {
204
- * type: 'Action.Submit',
205
- * title: 'Due Date'
206
- * }
207
- * ]
208
- * }
209
- * }]
210
- * });
211
- * })
212
- * .then(function(message) {
213
- * return webex.attachmentActions.create({
214
- * type: 'submit',
215
- * messageId: message.id,
216
- * inputs:{
217
- * dueDate: '26/06/1995'
218
- * });
219
- * })
220
- * .then(function(attachmentAction) {
221
- * return webex.attachmentActions.get(attachmentAction.id)
222
- * })
223
- * .then(function(attachmentAction){
224
- * var assert = require('assert');
225
- * assert.deepEqual(attachmentAction, attachmentAction);
226
- * return 'success';
227
- * })
228
- * // => success
229
- */
230
- get(attachmentAction) {
231
- const id = attachmentAction.id || attachmentAction;
232
-
233
- return this.request({
234
- service: 'hydra',
235
- resource: `attachment/actions/${id}`,
236
- }).then((res) => res.body.items || res.body);
237
- },
238
-
239
- /**
240
- * This function is called when an internal mercury events fires,
241
- * if the user registered for these events with the listen() function.
242
- * External users of the SDK should not call this function
243
- * @private
244
- * @memberof AttachmentAction
245
- * @param {Object} event
246
- * @returns {void}
247
- */
248
- onWebexApiEvent(event) {
249
- const {activity} = event.data;
250
-
251
- /* eslint-disable no-case-declarations */
252
- switch (activity.verb) {
253
- case SDK_EVENT.INTERNAL.ACTIVITY_VERB.CARD_ACTION:
254
- const createdEvent = this.getattachmentActionEvent(
255
- activity,
256
- SDK_EVENT.EXTERNAL.EVENT_TYPE.CREATED
257
- );
258
-
259
- if (createdEvent) {
260
- debug(`attachmentAction "created" payload: \
261
- ${JSON.stringify(createdEvent)}`);
262
- this.trigger(SDK_EVENT.EXTERNAL.EVENT_TYPE.CREATED, createdEvent);
263
- }
264
- break;
265
-
266
- default: {
267
- break;
268
- }
269
- }
270
- },
271
-
272
- /**
273
- * Constructs the data object for an event on the attachmentAction resource,
274
- * adhering to Hydra's Webhook data structure messages.
275
- * External users of the SDK should not call this function
276
- * @private
277
- * @memberof AttachmentAction
278
- * @param {Object} activity from mercury
279
- * @param {Object} event type of "webhook" event
280
- * @returns {Object} constructed event
281
- */
282
- getattachmentActionEvent(activity, event) {
283
- try {
284
- const sdkEvent = cloneDeep(this.eventEnvelope);
285
- const cluster = getHydraClusterString(this.webex, activity.target.url);
286
-
287
- sdkEvent.event = event;
288
- sdkEvent.data.created = activity.published;
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
- );
297
- // Seems like it would be nice to have this, but its not in the hydra webhook
298
- // sdkEvent.data.personEmail =
299
- // activity.actor.emailAddress || activity.actor.entryEmail;
300
-
301
- sdkEvent.data.id = constructHydraId(hydraTypes.ATTACHMENT_ACTION, activity.id, cluster);
302
- if (activity.object.inputs) {
303
- sdkEvent.data.inputs = activity.object.inputs;
304
- }
305
- sdkEvent.data.type = activity.object.objectType;
306
-
307
- return sdkEvent;
308
- } catch (e) {
309
- this.webex.logger.error(`Unable to generate SDK event from mercury \
310
- 'socket activity for attachmentAction:${event} event: ${e.message}`);
311
-
312
- return null;
313
- }
314
- },
315
- });
316
-
317
- export default AttachmentActions;
1
+ /*!
2
+ * Copyright (c) 2015-2017 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ import {WebexPlugin} from '@webex/webex-core';
6
+ import {
7
+ SDK_EVENT,
8
+ createEventEnvelope,
9
+ constructHydraId,
10
+ getHydraClusterString,
11
+ hydraTypes,
12
+ } from '@webex/common';
13
+ import {cloneDeep} from 'lodash';
14
+
15
+ const debug = require('debug')('attachmentActions');
16
+
17
+ /**
18
+ * @typedef {Object} AttachmentActionObject
19
+ * @property {string} id - (server generated) Unique identifier for the attachment action
20
+ * @property {string} messageId - The ID of the message in which attachment action is to be performed
21
+ * @property {string} type - The type of attachment action eg., submit
22
+ * @property {Object} inputs - The inputs for form fields in attachment message
23
+ * @property {string} personId - (server generated) The ID for the author of the attachment action
24
+ * @property {string} roomId - (server generated) The ID for the room of the message
25
+ * @property {isoDate} created - (server generated) The date and time that the message was created
26
+ */
27
+
28
+ /**
29
+ * AttachmentActions are events that communicate information when a user clicks on an
30
+ * Action.Submit button in a card displayed in Webex
31
+ * Information conveyed in an AttachmentAction includes details about the user that
32
+ * clicked the button along with any card specific inputs. See the
33
+ * {@link https://developer.webex.com/docs/api/v1/attachment-actions|Attachments Actions API Documentation}
34
+ * for more details
35
+ * @class
36
+ */
37
+ const AttachmentActions = WebexPlugin.extend({
38
+ /**
39
+ * Initializer used to generate AttachmentActions
40
+ * as a plugin wrapped around the provided arguments.
41
+ * @private
42
+ * @see WebexPlugin.initialize
43
+ * @param {...any} args
44
+ * @returns {undefined}
45
+ */
46
+ initialize(...args) {
47
+ Reflect.apply(WebexPlugin.prototype.initialize, this, args);
48
+ },
49
+
50
+ /**
51
+ * Register to listen for incoming attachmentAction events
52
+ * This is an alternate approach to registering for attachmentAction webhooks.
53
+ * The events passed to any registered handlers will be similar to the webhook JSON,
54
+ * but will omit webhook specific fields such as name, secret, url, etc.
55
+ * The attachmentActions.listen() event objects can also include additional fields not
56
+ * available in the webhook's JSON payload, specifically: `inputs`.
57
+ * To utilize the `listen()` method, the authorization token used
58
+ * will need to have `spark:all` and `spark:kms` scopes enabled.
59
+ * Note that by configuring your application to enable or disable `spark:all`
60
+ * via its configuration page will also enable or disable `spark:kms`.
61
+ * See the <a href="https://webex.github.io/webex-js-sdk/samples/browser-socket/">Sample App</a>
62
+ * for more details.
63
+ * @instance
64
+ * @memberof Messages
65
+ * @returns {Promise}
66
+ * @example
67
+ * webex.attachmentActions.listen()
68
+ * .then(() => {
69
+ * console.log('listening to attachmentActions events');
70
+ * webex.attachmentActions.on('created', (event) => console.log(`Got an attachmentActions:created event:\n${event}`));
71
+ * })
72
+ * .catch((e) => console.error(`Unable to register for attachmentAction events: ${e}`));
73
+ * // Some app logic...
74
+ * // WHen it is time to cleanup
75
+ * webex.attachmentActions.stopListening();
76
+ * webex.attachmentActions.off('created');
77
+ */
78
+ listen() {
79
+ // Create a common envelope that we will wrap all events in
80
+ return createEventEnvelope(this.webex, SDK_EVENT.EXTERNAL.RESOURCE.ATTACHMENT_ACTIONS).then(
81
+ (envelope) => {
82
+ this.eventEnvelope = envelope;
83
+
84
+ // Register to listen to events
85
+ return this.webex.internal.mercury.connect().then(() => {
86
+ this.listenTo(this.webex.internal.mercury, SDK_EVENT.INTERNAL.WEBEX_ACTIVITY, (event) =>
87
+ this.onWebexApiEvent(event)
88
+ );
89
+ });
90
+ }
91
+ );
92
+ },
93
+
94
+ /**
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
+ */
159
+ create(attachmentAction) {
160
+ return this.request({
161
+ method: 'POST',
162
+ service: 'hydra',
163
+ resource: 'attachment/actions',
164
+ body: attachmentAction,
165
+ }).then((res) => res.body);
166
+ },
167
+
168
+ /**
169
+ * Returns a single attachment action.
170
+ * @instance
171
+ * @memberof AttachmentActions
172
+ * @param {string} attachmentAction
173
+ * @returns {Promise<AttachmentActionObject>}
174
+ * @example
175
+ * var attachmentAction;
176
+ * webex.rooms.create({title: 'Get Message Example'})
177
+ * .then(function(room) {
178
+ * return webex.messages.create({
179
+ * text: 'Howdy!',
180
+ * roomId: room.id,
181
+ * attachments:[ {
182
+ * contentType: 'application/vnd.microsoft.card.adaptive',
183
+ * content: {
184
+ * type: 'AdaptiveCard',
185
+ * version: '1.0',
186
+ * body: [
187
+ * {
188
+ * type: 'TextBlock',
189
+ * text: '',
190
+ * size: 'large'
191
+ * },
192
+ * {
193
+ * type: 'TextBlock',
194
+ * text: 'Adaptive Cards',
195
+ * separation: 'none'
196
+ * },
197
+ * {
198
+ * type: 'Input.Date',
199
+ * id: 'dueDate'
200
+ * }
201
+ * ],
202
+ * actions: [
203
+ * {
204
+ * type: 'Action.Submit',
205
+ * title: 'Due Date'
206
+ * }
207
+ * ]
208
+ * }
209
+ * }]
210
+ * });
211
+ * })
212
+ * .then(function(message) {
213
+ * return webex.attachmentActions.create({
214
+ * type: 'submit',
215
+ * messageId: message.id,
216
+ * inputs:{
217
+ * dueDate: '26/06/1995'
218
+ * });
219
+ * })
220
+ * .then(function(attachmentAction) {
221
+ * return webex.attachmentActions.get(attachmentAction.id)
222
+ * })
223
+ * .then(function(attachmentAction){
224
+ * var assert = require('assert');
225
+ * assert.deepEqual(attachmentAction, attachmentAction);
226
+ * return 'success';
227
+ * })
228
+ * // => success
229
+ */
230
+ get(attachmentAction) {
231
+ const id = attachmentAction.id || attachmentAction;
232
+
233
+ return this.request({
234
+ service: 'hydra',
235
+ resource: `attachment/actions/${id}`,
236
+ }).then((res) => res.body.items || res.body);
237
+ },
238
+
239
+ /**
240
+ * This function is called when an internal mercury events fires,
241
+ * if the user registered for these events with the listen() function.
242
+ * External users of the SDK should not call this function
243
+ * @private
244
+ * @memberof AttachmentAction
245
+ * @param {Object} event
246
+ * @returns {void}
247
+ */
248
+ onWebexApiEvent(event) {
249
+ const {activity} = event.data;
250
+
251
+ /* eslint-disable no-case-declarations */
252
+ switch (activity.verb) {
253
+ case SDK_EVENT.INTERNAL.ACTIVITY_VERB.CARD_ACTION:
254
+ const createdEvent = this.getattachmentActionEvent(
255
+ activity,
256
+ SDK_EVENT.EXTERNAL.EVENT_TYPE.CREATED
257
+ );
258
+
259
+ if (createdEvent) {
260
+ debug(`attachmentAction "created" payload: \
261
+ ${JSON.stringify(createdEvent)}`);
262
+ this.trigger(SDK_EVENT.EXTERNAL.EVENT_TYPE.CREATED, createdEvent);
263
+ }
264
+ break;
265
+
266
+ default: {
267
+ break;
268
+ }
269
+ }
270
+ },
271
+
272
+ /**
273
+ * Constructs the data object for an event on the attachmentAction resource,
274
+ * adhering to Hydra's Webhook data structure messages.
275
+ * External users of the SDK should not call this function
276
+ * @private
277
+ * @memberof AttachmentAction
278
+ * @param {Object} activity from mercury
279
+ * @param {Object} event type of "webhook" event
280
+ * @returns {Object} constructed event
281
+ */
282
+ getattachmentActionEvent(activity, event) {
283
+ try {
284
+ const sdkEvent = cloneDeep(this.eventEnvelope);
285
+ const cluster = getHydraClusterString(this.webex, activity.target.url);
286
+
287
+ sdkEvent.event = event;
288
+ sdkEvent.data.created = activity.published;
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
+ );
297
+ // Seems like it would be nice to have this, but its not in the hydra webhook
298
+ // sdkEvent.data.personEmail =
299
+ // activity.actor.emailAddress || activity.actor.entryEmail;
300
+
301
+ sdkEvent.data.id = constructHydraId(hydraTypes.ATTACHMENT_ACTION, activity.id, cluster);
302
+ if (activity.object.inputs) {
303
+ sdkEvent.data.inputs = activity.object.inputs;
304
+ }
305
+ sdkEvent.data.type = activity.object.objectType;
306
+
307
+ return sdkEvent;
308
+ } catch (e) {
309
+ this.webex.logger.error(`Unable to generate SDK event from mercury \
310
+ 'socket activity for attachmentAction:${event} event: ${e.message}`);
311
+
312
+ return null;
313
+ }
314
+ },
315
+ });
316
+
317
+ export default AttachmentActions;
package/src/index.js CHANGED
@@ -1,14 +1,14 @@
1
- /*!
2
- * Copyright (c) 2015-2017 Cisco Systems, Inc. See LICENSE file.
3
- */
4
-
5
- import '@webex/internal-plugin-conversation'; // decrypt mercury activities
6
- import '@webex/internal-plugin-mercury';
7
-
8
- import {registerPlugin} from '@webex/webex-core';
9
-
10
- import AttachmentActions from './attachmentActions';
11
-
12
- registerPlugin('attachmentActions', AttachmentActions);
13
-
14
- export default AttachmentActions;
1
+ /*!
2
+ * Copyright (c) 2015-2017 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ import '@webex/internal-plugin-conversation'; // decrypt mercury activities
6
+ import '@webex/internal-plugin-mercury';
7
+
8
+ import {registerPlugin} from '@webex/webex-core';
9
+
10
+ import AttachmentActions from './attachmentActions';
11
+
12
+ registerPlugin('attachmentActions', AttachmentActions);
13
+
14
+ export default AttachmentActions;