feat(Google Chat Node): Updates (#12827)

Co-authored-by: Dana <152518854+dana-gill@users.noreply.github.com>
This commit is contained in:
Michael Kret
2025-01-28 13:26:34 +02:00
committed by GitHub
parent de49c23971
commit e146ad021a
9 changed files with 356 additions and 31 deletions

View File

@@ -13,7 +13,7 @@ import type {
INodeTypeDescription,
IRequestOptions,
} from 'n8n-workflow';
import { NodeConnectionType, NodeOperationError } from 'n8n-workflow';
import { NodeConnectionType, NodeOperationError, SEND_AND_WAIT_OPERATION } from 'n8n-workflow';
import {
// attachmentFields,
@@ -27,10 +27,22 @@ import {
messageFields,
messageOperations,
spaceFields,
spaceIdProperty,
spaceOperations,
} from './descriptions';
import { googleApiRequest, googleApiRequestAllItems, validateJSON } from './GenericFunctions';
import {
createSendAndWaitMessageBody,
googleApiRequest,
googleApiRequestAllItems,
validateJSON,
} from './GenericFunctions';
import type { IMessage, IMessageUi } from './MessageInterface';
import { sendAndWaitWebhooksDescription } from '../../../utils/sendAndWait/descriptions';
import {
configureWaitTillDate,
getSendAndWaitProperties,
sendAndWaitWebhook,
} from '../../../utils/sendAndWait/utils';
export class GoogleChat implements INodeType {
description: INodeTypeDescription = {
@@ -46,14 +58,46 @@ export class GoogleChat implements INodeType {
},
inputs: [NodeConnectionType.Main],
outputs: [NodeConnectionType.Main],
webhooks: sendAndWaitWebhooksDescription,
credentials: [
{
name: 'googleApi',
required: true,
testedBy: 'testGoogleTokenAuth',
displayOptions: {
show: {
authentication: ['serviceAccount'],
},
},
},
{
name: 'googleChatOAuth2Api',
required: true,
displayOptions: {
show: {
authentication: ['oAuth2'],
},
},
},
],
properties: [
{
displayName: 'Authentication',
name: 'authentication',
type: 'options',
options: [
{
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-miscased
name: 'OAuth2 (recommended)',
value: 'oAuth2',
},
{
name: 'Service Account',
value: 'serviceAccount',
},
],
default: 'serviceAccount',
},
{
displayName: 'Resource',
name: 'resource',
@@ -100,9 +144,16 @@ export class GoogleChat implements INodeType {
...messageFields,
...spaceOperations,
...spaceFields,
...getSendAndWaitProperties([spaceIdProperty], 'message', undefined, {
noButtonStyle: true,
defaultApproveLabel: '✅ Approve',
defaultDisapproveLabel: '❌ Decline',
}).filter((p) => p.name !== 'subject'),
],
};
webhook = sendAndWaitWebhook;
methods = {
loadOptions: {
// Get all the spaces to display them to user so that they can
@@ -196,6 +247,19 @@ export class GoogleChat implements INodeType {
let responseData;
const resource = this.getNodeParameter('resource', 0);
const operation = this.getNodeParameter('operation', 0);
if (resource === 'message' && operation === SEND_AND_WAIT_OPERATION) {
const spaceId = this.getNodeParameter('spaceId', 0) as string;
const body = createSendAndWaitMessageBody(this);
await googleApiRequest.call(this, 'POST', `/v1/${spaceId}/messages`, body);
const waitTill = configureWaitTillDate(this);
await this.putExecutionToWait(waitTill);
return [this.getInputData()];
}
for (let i = 0; i < length; i++) {
try {
if (resource === 'media') {