diff --git a/packages/nodes-base/nodes/Google/Chat/GenericFunctions.ts b/packages/nodes-base/nodes/Google/Chat/GenericFunctions.ts index 0e971e4b53877..8632649c9d6b7 100644 --- a/packages/nodes-base/nodes/Google/Chat/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Google/Chat/GenericFunctions.ts @@ -56,7 +56,6 @@ export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleF const { access_token } = await getAccessToken.call(this, credentials as ICredentialDataDecryptedObject); options.headers!.Authorization = `Bearer ${access_token}`; - //@ts-ignore responseData = await this.helpers.request(options); } @@ -64,6 +63,7 @@ export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleF if (error.code === 'ERR_OSSL_PEM_NO_START_LINE') { error.statusCode = '401'; } + throw new NodeApiError(this.getNode(), error); } if(Object.keys(responseData as IDataObject).length !== 0) { @@ -166,12 +166,15 @@ export function getPagingParameters(resource: string, operation = 'getAll') { }, }, 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', name: 'limit', type: 'number', + typeOptions: { + maxValue: 1000, + }, displayOptions: { show: { resource: [ @@ -186,7 +189,7 @@ export function getPagingParameters(resource: string, operation = 'getAll') { }, }, default: 100, - description: 'The limit of records to return. The value is capped at 1000. Server may return fewer results than requested. If unspecified, server will default to 100.', + description: 'How many results to return', }, ]; return pagingParameters; diff --git a/packages/nodes-base/nodes/Google/Chat/GoogleChat.node.ts b/packages/nodes-base/nodes/Google/Chat/GoogleChat.node.ts index 3c2f87f2a48e4..3829f33555a07 100644 --- a/packages/nodes-base/nodes/Google/Chat/GoogleChat.node.ts +++ b/packages/nodes-base/nodes/Google/Chat/GoogleChat.node.ts @@ -20,6 +20,10 @@ import { IMessageUi, } from './MessageInterface'; +import { + OptionsWithUri +} from 'request'; + import { attachmentFields, attachmentOperations, @@ -44,9 +48,6 @@ import { import * as moment from 'moment-timezone'; import * as jwt from 'jsonwebtoken'; - -import { OptionsWithUri } from 'request'; - export class GoogleChat implements INodeType { description: INodeTypeDescription = { displayName: 'Google Chat', @@ -65,7 +66,7 @@ export class GoogleChat implements INodeType { credentials: [ { name: 'googleApi', - required: false, // not required, webhooks do not need credentials + required: true, testedBy: 'testGoogleTokenAuth', }, ], @@ -77,18 +78,18 @@ export class GoogleChat implements INodeType { noDataExpression: true, type: 'options', options: [ - { - name: 'Attachment', - value: 'attachment', - }, - { - name: 'Incoming Webhook', - value: 'incomingWebhook', - }, - { - name: 'Media', - value: 'media', - }, + // { + // name: 'Attachment', + // value: 'attachment', + // }, + // { + // name: 'Incoming Webhook', + // value: 'incomingWebhook', + // }, + // { + // name: 'Media', + // value: 'media', + // }, { name: 'Member', value: 'member', @@ -105,12 +106,12 @@ export class GoogleChat implements INodeType { default: 'message', description: 'The resource to operate on', }, - ...attachmentOperations, - ...attachmentFields, - ...incomingWebhookOperations, - ...incomingWebhookFields, - ...mediaOperations, - ...mediaFields, + // ...attachmentOperations, + // ...attachmentFields, + // ...incomingWebhookOperations, + // ...incomingWebhookFields, + // ...mediaOperations, + // ...mediaFields, ...memberOperations, ...memberFields, ...messageOperations, @@ -135,11 +136,9 @@ export class GoogleChat implements INodeType { `/v1/spaces`, ); for (const space of spaces) { - const spaceName = space.name; - const spaceId = space.name; returnData.push({ - name: spaceName, - value: spaceId, + name: space.displayName, + value: space.name, }); } return returnData; @@ -276,12 +275,12 @@ export class GoogleChat implements INodeType { // https://developers.google.com/chat/reference/rest/v1/spaces/get - const spaceName = this.getNodeParameter('spaceName', i) as string; + const spaceId = this.getNodeParameter('spaceId', i) as string; responseData = await googleApiRequest.call( this, 'GET', - `/v1/${spaceName}`, + `/v1/${spaceId}`, ); } else if (operation === 'getAll') { @@ -302,7 +301,7 @@ export class GoogleChat implements INodeType { ); } else { const limit = this.getNodeParameter('limit', i) as number; - qs.pageSize = limit >>> 0; // convert to an unsigned 32-bit integer + qs.pageSize = limit; responseData = await googleApiRequest.call( this, @@ -323,12 +322,12 @@ export class GoogleChat implements INodeType { // https://developers.google.com/chat/reference/rest/v1/spaces.members/get - const memberName = this.getNodeParameter('memberName', i) as string; + const memberId = this.getNodeParameter('memberId', i) as string; responseData = await googleApiRequest.call( this, 'GET', - `/v1/${memberName}`, + `/v1/${memberId}`, ); } else if (operation === 'getAll') { @@ -339,7 +338,7 @@ export class GoogleChat implements INodeType { // https://developers.google.com/chat/reference/rest/v1/spaces.members/list - const spaceName = this.getNodeParameter('spaceName', i) as string; + const spaceId = this.getNodeParameter('spaceId', i) as string; const returnAll = this.getNodeParameter('returnAll', 0) as IDataObject; if (returnAll) { @@ -347,19 +346,19 @@ export class GoogleChat implements INodeType { this, 'memberships', 'GET', - `/v1/${spaceName}/members`, + `/v1/${spaceId}/members`, undefined, qs, ); } else { const limit = this.getNodeParameter('limit', i) as number; - qs.pageSize = limit >>> 0; // convert to an unsigned 32-bit integer + qs.pageSize = limit; responseData = await googleApiRequest.call( this, 'GET', - `/v1/${spaceName}/members`, + `/v1/${spaceId}/members`, undefined, qs, ); @@ -376,7 +375,7 @@ export class GoogleChat implements INodeType { // https://developers.google.com/chat/reference/rest/v1/spaces.messages/create - const spaceName = this.getNodeParameter('spaceName', i) as string; + const spaceId = this.getNodeParameter('spaceId', i) as string; // get additional fields for threadKey and requestId const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; @@ -424,7 +423,7 @@ export class GoogleChat implements INodeType { responseData = await googleApiRequest.call( this, 'POST', - `/v1/${spaceName}/messages`, + `/v1/${spaceId}/messages`, body, qs, ); @@ -437,12 +436,12 @@ export class GoogleChat implements INodeType { // https://developers.google.com/chat/reference/rest/v1/spaces.messages/delete - const messageName = this.getNodeParameter('messageName', i) as string; + const messageId = this.getNodeParameter('messageId', i) as string; responseData = await googleApiRequest.call( this, 'DELETE', - `/v1/${messageName}`, + `/v1/${messageId}`, ); } else if (operation === 'get') { @@ -453,12 +452,12 @@ export class GoogleChat implements INodeType { // https://developers.google.com/chat/reference/rest/v1/spaces.messages/get - const messageName = this.getNodeParameter('messageName', i) as string; + const messageId = this.getNodeParameter('messageId', i) as string; responseData = await googleApiRequest.call( this, 'GET', - `/v1/${messageName}`, + `/v1/${messageId}`, ); } else if (operation === 'update') { @@ -469,7 +468,7 @@ export class GoogleChat implements INodeType { // https://developers.google.com/chat/reference/rest/v1/spaces.messages/update - const messageName = this.getNodeParameter('messageName', i) as string; + const messageId = this.getNodeParameter('messageId', i) as string; let message: IMessage = {}; const jsonParameters = this.getNodeParameter('jsonParameters', i) as boolean; @@ -516,7 +515,7 @@ export class GoogleChat implements INodeType { responseData = await googleApiRequest.call( this, 'PUT', - `/v1/${messageName}`, + `/v1/${messageId}`, body, qs, ); @@ -602,7 +601,7 @@ export class GoogleChat implements INodeType { } else if (responseData !== undefined) { returnData.push(responseData as IDataObject); } - } catch (error) { + } catch (error) { if (this.continueOnFail()) { // Return the actual reason as error if (operation === 'download') { diff --git a/packages/nodes-base/nodes/Google/Chat/descriptions/MemberDescription.ts b/packages/nodes-base/nodes/Google/Chat/descriptions/MemberDescription.ts index 301868a51822b..6ad61281bc021 100644 --- a/packages/nodes-base/nodes/Google/Chat/descriptions/MemberDescription.ts +++ b/packages/nodes-base/nodes/Google/Chat/descriptions/MemberDescription.ts @@ -23,12 +23,12 @@ export const memberOperations: INodeProperties[] = [ { name: 'Get', value: 'get', - description: 'Returns a membership', + description: 'Get a membership', }, { name: 'Get All', value: 'getAll', - description: 'Lists human memberships in a space', + description: 'Get all memberships in a space', }, ], default: 'get', @@ -38,11 +38,11 @@ export const memberOperations: INodeProperties[] = [ export const memberFields: INodeProperties[] = [ /* -------------------------------------------------------------------------- */ - /* member:get */ + /* member:get */ /* -------------------------------------------------------------------------- */ { - displayName: 'Member Name', - name: 'memberName', + displayName: 'Member ID', + name: 'memberId', type: 'string', required: true, displayOptions: { @@ -63,8 +63,8 @@ export const memberFields: INodeProperties[] = [ /* member:getAll */ /* -------------------------------------------------------------------------- */ { - displayName: 'Space Name', - name: 'spaceName', + displayName: 'Space Name/ID', + name: 'spaceId', type: 'options', required: true, typeOptions: { diff --git a/packages/nodes-base/nodes/Google/Chat/descriptions/MessageDescription.ts b/packages/nodes-base/nodes/Google/Chat/descriptions/MessageDescription.ts index bbe7bb51f9245..bda65a18568d2 100644 --- a/packages/nodes-base/nodes/Google/Chat/descriptions/MessageDescription.ts +++ b/packages/nodes-base/nodes/Google/Chat/descriptions/MessageDescription.ts @@ -19,22 +19,22 @@ export const messageOperations: INodeProperties[] = [ { name: 'Create', value: 'create', - description: 'Creates a message', + description: 'Create a message', }, { name: 'Delete', value: 'delete', - description: 'Deletes a message', + description: 'Delete a message', }, { name: 'Get', value: 'get', - description: 'Returns a message', + description: 'Get a message', }, { name: 'Update', value: 'update', - description: 'Updates a message', + description: 'Update a message', }, ], default: 'create', @@ -47,8 +47,8 @@ export const messageFields: INodeProperties[] = [ /* message:create */ /* -------------------------------------------------------------------------- */ { - displayName: 'Space Name', - name: 'spaceName', + displayName: 'Space Name/ID', + name: 'spaceId', type: 'options', required: true, typeOptions: { @@ -89,7 +89,7 @@ export const messageFields: INodeProperties[] = [ name: 'messageUi', type: 'collection', required: true, - placeholder: 'Add Options', + placeholder: 'Add Message', displayOptions: { show: { resource: [ @@ -103,15 +103,13 @@ export const messageFields: INodeProperties[] = [ ], }, }, - default: {'text': ''}, - description: 'The message object', + default: {}, options: [ { displayName: 'Text', name: 'text', type: 'string', default: '', - description: 'The message text', }, // { // TODO: get cards from the UI (check the Slack node, specifically the blocks parameter under message: post) // displayName: 'Cards', @@ -222,13 +220,13 @@ export const messageFields: INodeProperties[] = [ }, }, options: [ - { - displayName: 'Thread Key', - name: 'threadKey', - type: 'string', - default: '', - description: 'Thread identifier which groups messages into a single thread. Has no effect if thread field, corresponding to an existing thread, is set in message. Example: spaces/AAAAMpdlehY/threads/MZ8fXhZXGkk.', - }, + // { + // displayName: 'Thread Key', + // name: 'threadKey', + // type: 'string', + // default: '', + // description: 'Thread identifier which groups messages into a single thread. Has no effect if thread field, corresponding to an existing thread, is set in message. Example: spaces/AAAAMpdlehY/threads/MZ8fXhZXGkk.', + // }, { displayName: 'Request ID', name: 'requestId', @@ -240,11 +238,11 @@ export const messageFields: INodeProperties[] = [ }, /* -------------------------------------------------------------------------- */ - /* messages:delete */ + /* messages:delete */ /* -------------------------------------------------------------------------- */ { - displayName: 'Message Name', - name: 'messageName', + displayName: 'Message ID', + name: 'messageId', type: 'string', required: true, displayOptions: { @@ -258,15 +256,15 @@ export const messageFields: INodeProperties[] = [ }, }, default: '', - description: 'Resource name of the message to be deleted, in the form "spaces/*/messages/*"', + description: 'Resource name of the message to be deleted, in the form "spaces//messages/"', }, /* -------------------------------------------------------------------------- */ - /* message:get */ + /* message:get */ /* -------------------------------------------------------------------------- */ { - displayName: 'Message Name', - name: 'messageName', + displayName: 'Message ID', + name: 'messageId', type: 'string', required: true, displayOptions: { @@ -280,15 +278,15 @@ export const messageFields: INodeProperties[] = [ }, }, default: '', - description: 'Resource name of the message to be deleted, in the form "spaces/*/messages/*"', + description: 'Resource name of the message to be retrieved, in the form "spaces//messages/"', }, /* -------------------------------------------------------------------------- */ - /* message:update */ + /* message:update */ /* -------------------------------------------------------------------------- */ { - displayName: 'Message Name', - name: 'messageName', + displayName: 'Message ID', + name: 'messageId', type: 'string', required: true, displayOptions: { @@ -302,7 +300,7 @@ export const messageFields: INodeProperties[] = [ }, }, default: '', - description: 'Resource name of the message to be retrieved, in the form "spaces/*/messages/*"', + description: 'Resource name of the message to be updated, in the form "spaces//messages/"', }, { displayName: 'JSON Parameters', diff --git a/packages/nodes-base/nodes/Google/Chat/descriptions/SpaceDescription.ts b/packages/nodes-base/nodes/Google/Chat/descriptions/SpaceDescription.ts index 0f05d2e256010..9c2257d54b85b 100644 --- a/packages/nodes-base/nodes/Google/Chat/descriptions/SpaceDescription.ts +++ b/packages/nodes-base/nodes/Google/Chat/descriptions/SpaceDescription.ts @@ -23,30 +23,27 @@ export const spaceOperations: INodeProperties[] = [ { name: 'Get', value: 'get', - description: 'Returns a space', + description: 'Get a space', }, { name: 'Get All', value: 'getAll', - description: 'Lists spaces the caller is a member of', + description: 'Get all spaces the caller is a member of', }, ], default: 'get', }, ]; -export const spaceFields: INodeProperties[] = [ +export const spaceFields: INodeProperties[] = [ /* -------------------------------------------------------------------------- */ - /* space:get */ + /* space:get */ /* -------------------------------------------------------------------------- */ { - displayName: 'Space Name', - name: 'spaceName', - type: 'options', + displayName: 'Space ID', + name: 'spaceId', + type: 'string', required: true, - typeOptions: { - loadOptionsMethod: 'getSpaces', - }, displayOptions: { show: { resource: [