n8n/packages/nodes-base/nodes/Cisco/Webex/CiscoWebex.node.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

564 lines
16 KiB
TypeScript
Raw Normal View History

import type {
IDataObject,
IExecuteFunctions,
ILoadOptionsFunctions,
INodeExecutionData,
INodePropertyOptions,
INodeType,
INodeTypeDescription,
} from 'n8n-workflow';
import moment from 'moment-timezone';
import { getAttachments, webexApiRequest, webexApiRequestAllItems } from './GenericFunctions';
import {
meetingFields,
meetingOperations,
// meetingTranscriptFields,
// meetingTranscriptOperations,
messageFields,
messageOperations,
} from './descriptions';
export class CiscoWebex implements INodeType {
description: INodeTypeDescription = {
displayName: 'Webex by Cisco',
name: 'ciscoWebex',
refactor: Apply more `eslint-plugin-n8n-nodes-base` rules (#3534) * :zap: Update `lintfix` script * :zap: Run baseline `lintfix` * :fire: Remove unneeded exceptions (#3538) * :fire: Remove exceptions for `node-param-default-wrong-for-simplify` * :fire: Remove exceptions for `node-param-placeholder-miscased-id` * :zap: Update version * :shirt: Apply `node-param-placeholder-missing` (#3542) * :shirt: Apply `filesystem-wrong-cred-filename` (#3543) * :shirt: Apply `node-param-description-missing-from-dynamic-options` (#3545) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :shirt: Apply `node-class-description-empty-string` (#3546) * :shirt: Apply `node-class-description-icon-not-svg` (#3548) * :shirt: Apply `filesystem-wrong-node-filename` (#3549) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :shirt: Expand lintings to credentials (#3550) * :shirt: Apply `node-param-multi-options-type-unsorted-items` (#3552) * :zap: fix * :zap: Minor fixes Co-authored-by: Michael Kret <michael.k@radency.com> * :shirt: Apply `node-param-description-wrong-for-dynamic-multi-options` (#3541) * :zap: Add new lint rule, node-param-description-wrong-for-dynamic-multi-options * :zap: Fix with updated linting rules * :zap: Minor fixes Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :shirt: Apply `node-param-description-boolean-without-whether` (#3553) * :zap: fix * Update packages/nodes-base/nodes/Clockify/ProjectDescription.ts Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :shirt: Apply node-param-display-name-wrong-for-dynamic-multi-options (#3537) * :shirt: Add exceptions * :shirt: Add exception * :pencil2: Alphabetize rules * :zap: Restore `lintfix` command Co-authored-by: agobrech <45268029+agobrech@users.noreply.github.com> Co-authored-by: Omar Ajoue <krynble@gmail.com> Co-authored-by: Michael Kret <michael.k@radency.com> Co-authored-by: brianinoa <54530642+brianinoa@users.noreply.github.com> Co-authored-by: Michael Kret <88898367+michael-radency@users.noreply.github.com>
2022-06-20 07:54:01 -07:00
// eslint-disable-next-line n8n-nodes-base/node-class-description-icon-not-svg
2021-08-05 10:06:28 -07:00
icon: 'file:ciscoWebex.png',
group: ['transform'],
version: 1,
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
description: 'Consume the Cisco Webex API',
defaults: {
feat(editor): Node creator actions (#4696) * WIP: Node Actions List UI * WIP: Recommended Actions and preseting of fields * WIP: Resource category * :art: Moved actions categorisation to the server * :label: Add missing INodeAction type * :sparkles: Improve SSR categorisation, fix adding of mixed actions * :recycle: Refactor CategorizedItems to composition api, style fixes * WIP: Adding multiple nodes * :recycle: Refactor rest of the NodeCreator component to composition API, conver globalLinkActions to composable * :sparkles: Allow actions dragging, fix search and refactor passing of actions to categorized items * :lipstick: Fix node actions title * Migrate to the pinia store, add posthog feature and various fixes * :bug: Fix filtering of trigger actions when not merged * fix: N8N-5439 — Do not use simple node item when at NodeHelperPanel root * :bug: Design review fixes * :bug: Fix disabling of merged actions * Fix trigger root filtering * :sparkles: Allow for custom node actions parser, introduce hubspot parser * :bug: Fix initial node params validation, fix position of second added node * :bug: Introduce operations category, removed canvas node names overrride, fix API actions display and prevent dragging of action nodes * :sparkles: Prevent NDV auto-open feature flag * :bug: Inject recommened action for trigger nodes without actions * Refactored NodeCreatorNode to Storybook, change filtering of merged nodes for the trigger helper panel, minor fixes * Improve rendering of app nodes and animation * Cleanup, any only enable accordion transition on triggerhelperpanel * Hide node creator scrollbars in Firefox * Minor styles fixes * Do not copy the array in rendering method * Removed unused props * Fix memory leak * Fix categorisation of regular nodes with a single resource * Implement telemetry calls for node actions * Move categorization to FE * Fix client side actions categorisation * Skip custom action show * Only load tooltip for NodeIcon if necessary * Fix lodash startCase import * Remove lodash.startcase * Cleanup * Fix node creator autofocus on "tab" * Prevent posthog getFeatureFlag from crashing * Debugging preview env search issues * Remove logs * Make sure the pre-filled params are update not overwritten * Get rid of transition in itemiterator * WIP: Rough version of NodeActions keyboard navigation, replace nodeCreator composable with Pinia store module * Rewrite to add support for ActionItem to ItemIterator and make CategorizedItems accept items props * Fix category item counter & cleanup * Add APIHint to actions search no-result, clean up NodeCreatorNode * Improve node actions no results message * Remove logging, fix filtering of recommended placeholder category * Remove unused NodeActions component and node merging feature falg * Do not show regular nodes without actions * Make sure to add manual trigger when adding http node via actions hint * Fixed api hint footer line height * Prevent pointer-events od NodeIcon img and remove "this" from template * Address PR points * Fix e2e specs * Make sure canvas ia loaded * Make sure canvas ia loaded before opening nodeCreator in e2e spec * Fix flaky workflows tags e2e getter * Imrpove node creator click outside UX, add manual node to regular nodes added from trigger panel * Add manual trigger node if dragging regular from trigger panel
2022-12-09 01:56:36 -08:00
name: 'Webex by Cisco',
},
credentials: [
{
name: 'ciscoWebexOAuth2Api',
required: true,
},
],
inputs: ['main'],
outputs: ['main'],
properties: [
{
displayName: 'Resource',
name: 'resource',
type: 'options',
refactor: Apply more nodelinting rules (#3324) * :pencil2: Alphabetize lint rules * :fire: Remove duplicates * :zap: Update `lintfix` script * :shirt: Apply `node-param-operation-without-no-data-expression` (#3329) * :shirt: Apply `node-param-operation-without-no-data-expression` * :shirt: Add exceptions * :shirt: Apply `node-param-description-weak` (#3328) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :shirt: Apply `node-param-option-value-duplicate` (#3331) * :shirt: Apply `node-param-description-miscased-json` (#3337) * :shirt: Apply `node-param-display-name-excess-inner-whitespace` (#3335) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :shirt: Apply `node-param-type-options-missing-from-limit` (#3336) * Rule workig as intended * :pencil2: Uncomment rules Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :shirt: Apply `node-param-option-name-duplicate` (#3338) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :shirt: Apply `node-param-description-wrong-for-simplify` (#3334) * :zap: fix * :zap: exceptions * :zap: changed rule ignoring from file to line * :shirt: Apply `node-param-resource-without-no-data-expression` (#3339) * :shirt: Apply `node-param-display-name-untrimmed` (#3341) * :shirt: Apply `node-param-display-name-miscased-id` (#3340) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :shirt: Apply `node-param-resource-with-plural-option` (#3342) * :shirt: Apply `node-param-description-wrong-for-upsert` (#3333) * :zap: fix * :zap: replaced record with contact in description * :zap: fix Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :shirt: Apply `node-param-option-description-identical-to-name` (#3343) * :shirt: Apply `node-param-option-name-containing-star` (#3347) * :shirt: Apply `node-param-display-name-wrong-for-update-fields` (#3348) * :shirt: Apply `node-param-option-name-wrong-for-get-all` (#3345) * :zap: fix * :zap: exceptions * :shirt: Apply node-param-display-name-wrong-for-simplify (#3344) * Rule working as intended * Uncomented other rules * :shirt: Undo and add exceptions Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :zap: Alphabetize lint rules * :zap: Restore `lintfix` script Co-authored-by: Michael Kret <88898367+michael-radency@users.noreply.github.com> Co-authored-by: agobrech <45268029+agobrech@users.noreply.github.com>
2022-05-20 14:47:24 -07:00
noDataExpression: true,
options: [
{
name: 'Meeting',
value: 'meeting',
},
// {
// name: 'Meeeting Transcript',
// value: 'meetingTranscript',
// },
{
name: 'Message',
value: 'message',
},
],
default: 'message',
},
...meetingOperations,
...meetingFields,
// ...meetingTranscriptOperations,
// ...meetingTranscriptFields,
...messageOperations,
...messageFields,
],
};
methods = {
loadOptions: {
async getRooms(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
const rooms = await webexApiRequestAllItems.call(this, 'items', 'GET', '/rooms');
for (const room of rooms) {
returnData.push({
name: room.title,
value: room.id,
});
}
return returnData;
},
async getSites(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
const sites = await webexApiRequestAllItems.call(
this,
'sites',
'GET',
'/meetingPreferences/sites',
);
for (const site of sites) {
returnData.push({
name: site.siteUrl,
value: site.siteUrl,
});
}
return returnData;
},
},
};
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
const returnData: INodeExecutionData[] = [];
const timezone = this.getTimezone();
const resource = this.getNodeParameter('resource', 0);
const operation = this.getNodeParameter('operation', 0);
let responseData;
for (let i = 0; i < items.length; i++) {
try {
if (resource === 'message') {
// **********************************************************************
// message
// **********************************************************************
if (operation === 'create') {
// ----------------------------------------
// message: create
// ----------------------------------------
// https://developer.webex.com/docs/api/v1/messages/create-a-message
const destination = this.getNodeParameter('destination', i);
const file = this.getNodeParameter(
'additionalFields.fileUi.fileValue',
i,
{},
) as IDataObject;
const markdown = this.getNodeParameter('additionalFields.markdown', i, '') as boolean;
const body = {} as IDataObject;
if (destination === 'room') {
body.roomId = this.getNodeParameter('roomId', i);
}
if (destination === 'person') {
const specifyPersonBy = this.getNodeParameter('specifyPersonBy', 0) as string;
if (specifyPersonBy === 'id') {
body.toPersonId = this.getNodeParameter('toPersonId', i);
} else {
body.toPersonEmail = this.getNodeParameter('toPersonEmail', i);
}
}
if (markdown) {
body.markdown = markdown;
}
body.text = this.getNodeParameter('text', i);
body.attachments = getAttachments(
this.getNodeParameter(
'additionalFields.attachmentsUi.attachmentValues',
i,
[],
) as IDataObject[],
);
if (Object.keys(file).length) {
const isBinaryData = file.fileLocation === 'binaryData' ? true : false;
if (isBinaryData) {
const binaryPropertyName = file.binaryPropertyName as string;
const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(
i,
binaryPropertyName,
);
const formData = {
files: {
value: binaryDataBuffer,
options: {
filename: binaryData.fileName,
contentType: binaryData.mimeType,
},
},
};
Object.assign(body, formData);
} else {
const url = file.url as string;
Object.assign(body, { files: url });
}
}
if (file.fileLocation === 'binaryData') {
responseData = await webexApiRequest.call(
this,
'POST',
'/messages',
{},
{},
undefined,
{ formData: body },
);
} else {
responseData = await webexApiRequest.call(this, 'POST', '/messages', body);
}
responseData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData as IDataObject[]),
{ itemData: { item: i } },
);
} else if (operation === 'delete') {
// ----------------------------------------
// message: delete
// ----------------------------------------
// https://developer.webex.com/docs/api/v1/messages/delete-a-message
const messageId = this.getNodeParameter('messageId', i);
const endpoint = `/messages/${messageId}`;
responseData = await webexApiRequest.call(this, 'DELETE', endpoint);
responseData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray({ success: true }),
{ itemData: { item: i } },
);
} else if (operation === 'get') {
// ----------------------------------------
// message: get
// ----------------------------------------
// https://developer.webex.com/docs/api/v1/messages/get-message-details
const messageId = this.getNodeParameter('messageId', i);
const endpoint = `/messages/${messageId}`;
responseData = await webexApiRequest.call(this, 'GET', endpoint);
responseData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData as IDataObject[]),
{ itemData: { item: i } },
);
} else if (operation === 'getAll') {
// ----------------------------------------
// message: getAll
// ----------------------------------------
// https://developer.webex.com/docs/api/v1/messages/list-messages
const qs: IDataObject = {
roomId: this.getNodeParameter('roomId', i),
};
const filters = this.getNodeParameter('filters', i);
const returnAll = this.getNodeParameter('returnAll', i);
if (Object.keys(filters).length) {
Object.assign(qs, filters);
}
if (returnAll) {
responseData = await webexApiRequestAllItems.call(
this,
'items',
'GET',
'/messages',
{},
qs,
);
} else {
qs.max = this.getNodeParameter('limit', i);
responseData = await webexApiRequest.call(this, 'GET', '/messages', {}, qs);
responseData = responseData.items;
}
responseData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData.items as IDataObject[]),
{ itemData: { item: i } },
);
} else if (operation === 'update') {
// ----------------------------------------
// message: update
// ----------------------------------------
// https://developer.webex.com/docs/api/v1/messages/edit-a-message
const messageId = this.getNodeParameter('messageId', i) as string;
const markdown = this.getNodeParameter('markdown', i) as boolean;
const endpoint = `/messages/${messageId}`;
responseData = await webexApiRequest.call(this, 'GET', endpoint);
const body = {
roomId: responseData.roomId,
} as IDataObject;
if (markdown) {
body.markdown = this.getNodeParameter('markdownText', i);
} else {
body.text = this.getNodeParameter('text', i);
}
responseData = await webexApiRequest.call(this, 'PUT', endpoint, body);
responseData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData as IDataObject[]),
{ itemData: { item: i } },
);
}
}
if (resource === 'meeting') {
if (operation === 'create') {
const title = this.getNodeParameter('title', i) as string;
const start = this.getNodeParameter('start', i) as string;
const end = this.getNodeParameter('end', i) as string;
const invitees = this.getNodeParameter(
'additionalFields.inviteesUi.inviteeValues',
i,
[],
) as IDataObject[];
const additionalFields = this.getNodeParameter('additionalFields', i);
const body: IDataObject = {
title,
start: moment.tz(start, timezone).format(),
end: moment.tz(end, timezone).format(),
...additionalFields,
};
if (body.requireRegistrationInfo) {
body.registration = (body.requireRegistrationInfo as string[]).reduce(
(obj, value) => Object.assign(obj, { [`${value}`]: true }),
{},
);
delete body.requireRegistrationInfo;
}
if (invitees) {
body.invitees = invitees;
delete body.inviteesUi;
}
responseData = await webexApiRequest.call(this, 'POST', '/meetings', body);
responseData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData as IDataObject[]),
{ itemData: { item: i } },
);
}
if (operation === 'delete') {
const meetingId = this.getNodeParameter('meetingId', i) as string;
const options = this.getNodeParameter('options', i);
const qs: IDataObject = {
...options,
};
responseData = await webexApiRequest.call(
this,
'DELETE',
`/meetings/${meetingId}`,
{},
qs,
);
responseData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray({ success: true }),
{ itemData: { item: i } },
);
}
if (operation === 'get') {
const meetingId = this.getNodeParameter('meetingId', i) as string;
const options = this.getNodeParameter('options', i);
let headers = {};
const qs: IDataObject = {
...options,
};
if (options.passsword) {
headers = {
passsword: options.passsword,
};
}
responseData = await webexApiRequest.call(
this,
'GET',
`/meetings/${meetingId}`,
{},
qs,
undefined,
{ headers },
);
responseData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData as IDataObject[]),
{ itemData: { item: i } },
);
}
if (operation === 'getAll') {
const filters = this.getNodeParameter('filters', i);
const returnAll = this.getNodeParameter('returnAll', i);
const qs: IDataObject = {
...filters,
};
if (qs.from) {
qs.from = moment(qs.from as string)
.utc(true)
.format();
}
if (qs.to) {
qs.to = moment(qs.to as string)
.utc(true)
.format();
}
if (returnAll) {
responseData = await webexApiRequestAllItems.call(
this,
'items',
'GET',
'/meetings',
{},
qs,
);
} else {
qs.max = this.getNodeParameter('limit', i);
responseData = await webexApiRequest.call(this, 'GET', '/meetings', {}, qs);
responseData = responseData.items;
}
responseData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData as IDataObject[]),
{ itemData: { item: i } },
);
}
if (operation === 'update') {
const meetingId = this.getNodeParameter('meetingId', i) as string;
const invitees = this.getNodeParameter(
'updateFields.inviteesUi.inviteeValues',
i,
[],
) as IDataObject[];
const updateFields = this.getNodeParameter('updateFields', i);
const { title, password, start, end } = await webexApiRequest.call(
this,
'GET',
`/meetings/${meetingId}`,
);
const body: IDataObject = {
...updateFields,
};
if (body.requireRegistrationInfo) {
body.registration = (body.requireRegistrationInfo as string[]).reduce(
(obj, value) => Object.assign(obj, { [`${value}`]: true }),
{},
);
delete body.requireRegistrationInfo;
}
if (invitees.length) {
body.invitees = invitees;
}
if (body.start) {
body.start = moment.tz(updateFields.start, timezone).format();
} else {
body.start = start;
}
if (body.end) {
body.end = moment.tz(updateFields.end, timezone).format();
} else {
body.end = end;
}
if (!body.title) {
body.title = title;
}
if (!body.password) {
body.password = password;
}
responseData = await webexApiRequest.call(this, 'PUT', `/meetings/${meetingId}`, body);
responseData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData as IDataObject[]),
{ itemData: { item: i } },
);
}
}
returnData.push(...(responseData as INodeExecutionData[]));
} catch (error) {
if (this.continueOnFail()) {
returnData.push({ error: error.toString(), json: {}, itemIndex: i });
continue;
}
throw error;
}
}
// if (resource === 'meetingTranscript') {
// if (operation === 'download') {
// for (let i = 0; i < items.length; i++) {
// const transcriptId = this.getNodeParameter('transcriptId', i) as string;
// const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
// const meetingId = this.getNodeParameter('meetingId', i) as string;
// const options = this.getNodeParameter('options', i);
// const qs: IDataObject = {
// meetingId,
// ...options,
// };
// const transcription = await webexApiRequest.call(this, 'GET', `/meetingTranscripts/${transcriptId}/download`, {}, qs);
// responseData = {
// json: {},
// binary: {
// [binaryPropertyName]: {
// data: Buffer.from(transcription, BINARY_ENCODING),
// //contentType:
// //FILE
// }
// }
// }
// }
// }
// if (operation === 'getAll') {
// for (let i = 0; i < items.length; i++) {
// try {
// const meetingId = this.getNodeParameter('meetingId', i) as string;
// const filters = this.getNodeParameter('filters', i);
// const returnAll = this.getNodeParameter('returnAll', i);
// const qs: IDataObject = {
// meetingId,
// ...filters,
// };
// if (returnAll === true) {
// responseData = await webexApiRequestAllItems.call(this, 'items', 'GET', '/meetingTranscripts', {}, qs);
// returnData.push(...responseData);
// } else {
// qs.max = this.getNodeParameter('limit', i);
// responseData = await webexApiRequest.call(this, 'GET', '/meetingTranscripts', {}, qs);
// returnData.push(...responseData.items);
// }
// } catch (error) {
// if (this.continueOnFail()) {
// returnData.push({
// error: error.message,
// });
// }
// }
// }
// }
// }
return [returnData];
}
}