mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-20 11:22:15 +00:00
feat(Google Chat Node): Updates (#12827)
Co-authored-by: Dana <152518854+dana-gill@users.noreply.github.com>
This commit is contained in:
@@ -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') {
|
||||
|
||||
Reference in New Issue
Block a user