add OAuth2

This commit is contained in:
shraddha shaligram 2020-06-18 12:29:16 -07:00
commit 37c80f3d8b
12 changed files with 854 additions and 706 deletions

View file

@ -1,6 +1,11 @@
import { ICredentialType, NodePropertyTypes } from 'n8n-workflow';
import {
ICredentialType,
NodePropertyTypes,
} from 'n8n-workflow';
const scopes = ['https://www.googleapis.com/auth/tasks'];
const scopes = [
'https://www.googleapis.com/auth/tasks',
];
export class GoogleTasksOAuth2Api implements ICredentialType {
name = 'googleTasksOAuth2Api';
@ -12,6 +17,6 @@ export class GoogleTasksOAuth2Api implements ICredentialType {
name: 'scope',
type: 'hidden' as NodePropertyTypes,
default: scopes.join(' ')
}
},
];
}

View file

@ -44,7 +44,7 @@ export class ZoomOAuth2Api implements ICredentialType {
displayName: 'Authentication',
name: 'authentication',
type: 'hidden' as NodePropertyTypes,
default: 'body'
default: 'header'
}
];
}

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,6 @@
import { IDataObject } from "n8n-workflow";
import {
IDataObject,
} from 'n8n-workflow';
export interface IReminder {
useDefault?: boolean;

View file

@ -1,4 +1,6 @@
import { IExecuteFunctions } from 'n8n-core';
import {
IExecuteFunctions,
} from 'n8n-core';
import {
IDataObject,
@ -6,14 +8,22 @@ import {
INodeTypeDescription,
INodeType,
ILoadOptionsFunctions,
INodePropertyOptions
INodePropertyOptions,
} from 'n8n-workflow';
import { googleApiRequest, googleApiRequestAllItems } from './GenericFunctions';
import {
googleApiRequest,
googleApiRequestAllItems,
} from './GenericFunctions';
import { eventOperations, eventFields } from './EventDescription';
import {
eventOperations,
eventFields,
} from './EventDescription';
import { IEvent } from './EventInterface';
import {
IEvent,
} from './EventInterface';
import * as moment from 'moment-timezone';
@ -28,14 +38,14 @@ export class GoogleCalendar implements INodeType {
description: 'Consume Google Calendar API.',
defaults: {
name: 'Google Calendar',
color: '#3E87E4'
color: '#3E87E4',
},
inputs: ['main'],
outputs: ['main'],
credentials: [
{
name: 'googleCalendarOAuth2Api',
required: true
required: true,
}
],
properties: [
@ -46,15 +56,15 @@ export class GoogleCalendar implements INodeType {
options: [
{
name: 'Event',
value: 'event'
}
value: 'event',
},
],
default: 'event',
description: 'The resource to operate on.'
},
...eventOperations,
...eventFields
]
...eventFields,
],
};
methods = {

View file

@ -1,12 +1,16 @@
import { OptionsWithUri } from 'request';
import {
OptionsWithUri,
} from 'request';
import {
IExecuteFunctions,
IExecuteSingleFunctions,
ILoadOptionsFunctions
ILoadOptionsFunctions,
} from 'n8n-core';
import { IDataObject } from 'n8n-workflow';
import {
IDataObject,
} from 'n8n-workflow';
export async function googleApiRequest(
this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions,
@ -27,6 +31,7 @@ export async function googleApiRequest(
uri: uri || `https://www.googleapis.com${resource}`,
json: true
};
try {
if (Object.keys(headers).length !== 0) {
options.headers = Object.assign({}, options.headers, headers);
@ -41,10 +46,14 @@ export async function googleApiRequest(
options
);
} catch (error) {
if (error.response && error.response.body && error.response.body.message) {
if (error.response && error.response.body && error.response.body.error) {
let errors = error.response.body.error.errors;
errors = errors.map((e: IDataObject) => e.message);
// Try to return the error prettier
throw new Error(
`Google Tasks error response [${error.statusCode}]: ${error.response.body.message}`
`Google Tasks error response [${error.statusCode}]: ${errors.join('|')}`
);
}
throw error;

View file

@ -1,16 +1,25 @@
import { IExecuteFunctions } from 'n8n-core';
import {
IExecuteFunctions,
} from 'n8n-core';
import {
IDataObject,
INodeExecutionData,
INodeTypeDescription,
INodeType,
ILoadOptionsFunctions,
INodePropertyOptions
INodeExecutionData,
INodePropertyOptions,
INodeType,
INodeTypeDescription,
} from 'n8n-workflow';
import { taskOperations, taskFields } from './TaskDescription';
import { googleApiRequest, googleApiRequestAllItems } from './GenericFunctions';
import {
googleApiRequest,
googleApiRequestAllItems,
} from './GenericFunctions';
import {
taskOperations,
taskFields,
} from './TaskDescription';
export class GoogleTasks implements INodeType {
description: INodeTypeDescription = {
@ -98,43 +107,36 @@ export class GoogleTasks implements INodeType {
i
) as IDataObject;
if (additionalFields.parent)
if (additionalFields.parent) {
qs.parent = additionalFields.parent as string;
if (additionalFields.previous)
qs.previous = additionalFields.previous as string;
if (additionalFields.links) {
body.links = (additionalFields.links as string[]).map(link => {
return { link };
});
}
if (additionalFields.status)
if (additionalFields.previous) {
qs.previous = additionalFields.previous as string;
}
if (additionalFields.status) {
body.status = additionalFields.status as string;
}
if (additionalFields.notes)
if (additionalFields.notes) {
body.notes = additionalFields.notes as string;
}
if (additionalFields.title)
if (additionalFields.title) {
body.title = additionalFields.title as string;
}
if (additionalFields.dueDate)
if (additionalFields.dueDate) {
body.dueDate = additionalFields.dueDate as string;
}
if (additionalFields.completed)
if (additionalFields.completed) {
body.completed = additionalFields.completed as string;
}
if (additionalFields.deleted)
if (additionalFields.deleted) {
body.deleted = additionalFields.deleted as boolean;
if (additionalFields.hidden)
body.hidden = additionalFields.hidden as boolean;
if (additionalFields.position)
body.position = additionalFields.position as string;
if (additionalFields.selfLink)
body.selfLink = additionalFields.selfLink as string;
}
responseData = await googleApiRequest.call(
this,
@ -189,9 +191,6 @@ export class GoogleTasks implements INodeType {
if (options.dueMax) {
qs.dueMax = options.dueMax as string;
}
if (options.pageToken) {
qs.pageToken = options.pageToken as string;
}
if (options.showCompleted) {
qs.showCompleted = options.showCompleted as boolean;
}
@ -201,10 +200,10 @@ export class GoogleTasks implements INodeType {
if (options.showHidden) {
qs.showHidden = options.showHidden as boolean;
}
if (options.updatedMin) {
qs.updatedMin = options.updatedMin as string;
}
if (returnAll) {
responseData = await googleApiRequestAllItems.call(
this,
@ -236,38 +235,33 @@ export class GoogleTasks implements INodeType {
i
) as IDataObject;
if (updateFields.parent) qs.parent = updateFields.parent as string;
if (updateFields.previous)
if (updateFields.previous) {
qs.previous = updateFields.previous as string;
if (updateFields.links) {
body.links = (updateFields.links as string[]).map(link => {
return { link: link };
});
}
if (updateFields.status) body.status = updateFields.status as string;
if (updateFields.notes) body.notes = updateFields.notes as string;
if (updateFields.status) {
body.status = updateFields.status as string;
}
if (updateFields.title) body.title = updateFields.title as string;
if (updateFields.notes) {
body.notes = updateFields.notes as string;
}
if (updateFields.dueDate)
if (updateFields.title) {
body.title = updateFields.title as string;
}
if (updateFields.dueDate) {
body.dueDate = updateFields.dueDate as string;
}
if (updateFields.completed)
if (updateFields.completed) {
body.completed = updateFields.completed as string;
}
if (updateFields.deleted)
if (updateFields.deleted) {
body.deleted = updateFields.deleted as boolean;
if (updateFields.hidden) body.hidden = updateFields.hidden as boolean;
if (updateFields.position)
body.position = updateFields.position as string;
if (updateFields.selfLink)
body.selfLink = updateFields.selfLink as string;
}
responseData = await googleApiRequest.call(
this,
@ -278,12 +272,11 @@ export class GoogleTasks implements INodeType {
);
}
}
}
if (Array.isArray(responseData)) {
returnData.push.apply(returnData, responseData as IDataObject[]);
} else if (responseData !== undefined) {
returnData.push(responseData as IDataObject);
if (Array.isArray(responseData)) {
returnData.push.apply(returnData, responseData as IDataObject[]);
} else if (responseData !== undefined) {
returnData.push(responseData as IDataObject);
}
}
return [this.helpers.returnJsonArray(returnData)];
}

View file

@ -1,4 +1,6 @@
import { INodeProperties } from 'n8n-workflow';
import {
INodeProperties,
} from 'n8n-workflow';
export const taskOperations = [
{
@ -7,60 +9,66 @@ export const taskOperations = [
type: 'options',
displayOptions: {
show: {
resource: ['task']
}
resource: [
'task',
],
},
},
options: [
{
name: 'Create',
value: 'create',
description: 'Add a task to tasklist'
description: 'Add a task to tasklist',
},
{
name: 'Delete',
value: 'delete',
description: 'Delete a task'
description: 'Delete a task',
},
{
name: 'Get',
value: 'get',
description: 'Retrieve a task'
description: 'Retrieve a task',
},
{
name: 'Get All',
value: 'getAll',
description: 'Retrieve all tasks from a tasklist'
description: 'Retrieve all tasks from a tasklist',
},
{
name: 'Update',
value: 'update',
description: 'Update a task'
description: 'Update a task',
}
],
default: 'create',
description: 'The operation to perform.'
description: 'The operation to perform.',
}
] as INodeProperties[];
export const taskFields = [
/* -------------------------------------------------------------------------- */
/* task:create */
/* task:create */
/* -------------------------------------------------------------------------- */
{
displayName: 'TaskList',
name: 'task',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getTasks'
loadOptionsMethod: 'getTasks',
},
required: true,
displayOptions: {
show: {
operation: ['create'],
resource: ['task']
}
operation: [
'create',
],
resource: [
'task',
],
},
},
default: ''
default: '',
},
{
displayName: 'Additional Fields',
@ -70,135 +78,105 @@ export const taskFields = [
default: {},
displayOptions: {
show: {
operation: ['create'],
resource: ['task']
operation: [
'create',
],
resource: [
'task',
],
}
},
options: [
{
displayName: 'Status',
name: 'status',
type: 'options',
options: [
{
name: 'needs Action',
value: 'needsAction'
},
{
name: 'completed',
value: 'completed'
}
],
displayName: 'Completion Date',
name: 'completed',
type: 'dateTime',
default: '',
description: 'Current status of the task.'
description: `Completion date of the task (as a RFC 3339 timestamp). This field is omitted if the task has not been completed.`,
},
{
displayName: 'Links',
name: 'links',
type: 'string',
typeOptions: {
multipleValues: true,
multipleValueButtonText: 'Add Link'
},
default: '',
description: 'The links to insert in the task.'
},
{
displayName: 'Notes',
name: 'notes',
type: 'string',
default: '',
description: 'Additional Notes.'
},
{
displayName: 'Title',
name: 'title',
type: 'string',
default: '',
description: 'Title of the task.'
displayName: 'Deleted',
name: 'deleted',
type: 'boolean',
default: false,
description: 'Flag indicating whether the task has been deleted.',
},
{
displayName: 'Due Date',
name: 'dueDate',
type: 'dateTime',
default: '',
description: 'Due date of the task.'
description: 'Due date of the task.',
},
{
displayName: 'Completion date',
name: 'completed',
type: 'dateTime',
displayName: 'Notes',
name: 'notes',
type: 'string',
default: '',
description: `Completion date of the task (as a RFC 3339 timestamp). This field is omitted if the task has not been completed.`
},
{
displayName: 'Deleted status',
name: 'deleted',
type: 'boolean',
default: false,
description: 'Flag indicating whether the task has been deleted.'
},
{
displayName: 'Hidden',
name: 'hidden',
type: 'boolean',
default: false,
description: 'Flag indicating whether the task is hidden.'
description: 'Additional Notes.',
},
{
displayName: 'Parent',
name: 'parent',
type: 'string',
default: '',
description:
'Parent task identifier.This field is omitted if it is a top-level task.'
},
{
displayName: 'Position',
name: 'position',
type: 'string',
default: '',
description:
'Parent task identifier.This field is omitted if it is a top-level task.'
},
{
displayName: 'Self Link',
name: 'selfLink',
type: 'string',
default: '',
description:
'URL pointing to this task. Used to retrieve, update, or delete this task.'
description: 'Parent task identifier. If the task is created at the top level, this parameter is omitted.',
},
{
displayName: 'Previous',
name: 'previous',
type: 'string',
default: '',
description:
'Previous sibling task identifier. If the task is created at the first position among its siblings, this parameter is omitted.'
}
]
description: 'Previous sibling task identifier. If the task is created at the first position among its siblings, this parameter is omitted.',
},
{
displayName: 'Status',
name: 'status',
type: 'options',
options: [
{
name: 'Needs Action',
value: 'needsAction',
},
{
name: 'Completed',
value: 'completed',
}
],
default: '',
description: 'Current status of the task.',
},
{
displayName: 'Title',
name: 'title',
type: 'string',
default: '',
description: 'Title of the task.',
},
],
},
/* -------------------------------------------------------------------------- */
/* task:delete */
/* task:delete */
/* -------------------------------------------------------------------------- */
{
displayName: 'TaskList',
name: 'task',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getTasks'
loadOptionsMethod: 'getTasks',
},
required: true,
displayOptions: {
show: {
operation: ['delete'],
resource: ['task']
}
operation: [
'delete',
],
resource: [
'task',
],
},
},
default: ''
default: '',
},
{
displayName: 'Task ID',
@ -207,30 +185,38 @@ export const taskFields = [
required: true,
displayOptions: {
show: {
operation: ['delete'],
resource: ['task']
}
operation: [
'delete',
],
resource: [
'task',
],
},
},
default: ''
default: '',
},
/* -------------------------------------------------------------------------- */
/* task:get */
/* task:get */
/* -------------------------------------------------------------------------- */
{
displayName: 'TaskList',
name: 'task',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getTasks'
loadOptionsMethod: 'getTasks',
},
required: true,
displayOptions: {
show: {
operation: ['get'],
resource: ['task']
operation: [
'get',
],
resource: [
'task',
],
}
},
default: ''
default: '',
},
{
displayName: 'Task ID',
@ -239,30 +225,38 @@ export const taskFields = [
required: true,
displayOptions: {
show: {
operation: ['get'],
resource: ['task']
}
operation: [
'get',
],
resource: [
'task',
],
},
},
default: ''
default: '',
},
/* -------------------------------------------------------------------------- */
/* task:getAll */
/* task:getAll */
/* -------------------------------------------------------------------------- */
{
displayName: 'TaskList',
name: 'task',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getTasks'
loadOptionsMethod: 'getTasks',
},
required: true,
displayOptions: {
show: {
operation: ['getAll'],
resource: ['task']
}
operation: [
'getAll',
],
resource: [
'task',
],
},
},
default: ''
default: '',
},
{
displayName: 'Return All',
@ -270,13 +264,16 @@ export const taskFields = [
type: 'boolean',
displayOptions: {
show: {
operation: ['getAll'],
resource: ['task']
}
operation: [
'getAll',
],
resource: [
'task',
],
},
},
default: false,
description:
'If all results should be returned or only up to a given limit.'
description: 'If all results should be returned or only up to a given limit.',
},
{
displayName: 'Limit',
@ -284,17 +281,23 @@ export const taskFields = [
type: 'number',
displayOptions: {
show: {
operation: ['getAll'],
resource: ['task'],
returnAll: [false]
}
operation: [
'getAll',
],
resource: [
'task',
],
returnAll: [
false,
],
},
},
typeOptions: {
minValue: 1,
maxValue: 100
},
default: 20,
description: 'How many results to return.'
description: 'How many results to return.',
},
{
displayName: 'Additional Fields',
@ -304,105 +307,95 @@ export const taskFields = [
default: {},
displayOptions: {
show: {
operation: ['getAll'],
resource: ['task']
}
operation: [
'getAll',
],
resource: [
'task',
],
},
},
options: [
{
displayName: 'Completed Max',
name: 'completedMax',
type: 'dateTime',
default: '',
description:
'Upper bound for a task completion date (as a RFC 3339 timestamp) to filter by.'
description: 'Upper bound for a task completion date (as a RFC 3339 timestamp) to filter by.',
},
{
displayName: 'Completed Min',
name: 'completedMin',
type: 'dateTime',
default: '',
description:
'Lower bound for a task completion date (as a RFC 3339 timestamp) to filter by.'
description: 'Lower bound for a task completion date (as a RFC 3339 timestamp) to filter by.',
},
{
displayName: 'Due Min',
name: 'dueMin',
type: 'dateTime',
default: '',
description:
'Lower bound for a task due date (as a RFC 3339 timestamp) to filter by.'
description: 'Lower bound for a task due date (as a RFC 3339 timestamp) to filter by.',
},
{
displayName: 'Due Max',
name: 'dueMax',
type: 'dateTime',
default: '',
description:
'Upper bound for a task due date (as a RFC 3339 timestamp) to filter by.'
description: 'Upper bound for a task due date (as a RFC 3339 timestamp) to filter by.',
},
{
displayName: 'Page Token',
name: 'pageToken',
type: 'string',
default: '',
description: 'Token specifying the result page to return.'
},
{
displayName: 'Show Completed',
name: 'showCompleted',
type: 'boolean',
default: true,
description:
'Flag indicating whether completed tasks are returned in the result'
description: 'Flag indicating whether completed tasks are returned in the result',
},
{
displayName: 'Show Deleted',
name: 'showDeleted',
type: 'boolean',
default: false,
description:
'Flag indicating whether deleted tasks are returned in the result'
description: 'Flag indicating whether deleted tasks are returned in the result',
},
{
displayName: 'Show Hidden',
name: 'showHidden',
type: 'boolean',
default: false,
description:
'Flag indicating whether hidden tasks are returned in the result'
description: 'Flag indicating whether hidden tasks are returned in the result',
},
{
displayName: 'Updated Min',
name: 'updatedMin',
type: 'string',
description:
'Lower bound for a task last modification time (as a RFC 3339 timestamp) to filter by.'
}
type: 'dateTime',
default: '',
description: 'Lower bound for a task last modification time (as a RFC 3339 timestamp) to filter by.',
},
]
},
/* -------------------------------------------------------------------------- */
/* task:update */
/* task:update */
/* -------------------------------------------------------------------------- */
{
displayName: 'TaskList',
name: 'task',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getTasks'
loadOptionsMethod: 'getTasks',
},
required: true,
displayOptions: {
show: {
operation: ['update'],
resource: ['task']
}
operation: [
'update',
],
resource: [
'task',
],
},
},
default: ''
default: '',
},
{
displayName: 'Task ID',
@ -411,11 +404,15 @@ export const taskFields = [
required: true,
displayOptions: {
show: {
operation: ['update'],
resource: ['task']
}
operation: [
'update',
],
resource: [
'task',
],
},
},
default: ''
default: '',
},
{
displayName: 'Update Fields',
@ -425,115 +422,71 @@ export const taskFields = [
default: {},
displayOptions: {
show: {
operation: ['update'],
resource: ['task']
operation: [
'update',
],
resource: [
'task',
],
}
},
options: [
{
displayName: 'Status',
name: 'status',
type: 'options',
options: [
{
name: 'needs Action',
value: 'needsAction'
},
{
name: 'completed',
value: 'completed'
}
],
displayName: 'Completion Date',
name: 'completed',
type: 'dateTime',
default: '',
description: 'Current status of the task.'
},
{
displayName: 'Links',
name: 'links',
type: 'string',
typeOptions: {
multipleValues: true,
multipleValueButtonText: 'Add Link'
},
default: '',
description: 'The links to insert in the task.'
description: `Completion date of the task (as a RFC 3339 timestamp). This field is omitted if the task has not been completed.`,
},
{
displayName: 'Deleted',
name: 'deleted',
type: 'boolean',
default: false,
description: 'Flag indicating whether the task has been deleted.',
},
{
displayName: 'Notes',
name: 'notes',
type: 'string',
typeOptions: {
alwaysOpenEditWindow: true,
},
default: '',
description: 'Additional Notes.'
},
{
displayName: 'Title',
name: 'title',
type: 'string',
default: '',
description: 'Title of the task.'
},
{
displayName: 'Due Date',
name: 'dueDate',
type: 'dateTime',
default: '',
description: 'Due date of the task.'
},
{
displayName: 'Completion date',
name: 'completed',
type: 'dateTime',
default: '',
description: `Completion date of the task (as a RFC 3339 timestamp). This field is omitted if the task has not been completed.`
},
{
displayName: 'Deleted status',
name: 'deleted',
type: 'boolean',
default: false,
description: 'Flag indicating whether the task has been deleted.'
},
{
displayName: 'Hidden',
name: 'hidden',
type: 'boolean',
default: false,
description: 'Flag indicating whether the task is hidden.'
},
{
displayName: 'Parent',
name: 'parent',
type: 'string',
default: '',
description:
'Parent task identifier.This field is omitted if it is a top-level task.'
},
{
displayName: 'Position',
name: 'position',
type: 'string',
default: '',
description:
'Parent task identifier.This field is omitted if it is a top-level task.'
},
{
displayName: 'Self Link',
name: 'selfLink',
type: 'string',
default: '',
description:
'URL pointing to this task. Used to retrieve, update, or delete this task.'
description: 'Additional Notes.',
},
{
displayName: 'Previous',
name: 'previous',
type: 'string',
default: '',
description:
'Previous sibling task identifier. If the task is created at the first position among its siblings, this parameter is omitted.'
}
]
}
description: 'Previous sibling task identifier. If the task is created at the first position among its siblings, this parameter is omitted.',
},
{
displayName: 'Status',
name: 'status',
type: 'options',
options: [
{
name: 'Needs Update',
value: 'needsAction',
},
{
name: 'Completed',
value: 'completed',
}
],
default: '',
description: 'Current status of the task.',
},
{
displayName: 'Title',
name: 'title',
type: 'string',
default: '',
description: 'Title of the task.',
},
],
},
] as INodeProperties[];

View file

@ -1,13 +1,17 @@
import { IExecuteFunctions } from 'n8n-core';
import {
IExecuteFunctions,
} from 'n8n-core';
import {
IDataObject,
INodeTypeDescription,
INodeExecutionData,
INodeType
INodeType,
} from 'n8n-workflow';
import { messageBirdApiRequest } from './GenericFunctions';
import {
messageBirdApiRequest,
} from './GenericFunctions';
export class MessageBird implements INodeType {
description: INodeTypeDescription = {
@ -20,15 +24,15 @@ export class MessageBird implements INodeType {
description: 'Sending SMS',
defaults: {
name: 'MessageBird',
color: '#2481d7'
color: '#2481d7',
},
inputs: ['main'],
outputs: ['main'],
credentials: [
{
name: 'messageBirdApi',
required: true
}
required: true,
},
],
properties: [
{
@ -38,31 +42,32 @@ export class MessageBird implements INodeType {
options: [
{
name: 'SMS',
value: 'sms'
}
value: 'sms',
},
],
default: 'sms',
description: 'The resource to operate on.'
description: 'The resource to operate on.',
},
{
displayName: 'Operation',
name: 'operation',
type: 'options',
displayOptions: {
show: {
resource: ['sms']
}
resource: [
'sms',
],
},
},
options: [
{
name: 'Send',
value: 'send',
description: 'Send text messages (SMS)'
}
description: 'Send text messages (SMS)',
},
],
default: 'send',
description: 'The operation to perform.'
description: 'The operation to perform.',
},
// ----------------------------------
@ -77,11 +82,15 @@ export class MessageBird implements INodeType {
required: true,
displayOptions: {
show: {
operation: ['send'],
resource: ['sms']
}
operation: [
'send',
],
resource: [
'sms',
],
},
},
description: 'The number from which to send the message.'
description: 'The number from which to send the message.',
},
{
displayName: 'To',
@ -92,13 +101,16 @@ export class MessageBird implements INodeType {
required: true,
displayOptions: {
show: {
operation: ['send'],
resource: ['sms']
}
operation: [
'send',
],
resource: [
'sms',
],
},
},
description: 'All recipients separated by commas.'
description: 'All recipients separated by commas.',
},
{
displayName: 'Message',
name: 'message',
@ -107,11 +119,15 @@ export class MessageBird implements INodeType {
required: true,
displayOptions: {
show: {
operation: ['send'],
resource: ['sms']
}
operation: [
'send',
],
resource: [
'sms',
],
},
},
description: 'The message to be send.'
description: 'The message to be send.',
},
{
displayName: 'Additional Fields',
@ -125,8 +141,7 @@ export class MessageBird implements INodeType {
name: 'createdDatetime',
type: 'dateTime',
default: '',
description:
'The date and time of the creation of the message in RFC3339 format (Y-m-dTH:i:sP).'
description: 'The date and time of the creation of the message in RFC3339 format (Y-m-dTH:i:sP).',
},
{
displayName: 'Datacoding',
@ -135,27 +150,26 @@ export class MessageBird implements INodeType {
options: [
{
name: 'Auto',
value: 'auto'
value: 'auto',
},
{
name: 'Plain',
value: 'plain'
value: 'plain',
},
{
name: 'Unicode',
value: 'unicode'
}
value: 'unicode',
},
],
default: '',
description:
'Using unicode will limit the maximum number of characters to 70 instead of 160.'
description: 'Using unicode will limit the maximum number of characters to 70 instead of 160.',
},
{
displayName: 'Gateway',
name: 'gateway',
type: 'number',
default: '',
description: 'The SMS route that is used to send the message.'
description: 'The SMS route that is used to send the message.',
},
{
displayName: 'Group IDs',
@ -163,8 +177,7 @@ export class MessageBird implements INodeType {
placeholder: '1,2',
type: 'string',
default: '',
description:
'Group IDs separated by commas, If provided recipients can be omitted.'
description: 'Group IDs separated by commas, If provided recipients can be omitted.',
},
{
displayName: 'Message Type',
@ -174,39 +187,36 @@ export class MessageBird implements INodeType {
options: [
{
name: 'Flash',
value: 1
value: 1,
},
{
name: 'Normal',
value: 0
}
value: 0,
},
],
default: 1,
description:
'Indicated the message type. 1 is a normal message, 0 is a flash message.'
description: 'Indicated the message type. 1 is a normal message, 0 is a flash message.',
},
{
displayName: 'Reference',
name: 'reference',
type: 'string',
default: '',
description: 'A client reference.'
description: 'A client reference.',
},
{
displayName: 'Report Url',
name: 'reportUrl',
type: 'string',
default: '',
description:
'The status report URL to be used on a per-message basis.<br /> Reference is required for a status report webhook to be sent.'
description: 'The status report URL to be used on a per-message basis.<br /> Reference is required for a status report webhook to be sent.',
},
{
displayName: 'Scheduled Date-time',
name: 'scheduledDatetime',
type: 'dateTime',
default: '',
description:
'The scheduled date and time of the message in RFC3339 format (Y-m-dTH:i:sP).'
description: 'The scheduled date and time of the message in RFC3339 format (Y-m-dTH:i:sP).',
},
{
displayName: 'Type',
@ -215,28 +225,26 @@ export class MessageBird implements INodeType {
options: [
{
name: 'Binary',
value: 'binary'
value: 'binary',
},
{
name: 'Flash',
value: 'flash'
value: 'flash',
},
{
name: 'SMS',
value: 'sms'
}
value: 'sms',
},
],
default: '',
description:
'The type of message.<br /> Values can be: sms, binary, or flash.'
description: 'The type of message.<br /> Values can be: sms, binary, or flash.',
},
{
displayName: 'Type Details',
name: 'typeDetails',
type: 'string',
default: '',
description:
'A hash with extra information.<br /> Is only used when a binary message is sent.'
description: 'A hash with extra information.<br /> Is only used when a binary message is sent.',
},
{
displayName: 'Validity',
@ -244,13 +252,13 @@ export class MessageBird implements INodeType {
type: 'number',
default: 1,
typeOptions: {
minValue: 1
minValue: 1,
},
description: 'The amount of seconds that the message is valid.'
}
]
}
]
description: 'The amount of seconds that the message is valid.',
},
],
},
],
};
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {

View file

@ -9,21 +9,11 @@ import {
import { IDataObject } from 'n8n-workflow';
import * as _ from 'lodash';
export async function zoomApiRequest(
this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions,
method: string,
resource: string,
body: object = {},
query: object = {},
headers: {} | undefined = undefined,
option: {} = {}
): Promise<any> {
export async function zoomApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: object = {}, query: object = {}, headers: {} | undefined = undefined, option: {} = {}): Promise<any> { // tslint:disable-line:no-any
// tslint:disable-line:no-any
const authenticationMethod = this.getNodeParameter(
'authentication',
0,
'accessToken'
) as string;
const authenticationMethod = this.getNodeParameter('authentication', 0, 'accessToken') as string;
let options: OptionsWithUri = {
method,
headers: headers || {
@ -31,7 +21,7 @@ export async function zoomApiRequest(
},
body,
qs: query,
uri: `https://zoom.us/oauth${resource}`,
uri: `https://api.zoom.us/v2${resource}`,
json: true
};
options = Object.assign({}, options, option);
@ -41,6 +31,8 @@ export async function zoomApiRequest(
if (Object.keys(query).length === 0) {
delete options.qs;
}
console.log("options");
console.log(options);
try {
if (authenticationMethod === 'accessToken') {
const credentials = this.getCredentials('zoomApi');
@ -48,15 +40,24 @@ export async function zoomApiRequest(
throw new Error('No credentials got returned!');
}
options.headers!.Authorization = `Bearer ${credentials.accessToken}`;
console.log("options if");
console.log(options);
//@ts-ignore
return await this.helpers.request(options);
} else {
console.log("options else");
console.log(options);
let credentials = this.getCredentials('zoomOAuth2Api');
// let oauthtoken1 = credentials!.oauthTokenData;
console.log(credentials);
console.log("credss");
//@ts-ignore
return await this.helpers.requestOAuth2.call(
this,
'zoomOAuth2Api',
options
);
return await this.helpers.requestOAuth2.call(this, 'zoomOAuth2Api', options);
}
} catch (error) {
if (error.statusCode === 401) {
@ -66,16 +67,17 @@ export async function zoomApiRequest(
if (error.response && error.response.body && error.response.body.message) {
// Try to return the error prettier
throw new Error(
`Zoom error response [${error.statusCode}]: ${error.response.body.message}`
);
throw new Error(`Zoom error response [${error.statusCode}]: ${error.response.body.message}`);
}
// If that data does not exist for some reason return the actual error
throw error;
}
}
export async function zoomApiRequestAllItems(
this: IExecuteFunctions | ILoadOptionsFunctions,
propertyName: string,

View file

@ -3,13 +3,18 @@ import {
IDataObject,
INodeExecutionData,
INodeType,
INodeTypeDescription
INodeTypeDescription,
} from 'n8n-workflow';
import {
zoomApiRequest,
zoomApiRequestAllItems,
validateJSON
validateJSON,
} from './GenericFunctions';
import {
meetingOperations,
meetingFields,
} from './ZoomOperations';
export class Zoom implements INodeType {
description: INodeTypeDescription = {
displayName: 'Zoom',
@ -25,25 +30,49 @@ export class Zoom implements INodeType {
icon: 'file:zoom.png',
inputs: ['main'],
outputs: ['main'],
// credentials: [
// {
// name: 'zoomApi',
// required: true,
// displayOptions: {
// show: {
// authentication: ['accessToken']
// }
// }
// },
// {
// name: 'zoomOAuth2Api',
// required: true,
// displayOptions: {
// show: {
// authentication: ['oAuth2']
// }
// }
// }
// ],
credentials: [
{
name: 'zoomApi',
required: true,
displayOptions: {
show: {
authentication: ['accessToken']
}
}
authentication: [
'accessToken',
],
},
},
},
{
name: 'zoomOAuth2Api',
required: true,
displayOptions: {
show: {
authentication: ['oAuth2']
}
}
}
authentication: [
'oAuth2',
],
},
},
},
],
properties: [
{
@ -53,15 +82,15 @@ export class Zoom implements INodeType {
options: [
{
name: 'Access Token',
value: 'accessToken'
value: 'accessToken',
},
{
name: 'OAuth2',
value: 'oAuth2'
}
value: 'oAuth2',
},
],
default: 'accessToken',
description: 'The resource to operate on.'
description: 'The resource to operate on.',
},
{
displayName: 'Resource',
@ -69,14 +98,17 @@ export class Zoom implements INodeType {
type: 'options',
options: [
{
name: 'meeting',
name: 'Meeting',
value: 'meeting'
}
],
default: 'meeting',
description: 'The resource to operate on.'
}
},
...meetingOperations,
...meetingFields
]
};
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
@ -85,29 +117,26 @@ export class Zoom implements INodeType {
const length = (items.length as unknown) as number;
let qs: IDataObject;
let responseData;
const authentication = this.getNodeParameter('authentication', 0) as string;
const resource = this.getNodeParameter('resource', 0) as string;
// const operation = this.getNodeParameter('operation', 0) as string;
const operation = this.getNodeParameter('operation', 0) as string;
console.log(this.getCredentials('zoomOAuth2Api'));
// for (let i = 0; i < length; i++) {
// qs = {};
// if (resource === 'channel') {
// //https://api.slack.com/methods/conversations.archive
// if (operation === 'archive') {
// const channel = this.getNodeParameter('channelId', i) as string;
// const body: IDataObject = {
// channel
// };
// responseData = await zoomApiRequest.call(
// this,
// 'POST',
// '/conversations.archive',
// body,
// qs
// );
// }
// }
// }
for (let i = 0; i < length; i++) {
qs = {};
if (resource === 'meeting') {
if (operation === 'get') {
const userId = this.getNodeParameter('userId', i) as string;
responseData = await zoomApiRequest.call(
this,
'GET',
`/meetings/${userId}`,
{},
qs
);
}
}
}
if (Array.isArray(responseData)) {
returnData.push.apply(returnData, responseData as IDataObject[]);
} else {

View file

@ -0,0 +1,71 @@
import {
INodeProperties,
} from 'n8n-workflow';
export const meetingOperations = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
displayOptions: {
show: {
resource: [
'meeting',
],
},
},
options: [
{
name: 'Create',
value: 'create',
description: 'Create a meeting',
},
{
name: 'Delete',
value: 'delete',
description: 'Delete a meeting',
},
{
name: 'Get',
value: 'get',
description: 'Retrieve a meeting',
},
{
name: 'Get All',
value: 'getAll',
description: 'Retrieve all meetings',
},
{
name: 'Update',
value: 'update',
description: 'Update a meeting',
}
],
default: 'create',
description: 'The operation to perform.',
}
] as INodeProperties[];
export const meetingFields = [
/* -------------------------------------------------------------------------- */
/* meeting:get */
/* -------------------------------------------------------------------------- */
{
displayName: 'User Id',
name: 'userId',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
operation: [
'get',
],
resource: [
'meeting',
],
},
},
description: 'User ID.',
},
] as INodeProperties[];