first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled

This commit is contained in:
2026-03-17 16:22:57 +03:30
commit 3d5eaf9445
15349 changed files with 2847338 additions and 0 deletions
@@ -0,0 +1,184 @@
import type {
IDataObject,
IExecuteFunctions,
IHttpRequestMethods,
ILoadOptionsFunctions,
INodeProperties,
IRequestOptions,
JsonObject,
} from 'n8n-workflow';
import { NodeApiError } from 'n8n-workflow';
import { getSendAndWaitConfig } from '../../../utils/sendAndWait/utils';
import { createUtmCampaignLink } from '../../../utils/utilities';
import { getGoogleAccessToken } from '../GenericFunctions';
async function googleServiceAccountApiRequest(
this: IExecuteFunctions | ILoadOptionsFunctions,
options: IRequestOptions,
noCredentials = false,
): Promise<any> {
if (noCredentials) {
return await this.helpers.request(options);
}
const credentials = await this.getCredentials('googleApi');
const { access_token } = await getGoogleAccessToken.call(this, credentials, 'chat');
options.headers!.Authorization = `Bearer ${access_token}`;
return await this.helpers.request(options);
}
export async function googleApiRequest(
this: IExecuteFunctions | ILoadOptionsFunctions,
method: IHttpRequestMethods,
resource: string,
body: IDataObject = {},
qs: IDataObject = {},
uri?: string,
noCredentials = false,
encoding?: null,
) {
const options: IRequestOptions = {
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
method,
body,
qs,
uri: uri || `https://chat.googleapis.com${resource}`,
qsStringifyOptions: {
arrayFormat: 'repeat',
},
json: true,
};
if (encoding === null) {
options.encoding = null;
}
if (Object.keys(body).length === 0) {
delete options.body;
}
let responseData;
try {
if (noCredentials || this.getNodeParameter('authentication', 0) === 'serviceAccount') {
responseData = await googleServiceAccountApiRequest.call(this, options, noCredentials);
} else {
responseData = await this.helpers.requestWithAuthentication.call(
this,
'googleChatOAuth2Api',
options,
);
}
} catch (error) {
if (error.code === 'ERR_OSSL_PEM_NO_START_LINE') {
error.statusCode = '401';
}
throw new NodeApiError(this.getNode(), error as JsonObject);
}
if (Object.keys(responseData as IDataObject).length !== 0) {
return responseData;
} else {
return { success: true };
}
}
export async function googleApiRequestAllItems(
this: IExecuteFunctions | ILoadOptionsFunctions,
propertyName: string,
method: IHttpRequestMethods,
endpoint: string,
body: any = {},
query: IDataObject = {},
): Promise<any> {
const returnData: IDataObject[] = [];
let responseData;
query.pageSize = 100;
do {
responseData = await googleApiRequest.call(this, method, endpoint, body, query);
query.pageToken = responseData.nextPageToken;
returnData.push.apply(returnData, responseData[propertyName] as IDataObject[]);
} while (responseData.nextPageToken !== undefined && responseData.nextPageToken !== '');
return returnData;
}
export function validateJSON(json: string | undefined): any {
let result;
try {
result = JSON.parse(json!);
} catch (exception) {
result = undefined;
}
return result;
}
export function getPagingParameters(resource: string, operation = 'getAll') {
const pagingParameters: INodeProperties[] = [
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
displayOptions: {
show: {
resource: [resource],
operation: [operation],
},
},
default: false,
description: 'Whether to return all results or only up to a given limit',
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
typeOptions: {
maxValue: 1000,
},
displayOptions: {
show: {
resource: [resource],
operation: [operation],
returnAll: [false],
},
},
default: 100,
description: 'Max number of results to return',
},
];
return pagingParameters;
}
export function createSendAndWaitMessageBody(context: IExecuteFunctions) {
const config = getSendAndWaitConfig(context);
const buttons: string[] = config.options.map(
(option) => `*<${`${option.url}`}|${option.label}>*`,
);
let text = `${config.message}\n\n\n${buttons.join(' ')}`;
if (config.appendAttribution !== false) {
const instanceId = context.getInstanceId();
const attributionText = '_This_ _message_ _was_ _sent_ _automatically_ _with_';
const link = createUtmCampaignLink('n8n-nodes-base.googleChat', instanceId);
const attribution = `${attributionText} _<${link}|n8n>_`;
text += `\n\n${attribution}`;
}
const body = {
text,
};
return body;
}
@@ -0,0 +1,22 @@
{
"node": "n8n-nodes-base.googleChat",
"nodeVersion": "1.0",
"codexVersion": "1.0",
"categories": ["Communication", "HITL"],
"subcategories": {
"HITL": ["Human in the Loop"]
},
"resources": {
"credentialDocumentation": [
{
"url": "https://docs.n8n.io/integrations/builtin/credentials/google/service-account/"
}
],
"primaryDocumentation": [
{
"url": "https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.googlechat/"
}
]
},
"alias": ["human", "form", "wait", "hitl", "approval"]
}
@@ -0,0 +1,632 @@
import jwt from 'jsonwebtoken';
import moment from 'moment-timezone';
import type {
IExecuteFunctions,
ICredentialsDecrypted,
ICredentialTestFunctions,
IDataObject,
ILoadOptionsFunctions,
INodeCredentialTestResult,
INodeExecutionData,
INodePropertyOptions,
INodeType,
INodeTypeDescription,
IRequestOptions,
} from 'n8n-workflow';
import { NodeConnectionTypes, NodeOperationError, SEND_AND_WAIT_OPERATION } from 'n8n-workflow';
import {
// attachmentFields,
// attachmentOperations,
// incomingWebhookFields,
// incomingWebhookOperations,
// mediaFields,
// mediaOperations,
memberFields,
memberOperations,
messageFields,
messageOperations,
spaceFields,
spaceIdProperty,
spaceOperations,
} from './descriptions';
import {
createSendAndWaitMessageBody,
googleApiRequest,
googleApiRequestAllItems,
validateJSON,
} from './GenericFunctions';
import type { IMessage, IMessageUi } from './MessageInterface';
import { configureWaitTillDate } from '../../../utils/sendAndWait/configureWaitTillDate.util';
import { sendAndWaitWebhooksDescription } from '../../../utils/sendAndWait/descriptions';
import {
getSendAndWaitProperties,
SEND_AND_WAIT_WAITING_TOOLTIP,
sendAndWaitWebhook,
} from '../../../utils/sendAndWait/utils';
export class GoogleChat implements INodeType {
description: INodeTypeDescription = {
displayName: 'Google Chat',
name: 'googleChat',
icon: 'file:googleChat.svg',
group: ['input'],
version: 1,
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
description: 'Consume Google Chat API',
schemaPath: 'Google/Chat',
defaults: {
name: 'Google Chat',
},
usableAsTool: true,
inputs: [NodeConnectionTypes.Main],
outputs: [NodeConnectionTypes.Main],
waitingNodeTooltip: SEND_AND_WAIT_WAITING_TOOLTIP,
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',
required: true,
noDataExpression: true,
type: 'options',
options: [
// {
// name: 'Attachment',
// value: 'attachment',
// },
// {
// name: 'Incoming Webhook',
// value: 'incomingWebhook',
// },
// {
// name: 'Media',
// value: 'media',
// },
{
name: 'Member',
value: 'member',
},
{
name: 'Message',
value: 'message',
},
{
name: 'Space',
value: 'space',
},
],
default: 'message',
},
// ...attachmentOperations,
// ...attachmentFields,
// ...incomingWebhookOperations,
// ...incomingWebhookFields,
// ...mediaOperations,
// ...mediaFields,
...memberOperations,
...memberFields,
...messageOperations,
...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
// select them easily
async getSpaces(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
const spaces = await googleApiRequestAllItems.call(this, 'spaces', 'GET', '/v1/spaces');
for (const space of spaces) {
returnData.push({
name: space.displayName,
value: space.name,
});
}
return returnData;
},
},
credentialTest: {
async testGoogleTokenAuth(
this: ICredentialTestFunctions,
credential: ICredentialsDecrypted,
): Promise<INodeCredentialTestResult> {
const scopes = ['https://www.googleapis.com/auth/chat.bot'];
const now = moment().unix();
const email = (credential.data!.email as string).trim();
const privateKey = (credential.data!.privateKey as string).replace(/\\n/g, '\n').trim();
try {
const signature = jwt.sign(
{
iss: email,
sub: credential.data!.delegatedEmail || email,
scope: scopes.join(' '),
aud: 'https://oauth2.googleapis.com/token',
iat: now,
exp: now,
},
privateKey,
{
algorithm: 'RS256',
header: {
kid: privateKey,
typ: 'JWT',
alg: 'RS256',
},
},
);
const options: IRequestOptions = {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
method: 'POST',
form: {
grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
assertion: signature,
},
uri: 'https://oauth2.googleapis.com/token',
json: true,
};
const response = await this.helpers.request(options);
if (!response.access_token) {
return {
status: 'Error',
message: JSON.stringify(response),
};
}
} catch (err) {
return {
status: 'Error',
message: `${err.message}`,
};
}
return {
status: 'OK',
message: 'Connection successful!',
};
},
},
};
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
const returnData: INodeExecutionData[] = [];
const length = items.length;
const qs: IDataObject = {};
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') {
if (operation === 'download') {
// ----------------------------------------
// media: download
// ----------------------------------------
// https://developers.google.com/chat/reference/rest/v1/media/download
const resourceName = this.getNodeParameter('resourceName', i) as string;
const endpoint = `/v1/media/${resourceName}?alt=media`;
// Return the data as a buffer
const encoding = null;
responseData = await googleApiRequest.call(
this,
'GET',
endpoint,
undefined,
undefined,
undefined,
undefined,
encoding,
);
const newItem: INodeExecutionData = {
json: items[i].json,
binary: {},
};
if (items[i].binary !== undefined) {
// Create a shallow copy of the binary data so that the old
// data references which do not get changed still stay behind
// but the incoming data does not get changed.
Object.assign(newItem.binary!, items[i].binary);
}
items[i] = newItem;
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
items[i].binary![binaryPropertyName] = await this.helpers.prepareBinaryData(
responseData as Buffer,
endpoint,
);
}
} else if (resource === 'space') {
if (operation === 'get') {
// ----------------------------------------
// space: get
// ----------------------------------------
// https://developers.google.com/chat/reference/rest/v1/spaces/get
const spaceId = this.getNodeParameter('spaceId', i) as string;
responseData = await googleApiRequest.call(this, 'GET', `/v1/${spaceId}`);
} else if (operation === 'getAll') {
// ----------------------------------------
// space: getAll
// ----------------------------------------
// https://developers.google.com/chat/reference/rest/v1/spaces/list
const returnAll = this.getNodeParameter('returnAll', 0);
if (returnAll) {
responseData = await googleApiRequestAllItems.call(
this,
'spaces',
'GET',
'/v1/spaces',
);
} else {
const limit = this.getNodeParameter('limit', i);
qs.pageSize = limit;
responseData = await googleApiRequest.call(this, 'GET', '/v1/spaces', undefined, qs);
responseData = responseData.spaces;
}
}
} else if (resource === 'member') {
if (operation === 'get') {
// ----------------------------------------
// member: get
// ----------------------------------------
// https://developers.google.com/chat/reference/rest/v1/spaces.members/get
const memberId = this.getNodeParameter('memberId', i) as string;
responseData = await googleApiRequest.call(this, 'GET', `/v1/${memberId}`);
} else if (operation === 'getAll') {
// ----------------------------------------
// member: getAll
// ----------------------------------------
// https://developers.google.com/chat/reference/rest/v1/spaces.members/list
const spaceId = this.getNodeParameter('spaceId', i) as string;
const returnAll = this.getNodeParameter('returnAll', 0);
if (returnAll) {
responseData = await googleApiRequestAllItems.call(
this,
'memberships',
'GET',
`/v1/${spaceId}/members`,
undefined,
qs,
);
} else {
const limit = this.getNodeParameter('limit', i);
qs.pageSize = limit;
responseData = await googleApiRequest.call(
this,
'GET',
`/v1/${spaceId}/members`,
undefined,
qs,
);
responseData = responseData.memberships;
}
}
} else if (resource === 'message') {
if (operation === 'create') {
// ----------------------------------------
// message: create
// ----------------------------------------
// https://developers.google.com/chat/reference/rest/v1/spaces.messages/create
const spaceId = this.getNodeParameter('spaceId', i) as string;
// get additional fields for threadKey and requestId
const additionalFields = this.getNodeParameter('additionalFields', i);
if (additionalFields.threadKey) {
qs.threadKey = additionalFields.threadKey;
}
if (additionalFields.requestId) {
qs.requestId = additionalFields.requestId;
}
let message: IMessage = {};
const jsonParameters = this.getNodeParameter('jsonParameters', i);
if (jsonParameters) {
const messageJson = this.getNodeParameter('messageJson', i);
if (messageJson instanceof Object) {
// if it is an object
message = messageJson as IMessage;
} else {
// if it is a string
if (validateJSON(messageJson as string) !== undefined) {
message = JSON.parse(messageJson as string) as IMessage;
} else {
throw new NodeOperationError(
this.getNode(),
'Message (JSON) must be a valid json',
{ itemIndex: i },
);
}
}
} else {
const messageUi = this.getNodeParameter('messageUi', i) as IMessageUi;
if (messageUi.text && messageUi.text !== '') {
message.text = messageUi.text;
} else {
throw new NodeOperationError(this.getNode(), 'Message Text must be provided.', {
itemIndex: i,
});
}
// // TODO: get cards from the UI
// if (messageUi?.cards?.metadataValues && messageUi?.cards?.metadataValues.length !== 0) {
// const cards = messageUi.cards.metadataValues as IDataObject[]; // TODO: map cards to messageUi.cards.metadataValues
// message.cards = cards;
// }
}
const body: IDataObject = {};
Object.assign(body, message);
responseData = await googleApiRequest.call(
this,
'POST',
`/v1/${spaceId}/messages`,
body,
qs,
);
} else if (operation === 'delete') {
// ----------------------------------------
// message: delete
// ----------------------------------------
// https://developers.google.com/chat/reference/rest/v1/spaces.messages/delete
const messageId = this.getNodeParameter('messageId', i) as string;
responseData = await googleApiRequest.call(this, 'DELETE', `/v1/${messageId}`);
} else if (operation === 'get') {
// ----------------------------------------
// message: get
// ----------------------------------------
// https://developers.google.com/chat/reference/rest/v1/spaces.messages/get
const messageId = this.getNodeParameter('messageId', i) as string;
responseData = await googleApiRequest.call(this, 'GET', `/v1/${messageId}`);
} else if (operation === 'update') {
// ----------------------------------------
// message: update
// ----------------------------------------
// https://developers.google.com/chat/reference/rest/v1/spaces.messages/update
const messageId = this.getNodeParameter('messageId', i) as string;
let message: IMessage = {};
const jsonParameters = this.getNodeParameter('jsonParameters', i);
if (jsonParameters) {
const updateFieldsJson = this.getNodeParameter('updateFieldsJson', i);
if (updateFieldsJson instanceof Object) {
// if it is an object
message = updateFieldsJson as IMessage;
} else {
// if it is a string
if (validateJSON(updateFieldsJson as string) !== undefined) {
message = JSON.parse(updateFieldsJson as string) as IMessage;
} else {
throw new NodeOperationError(
this.getNode(),
'Update Fields (JSON) must be a valid json',
{ itemIndex: i },
);
}
}
} else {
const updateFieldsUi = this.getNodeParameter('updateFieldsUi', i) as IDataObject;
if (updateFieldsUi.text) {
message.text = updateFieldsUi.text as string;
}
// // TODO: get cards from the UI
// if (updateFieldsUi.cards) {
// message.cards = updateFieldsUi.cards as IDataObject[];
// }
}
const body: IDataObject = {};
Object.assign(body, message);
// get update mask
let updateMask = '';
if (message.text) {
updateMask += 'text,';
}
if (message.cards) {
updateMask += 'cards,';
}
updateMask = updateMask.slice(0, -1); // remove trailing comma
qs.updateMask = updateMask;
responseData = await googleApiRequest.call(this, 'PUT', `/v1/${messageId}`, body, qs);
}
} else if (resource === 'attachment') {
if (operation === 'get') {
// ----------------------------------------
// attachment: get
// ----------------------------------------
// https://developers.google.com/chat/reference/rest/v1/spaces.messages.attachments/get
const attachmentName = this.getNodeParameter('attachmentName', i) as string;
responseData = await googleApiRequest.call(this, 'GET', `/v1/${attachmentName}`);
}
} else if (resource === 'incomingWebhook') {
if (operation === 'create') {
// ----------------------------------------
// incomingWebhook: create
// ----------------------------------------
// https://developers.google.com/chat/how-tos/webhooks
const uri = this.getNodeParameter('incomingWebhookUrl', i) as string;
// get additional fields for threadKey
const additionalFields = this.getNodeParameter('additionalFields', i);
if (additionalFields.threadKey) {
qs.threadKey = additionalFields.threadKey;
}
let message: IMessage = {};
const jsonParameters = this.getNodeParameter('jsonParameters', i);
if (jsonParameters) {
const messageJson = this.getNodeParameter('messageJson', i);
if (messageJson instanceof Object) {
// if it is an object
message = messageJson as IMessage;
} else {
// if it is a string
if (validateJSON(messageJson as string) !== undefined) {
message = JSON.parse(messageJson as string) as IMessage;
} else {
throw new NodeOperationError(
this.getNode(),
'Message (JSON) must be a valid json',
{ itemIndex: i },
);
}
}
} else {
const messageUi = this.getNodeParameter('messageUi', i) as IMessageUi;
if (messageUi.text && messageUi.text !== '') {
message.text = messageUi.text;
} else {
throw new NodeOperationError(this.getNode(), 'Message Text must be provided.', {
itemIndex: i,
});
}
}
const body: IDataObject = {};
Object.assign(body, message);
responseData = await googleApiRequest.call(this, 'POST', '', body, qs, uri, true);
}
}
const executionData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData as IDataObject),
{ itemData: { item: i } },
);
returnData.push(...executionData);
} catch (error) {
if (this.continueOnFail()) {
// Return the actual reason as error
if (operation === 'download') {
items[i].json = { error: error.message };
} else {
const executionErrorData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray({ error: error.message }),
{ itemData: { item: i } },
);
returnData.push(...executionErrorData);
}
continue;
}
throw error;
}
}
if (operation === 'download') {
// For file downloads the files get attached to the existing items
return [items];
} else {
// For all other ones does the output get replaced
return [returnData];
}
}
}
@@ -0,0 +1,110 @@
import type { IDataObject } from 'n8n-workflow';
export interface IMessage {
name?: string;
sender?: IUser;
createTime?: string;
text?: string;
cards?: IDataObject[];
previewText?: string;
annotations?: IDataObject[];
thread?: IDataObject[];
space?: IDataObject;
fallbackText?: string;
actionResponse?: IDataObject;
argumentText?: string;
slashCommand?: IDataObject;
attachment?: IDataObject[];
}
export interface IMessageUi {
text?: string;
cards?: {
metadata: IDataObject[];
};
}
export interface IUser {
name?: string;
displayName?: string;
domainId?: string;
type?: Type;
isAnonymous?: boolean;
}
const Types = {
TYPE_UNSPECIFIED: 0,
HUMAN: 1,
BOT: 2,
} as const;
export type Type = (typeof Types)[keyof typeof Types];
// // TODO: define other interfaces
//
// export interface IMessage {s
// name?: string;
// sender?: IUser;
// createTime?: string;
// text?: string;
// cards?: ICard[];
// previewText?: string;
// annotations?: IAnnotation[];
// thread?: IThread[];
// space?: ISpace;
// fallbackText?: string;
// actionResponse?: IActionResponse;
// argumentText?: string;
// slashCommand?: ISlashCommand;
// attachment?: IAttachment[];
// }
//
// export interface ICard {
// header?: ICardHeader;
// sections?: ISection[];
// cardActions?: ICardAction[];
// name?: string;
// }
//
// export interface ICardHeader {
// title: string;
// subtitle: string;
// imageStyle: ImageStyleType;
// imageUrl: string;
// }
// enum ImageStyleType {
// 'IMAGE_STYLE_UNSPECIFIED',
// 'IMAGE',
// 'AVATAR',
// }
//
// export interface ISection {
//
// }
//
// export interface ICardAction {
//
// }
//
// export interface IAnnotation {
//
// }
//
// export interface IThread {
//
// }
//
// export interface ISpace {
//
// }
//
// export interface IActionResponse {
//
// }
//
// export interface ISlashCommand {
//
// }
//
// export interface IAttachment {
// // attachments are not available for bots
// }
@@ -0,0 +1,35 @@
{
"type": "object",
"properties": {
"createTime": {
"type": "string"
},
"member": {
"type": "object",
"properties": {
"displayName": {
"type": "string"
},
"domainId": {
"type": "string"
},
"name": {
"type": "string"
},
"type": {
"type": "string"
}
}
},
"name": {
"type": "string"
},
"role": {
"type": "string"
},
"state": {
"type": "string"
}
},
"version": 3
}
@@ -0,0 +1,77 @@
{
"type": "object",
"properties": {
"argumentText": {
"type": "string"
},
"createTime": {
"type": "string"
},
"formattedText": {
"type": "string"
},
"name": {
"type": "string"
},
"sender": {
"type": "object",
"properties": {
"displayName": {
"type": "string"
},
"name": {
"type": "string"
},
"type": {
"type": "string"
}
}
},
"space": {
"type": "object",
"properties": {
"lastActiveTime": {
"type": "string"
},
"membershipCount": {
"type": "object",
"properties": {
"joinedDirectHumanUserCount": {
"type": "integer"
}
}
},
"name": {
"type": "string"
},
"spaceHistoryState": {
"type": "string"
},
"spaceThreadingState": {
"type": "string"
},
"spaceType": {
"type": "string"
},
"spaceUri": {
"type": "string"
},
"type": {
"type": "string"
}
}
},
"text": {
"type": "string"
},
"thread": {
"type": "object",
"properties": {
"name": {
"type": "string"
}
}
}
},
"version": 6
}
@@ -0,0 +1,77 @@
{
"type": "object",
"properties": {
"argumentText": {
"type": "string"
},
"createTime": {
"type": "string"
},
"formattedText": {
"type": "string"
},
"name": {
"type": "string"
},
"sender": {
"type": "object",
"properties": {
"displayName": {
"type": "string"
},
"name": {
"type": "string"
},
"type": {
"type": "string"
}
}
},
"space": {
"type": "object",
"properties": {
"lastActiveTime": {
"type": "string"
},
"membershipCount": {
"type": "object",
"properties": {
"joinedDirectHumanUserCount": {
"type": "integer"
}
}
},
"name": {
"type": "string"
},
"spaceHistoryState": {
"type": "string"
},
"spaceThreadingState": {
"type": "string"
},
"spaceType": {
"type": "string"
},
"spaceUri": {
"type": "string"
},
"type": {
"type": "string"
}
}
},
"text": {
"type": "string"
},
"thread": {
"type": "object",
"properties": {
"name": {
"type": "string"
}
}
}
},
"version": 3
}
@@ -0,0 +1,17 @@
{
"type": "object",
"properties": {
"data": {
"type": "object",
"properties": {
"approved": {
"type": "boolean"
},
"text": {
"type": "string"
}
}
}
},
"version": 2
}
@@ -0,0 +1,148 @@
{
"type": "object",
"properties": {
"accessSettings": {
"type": "object",
"properties": {
"accessState": {
"type": "string"
},
"audience": {
"type": "string"
}
}
},
"createTime": {
"type": "string"
},
"customer": {
"type": "string"
},
"displayName": {
"type": "string"
},
"lastActiveTime": {
"type": "string"
},
"membershipCount": {
"type": "object",
"properties": {
"joinedDirectHumanUserCount": {
"type": "integer"
}
}
},
"name": {
"type": "string"
},
"permissionSettings": {
"type": "object",
"properties": {
"manageApps": {
"type": "object",
"properties": {
"managersAllowed": {
"type": "boolean"
},
"membersAllowed": {
"type": "boolean"
}
}
},
"manageMembersAndGroups": {
"type": "object",
"properties": {
"managersAllowed": {
"type": "boolean"
},
"membersAllowed": {
"type": "boolean"
}
}
},
"manageWebhooks": {
"type": "object",
"properties": {
"managersAllowed": {
"type": "boolean"
},
"membersAllowed": {
"type": "boolean"
}
}
},
"modifySpaceDetails": {
"type": "object",
"properties": {
"managersAllowed": {
"type": "boolean"
},
"membersAllowed": {
"type": "boolean"
}
}
},
"postMessages": {
"type": "object",
"properties": {
"managersAllowed": {
"type": "boolean"
},
"membersAllowed": {
"type": "boolean"
}
}
},
"replyMessages": {
"type": "object",
"properties": {
"managersAllowed": {
"type": "boolean"
},
"membersAllowed": {
"type": "boolean"
}
}
},
"toggleHistory": {
"type": "object",
"properties": {
"managersAllowed": {
"type": "boolean"
},
"membersAllowed": {
"type": "boolean"
}
}
},
"useAtMentionAll": {
"type": "object",
"properties": {
"managersAllowed": {
"type": "boolean"
},
"membersAllowed": {
"type": "boolean"
}
}
}
}
},
"spaceHistoryState": {
"type": "string"
},
"spaceThreadingState": {
"type": "string"
},
"spaceType": {
"type": "string"
},
"spaceUri": {
"type": "string"
},
"type": {
"type": "string"
}
},
"version": 2
}
@@ -0,0 +1,44 @@
{
"type": "object",
"properties": {
"createTime": {
"type": "string"
},
"customer": {
"type": "string"
},
"displayName": {
"type": "string"
},
"lastActiveTime": {
"type": "string"
},
"membershipCount": {
"type": "object",
"properties": {
"joinedDirectHumanUserCount": {
"type": "integer"
}
}
},
"name": {
"type": "string"
},
"spaceHistoryState": {
"type": "string"
},
"spaceThreadingState": {
"type": "string"
},
"spaceType": {
"type": "string"
},
"spaceUri": {
"type": "string"
},
"type": {
"type": "string"
}
},
"version": 2
}
@@ -0,0 +1,45 @@
import type { INodeProperties } from 'n8n-workflow';
export const attachmentOperations: INodeProperties[] = [
{
displayName: 'Operation',
name: 'operation',
noDataExpression: true,
type: 'options',
displayOptions: {
show: {
resource: ['attachment'],
},
},
options: [
{
name: 'Get',
value: 'get',
description:
'Gets the metadata of a message attachment. The attachment data is fetched using the media API.',
action: 'Get an attachment',
},
],
default: 'get',
},
];
export const attachmentFields: INodeProperties[] = [
/* -------------------------------------------------------------------------- */
/* attachments:get */
/* -------------------------------------------------------------------------- */
{
displayName: 'Attachment Name',
name: 'attachmentName',
type: 'string',
required: true,
displayOptions: {
show: {
resource: ['attachment'],
operation: ['get'],
},
},
default: '',
description: 'Resource name of the attachment, in the form "spaces/*/messages/*/attachments/*"',
},
];
@@ -0,0 +1,150 @@
import type { INodeProperties } from 'n8n-workflow';
export const incomingWebhookOperations: INodeProperties[] = [
{
displayName: 'Operation',
name: 'operation',
noDataExpression: true,
type: 'options',
displayOptions: {
show: {
resource: ['incomingWebhook'],
},
},
options: [
{
name: 'Create',
value: 'create',
description: 'Creates a message through incoming webhook (no chat bot needed)',
action: 'Create an incoming webhook',
},
],
default: 'create',
},
];
export const incomingWebhookFields: INodeProperties[] = [
/* -------------------------------------------------------------------------- */
/* incomingWebhook:create */
/* -------------------------------------------------------------------------- */
{
displayName:
'See <a href="https://developers.google.com/chat/how-tos/webhooks" target="_blank">Google Chat Guide</a> To Webhooks',
name: 'jsonNotice',
type: 'notice',
displayOptions: {
show: {
resource: ['incomingWebhook'],
operation: ['create'],
},
},
default: '',
},
{
displayName: 'Incoming Webhook URL',
name: 'incomingWebhookUrl',
type: 'string',
required: true,
displayOptions: {
show: {
resource: ['incomingWebhook'],
operation: ['create'],
},
},
default: '',
description: 'URL for the incoming webhook',
},
{
displayName: 'JSON Parameters',
name: 'jsonParameters',
type: 'boolean',
displayOptions: {
show: {
resource: ['incomingWebhook'],
operation: ['create'],
},
},
default: false,
description: 'Whether to pass the message object as JSON',
},
{
displayName: 'Message',
name: 'messageUi',
type: 'collection',
required: true,
placeholder: 'Add option',
displayOptions: {
show: {
resource: ['incomingWebhook'],
operation: ['create'],
jsonParameters: [false],
},
},
default: { text: '' },
description: 'The message object',
options: [
{
displayName: 'Text',
name: 'text',
type: 'string',
default: '',
description: 'The message text',
},
],
},
{
displayName:
'See <a href="https://developers.google.com/chat/reference/rest/v1/spaces.messages#Message" target="_blank">Google Chat Guide</a> To Creating Messages',
name: 'jsonNotice',
type: 'notice',
displayOptions: {
show: {
resource: ['incomingWebhook'],
operation: ['create'],
jsonParameters: [true],
},
},
default: '',
},
{
displayName: 'Message (JSON)',
name: 'messageJson',
type: 'json',
required: true,
typeOptions: {
alwaysOpenEditWindow: true,
},
displayOptions: {
show: {
resource: ['incomingWebhook'],
operation: ['create'],
jsonParameters: [true],
},
},
default: '',
description: 'Message input as JSON Object or JSON String',
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
resource: ['incomingWebhook'],
operation: ['create'],
},
},
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.',
},
],
},
];
@@ -0,0 +1,58 @@
import type { INodeProperties } from 'n8n-workflow';
export const mediaOperations: INodeProperties[] = [
{
displayName: 'Operation',
name: 'operation',
noDataExpression: true,
type: 'options',
displayOptions: {
show: {
resource: ['media'],
},
},
options: [
{
name: 'Download',
value: 'download',
description: 'Download media',
action: 'Download media',
},
],
default: 'download',
},
];
export const mediaFields: INodeProperties[] = [
/* -------------------------------------------------------------------------- */
/* media:download */
/* -------------------------------------------------------------------------- */
{
displayName: 'Resource Name',
name: 'resourceName',
type: 'string',
required: true,
displayOptions: {
show: {
resource: ['media'],
operation: ['download'],
},
},
default: '',
description: 'Name of the media that is being downloaded',
},
{
displayName: 'Put Output File in Field',
name: 'binaryPropertyName',
type: 'string',
default: 'data',
required: true,
displayOptions: {
show: {
resource: ['media'],
operation: ['download'],
},
},
hint: 'The name of the output binary field to put the file in',
},
];
@@ -0,0 +1,76 @@
import type { INodeProperties } from 'n8n-workflow';
import { getPagingParameters } from '../GenericFunctions';
export const memberOperations: INodeProperties[] = [
{
displayName: 'Operation',
name: 'operation',
noDataExpression: true,
type: 'options',
displayOptions: {
show: {
resource: ['member'],
},
},
options: [
{
name: 'Get',
value: 'get',
description: 'Get a membership',
action: 'Get a member',
},
{
name: 'Get Many',
value: 'getAll',
description: 'Get many memberships in a space',
action: 'Get many members',
},
],
default: 'get',
},
];
export const memberFields: INodeProperties[] = [
/* -------------------------------------------------------------------------- */
/* member:get */
/* -------------------------------------------------------------------------- */
{
displayName: 'Member ID',
name: 'memberId',
type: 'string',
required: true,
displayOptions: {
show: {
resource: ['member'],
operation: ['get'],
},
},
default: '',
description: 'Member to be retrieved in the form "spaces/*/members/*"',
},
/* -------------------------------------------------------------------------- */
/* member:getAll */
/* -------------------------------------------------------------------------- */
{
displayName: 'Space Name or ID',
name: 'spaceId',
type: 'options',
required: true,
typeOptions: {
loadOptionsMethod: 'getSpaces',
},
displayOptions: {
show: {
resource: ['member'],
operation: ['getAll'],
},
},
default: [],
description:
'The name of the space for which to retrieve members, in the form "spaces/*". Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
...getPagingParameters('member'),
];
@@ -0,0 +1,390 @@
import { SEND_AND_WAIT_OPERATION, type INodeProperties } from 'n8n-workflow';
export const messageOperations: INodeProperties[] = [
{
displayName: 'Operation',
name: 'operation',
noDataExpression: true,
type: 'options',
displayOptions: {
show: {
resource: ['message'],
},
},
options: [
{
name: 'Create',
value: 'create',
description: 'Create a message',
action: 'Create a message',
},
{
name: 'Delete',
value: 'delete',
description: 'Delete a message',
action: 'Delete a message',
},
{
name: 'Get',
value: 'get',
description: 'Get a message',
action: 'Get a message',
},
{
name: 'Send and Wait for Response',
value: SEND_AND_WAIT_OPERATION,
description: 'Send a message and wait for response',
action: 'Send message and wait for response',
},
{
name: 'Update',
value: 'update',
description: 'Update a message',
action: 'Update a message',
},
],
default: 'create',
},
];
export const spaceIdProperty: INodeProperties = {
displayName: 'Space Name or ID',
name: 'spaceId',
type: 'options',
required: true,
typeOptions: {
loadOptionsMethod: 'getSpaces',
},
default: '',
description:
'Space resource name, in the form "spaces/*". Example: spaces/AAAAMpdlehY. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
};
export const messageFields: INodeProperties[] = [
/* -------------------------------------------------------------------------- */
/* message:create */
/* -------------------------------------------------------------------------- */
{
...spaceIdProperty,
displayOptions: {
show: {
resource: ['message'],
operation: ['create'],
},
},
},
{
displayName: 'JSON Parameters',
name: 'jsonParameters',
type: 'boolean',
displayOptions: {
show: {
resource: ['message'],
operation: ['create'],
},
},
default: false,
description: 'Whether to pass the message object as JSON',
},
{
displayName: 'Message',
name: 'messageUi',
type: 'collection',
required: true,
placeholder: 'Add Message',
displayOptions: {
show: {
resource: ['message'],
operation: ['create'],
jsonParameters: [false],
},
},
default: {},
options: [
{
displayName: 'Text',
name: 'text',
type: 'string',
default: '',
},
// { // TODO: get cards from the UI (check the Slack node, specifically the blocks parameter under message: post)
// displayName: 'Cards',
// name: 'cards',
// placeholder: 'Add Cards',
// type: 'fixedCollection',
// default: '',
// typeOptions: {
// multipleValues: true,
// },
// description: 'Rich, formatted and interactive cards that can be used to display UI elements such as: formatted texts, buttons, clickable images',
// options: [
// {
// name: 'metadataValues',
// displayName: 'Metadata',
// values: [
// {
// displayName: 'Name',
// name: 'name',
// type: 'string',
// default: '',
// description: 'Name of the card',
// },
// {
// displayName: 'Header',
// name: 'header',
// type: 'json',
// default: '',
// description: 'Header of the card',
// },
// {
// displayName: 'Sections',
// name: 'sections',
// type: 'json',
// default: '',
// description: 'Sections of the card',
// },
// {
// displayName: 'Actions',
// name: 'cardActions',
// type: 'json',
// default: '',
// description: 'Actions of the card',
// },
// ],
// },
// ],
// },
],
},
{
displayName:
'See <a href="https://developers.google.com/chat/reference/rest/v1/spaces.messages#Message" target="_blank">Google Chat Guide</a> To Creating Messages',
name: 'jsonNotice',
type: 'notice',
displayOptions: {
show: {
resource: ['message'],
operation: ['create'],
jsonParameters: [true],
},
},
default: '',
},
{
displayName: 'Message (JSON)',
name: 'messageJson',
type: 'json',
required: true,
typeOptions: {
alwaysOpenEditWindow: true,
},
displayOptions: {
show: {
resource: ['message'],
operation: ['create'],
jsonParameters: [true],
},
},
default: '',
description: 'Message input as JSON Object or JSON String',
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
resource: ['message'],
operation: ['create'],
},
},
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: 'Request ID',
name: 'requestId',
type: 'string',
default: '',
description:
'A unique request ID for this message. If a message has already been created in the space with this request ID, the subsequent request will return the existing message and no new message will be created.',
},
],
},
/* -------------------------------------------------------------------------- */
/* messages:delete */
/* -------------------------------------------------------------------------- */
{
displayName: 'Message ID',
name: 'messageId',
type: 'string',
required: true,
displayOptions: {
show: {
resource: ['message'],
operation: ['delete'],
},
},
default: '',
description: 'Resource name of the message to be deleted, in the form "spaces//messages/"',
},
/* -------------------------------------------------------------------------- */
/* message:get */
/* -------------------------------------------------------------------------- */
{
displayName: 'Message ID',
name: 'messageId',
type: 'string',
required: true,
displayOptions: {
show: {
resource: ['message'],
operation: ['get'],
},
},
default: '',
description: 'Resource name of the message to be retrieved, in the form "spaces//messages/"',
},
/* -------------------------------------------------------------------------- */
/* message:update */
/* -------------------------------------------------------------------------- */
{
displayName: 'Message ID',
name: 'messageId',
type: 'string',
required: true,
displayOptions: {
show: {
resource: ['message'],
operation: ['update'],
},
},
default: '',
description: 'Resource name of the message to be updated, in the form "spaces//messages/"',
},
{
displayName: 'JSON Parameters',
name: 'jsonParameters',
type: 'boolean',
displayOptions: {
show: {
resource: ['message'],
operation: ['update'],
},
},
default: false,
description: 'Whether to pass the update fields object as JSON',
},
{
displayName: 'Update Fields',
name: 'updateFieldsUi',
type: 'collection',
required: true,
placeholder: 'Add option',
displayOptions: {
show: {
resource: ['message'],
operation: ['update'],
jsonParameters: [false],
},
},
default: {},
options: [
{
displayName: 'Text',
name: 'text',
type: 'string',
default: '',
},
// { // TODO: get cards from the UI (check the Slack node, specifically the blocks parameter under message: post)
// displayName: 'Cards',
// name: 'cards',
// placeholder: 'Add Cards',
// type: 'fixedCollection',
// default: '',
// typeOptions: {
// multipleValues: true,
// },
// description: 'Rich, formatted and interactive cards that can be used to display UI elements such as: formatted texts, buttons, clickable images',
// options: [
// {
// name: 'metadataValues',
// displayName: 'Metadata',
// values: [
// {
// displayName: 'Name',
// name: 'name',
// type: 'string',
// default: '',
// description: 'Name of the card',
// },
// {
// displayName: 'Header',
// name: 'header',
// type: 'json',
// default: '',
// description: 'Header of the card',
// },
// {
// displayName: 'Sections',
// name: 'sections',
// type: 'json',
// default: '',
// description: 'Sections of the card',
// },
// {
// displayName: 'Actions',
// name: 'cardActions',
// type: 'json',
// default: '',
// description: 'Actions of the card',
// },
// ],
// },
// ],
// },
],
},
{
displayName:
'See <a href="https://developers.google.com/chat/reference/rest/v1/spaces.messages#Message" target="_blank">Google Chat Guide</a> To Creating Messages',
name: 'jsonNotice',
type: 'notice',
displayOptions: {
show: {
resource: ['message'],
operation: ['update'],
jsonParameters: [true],
},
},
default: '',
},
{
displayName: 'Update Fields (JSON)',
name: 'updateFieldsJson',
type: 'json',
required: true,
typeOptions: {
alwaysOpenEditWindow: true,
},
displayOptions: {
show: {
resource: ['message'],
operation: ['update'],
jsonParameters: [true],
},
},
default: '',
description: 'Message input as JSON Object or JSON String',
},
];
@@ -0,0 +1,58 @@
import type { INodeProperties } from 'n8n-workflow';
import { getPagingParameters } from '../GenericFunctions';
export const spaceOperations: INodeProperties[] = [
{
displayName: 'Operation',
name: 'operation',
noDataExpression: true,
type: 'options',
displayOptions: {
show: {
resource: ['space'],
},
},
options: [
{
name: 'Get',
value: 'get',
description: 'Get a space',
action: 'Get a space',
},
{
name: 'Get Many',
value: 'getAll',
description: 'Get many spaces the caller is a member of',
action: 'Get many spaces',
},
],
default: 'get',
},
];
export const spaceFields: INodeProperties[] = [
/* -------------------------------------------------------------------------- */
/* space:get */
/* -------------------------------------------------------------------------- */
{
displayName: 'Space ID',
name: 'spaceId',
type: 'string',
required: true,
displayOptions: {
show: {
resource: ['space'],
operation: ['get'],
},
},
default: '',
description: 'Resource name of the space, in the form "spaces/*"',
},
/* -------------------------------------------------------------------------- */
/* space:getAll */
/* -------------------------------------------------------------------------- */
...getPagingParameters('space'),
];
@@ -0,0 +1,6 @@
export * from './AttachmentDescription';
export * from './IncomingWebhookDescription';
export * from './MediaDescription';
export * from './MemberDescription';
export * from './MessageDescription';
export * from './SpaceDescription';
@@ -0,0 +1,19 @@
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0.00 0.00 311.00 320.00">
<g stroke-width="2.00" fill="none" stroke-linecap="butt">
<path stroke="#7e916f" vector-effect="non-scaling-stroke" d=" M 76.37 0.51 L 76.38 76.98"/>
<path stroke="#1375eb" vector-effect="non-scaling-stroke" d=" M 76.38 76.98 L 0.00 76.96"/>
<path stroke="#f3801d" vector-effect="non-scaling-stroke" d=" M 235.08 1.09 Q 234.92 1.15 234.81 1.22 Q 234.64 1.31 234.64 1.50 L 234.62 77.01"/>
<path stroke="#7eb426" vector-effect="non-scaling-stroke" d=" M 234.62 77.01 Q 234.60 77.01 234.57 77.01"/>
<path stroke="#91a080" vector-effect="non-scaling-stroke" d=" M 76.41 77.01 Q 76.40 77.00 76.38 76.98"/>
<path stroke="#75783e" vector-effect="non-scaling-stroke" d=" M 310.53 76.77 L 234.62 77.01"/>
<path stroke="#138495" vector-effect="non-scaling-stroke" d=" M 76.43 182.69 L 0.00 182.67"/>
<path stroke="#00983a" vector-effect="non-scaling-stroke" d=" M 76.44 259.13 L 76.43 220.85"/>
</g>
<path fill="#0066da" d=" M 76.37 0.51 L 76.38 76.98 L 0.00 76.96 L 0.00 20.77 Q 0.85 14.81 3.53 10.76 Q 10.14 0.74 22.75 0.67 Q 49.41 0.53 76.37 0.51 Z"/>
<path fill="#fbbc04" d=" M 76.37 0.51 L 233.79 0.53 A 1.61 1.57 -26.7 0 1 234.71 0.82 L 235.08 1.09 Q 234.92 1.15 234.81 1.22 Q 234.64 1.31 234.64 1.50 L 234.62 77.01 Q 234.60 77.01 234.57 77.01 L 76.41 77.01 Q 76.40 77.00 76.38 76.98 L 76.37 0.51 Z"/>
<path fill="#ea4335" d=" M 235.08 1.09 L 310.53 76.77 L 234.62 77.01 L 234.64 1.50 Q 234.64 1.31 234.81 1.22 Q 234.92 1.15 235.08 1.09 Z"/>
<path fill="#2684fc" d=" M 0.00 76.96 L 76.38 76.98 Q 76.40 77.00 76.41 77.01 L 76.43 182.69 L 0.00 182.67 L 0.00 76.96 Z"/>
<path fill="#00ac47" d=" M 310.53 76.77 L 311.00 77.11 L 311.00 239.01 Q 308.34 253.54 295.94 257.78 Q 291.52 259.30 282.91 259.28 Q 227.02 259.19 169.99 259.11 Q 161.71 259.10 153.19 259.23 Q 152.72 259.24 152.39 259.57 Q 124.49 287.34 96.39 315.59 C 93.52 318.48 90.27 320.09 86.15 319.48 Q 80.39 318.63 77.66 313.54 Q 76.51 311.38 76.49 305.66 Q 76.42 282.47 76.44 259.13 L 76.43 220.85 L 114.21 183.07 A 1.79 1.77 22.3 0 1 115.47 182.55 L 233.77 182.59 A 0.83 0.83 0.0 0 0 234.60 181.76 L 234.57 77.01 Q 234.60 77.01 234.62 77.01 L 310.53 76.77 Z"/>
<path fill="#00832d" d=" M 76.43 182.69 L 76.43 220.85 L 76.44 259.13 Q 52.47 259.27 28.91 259.22 Q 19.09 259.20 14.76 257.68 Q 2.62 253.44 0.00 238.88 L 0.00 182.67 L 76.43 182.69 Z"/>
</svg>

After

Width:  |  Height:  |  Size: 2.5 KiB

@@ -0,0 +1,97 @@
import type { MockProxy } from 'jest-mock-extended';
import { mock } from 'jest-mock-extended';
import { type IExecuteFunctions } from 'n8n-workflow';
import * as googleHelpers from '../../GenericFunctions';
import { googleApiRequest } from '../GenericFunctions';
jest.mock('../../GenericFunctions', () => ({
...jest.requireActual('../../GenericFunctions'),
getGoogleAccessToken: jest.fn().mockResolvedValue({ access_token: 'mock-access-token' }),
}));
describe('Test GoogleChat, googleApiRequest', () => {
let mockExecuteFunctions: MockProxy<IExecuteFunctions>;
beforeEach(() => {
mockExecuteFunctions = mock<IExecuteFunctions>();
mockExecuteFunctions.helpers = {
requestWithAuthentication: jest.fn().mockResolvedValue({}),
request: jest.fn().mockResolvedValue({}),
} as any;
});
afterEach(() => {
jest.clearAllMocks();
});
it('should call requestWithAuthentication when authentication set to OAuth2', async () => {
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('oAuth2'); // authentication
const result = await googleApiRequest.call(mockExecuteFunctions, 'POST', '/test-resource', {
text: 'test',
});
expect(result).toEqual({ success: true });
expect(mockExecuteFunctions.helpers.requestWithAuthentication).toHaveBeenCalledTimes(1);
expect(mockExecuteFunctions.helpers.requestWithAuthentication).toHaveBeenCalledWith(
'googleChatOAuth2Api',
{
body: { text: 'test' },
headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
json: true,
method: 'POST',
qs: {},
qsStringifyOptions: { arrayFormat: 'repeat' },
uri: 'https://chat.googleapis.com/test-resource',
},
);
});
it('should call request when authentication set to serviceAccount', async () => {
const mockCredentials = {
email: 'test@example.com',
privateKey: 'private-key',
};
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('serviceAccount');
mockExecuteFunctions.getCredentials.mockResolvedValueOnce(mockCredentials);
const result = await googleApiRequest.call(mockExecuteFunctions, 'GET', '/test-resource');
expect(googleHelpers.getGoogleAccessToken).toHaveBeenCalledWith(mockCredentials, 'chat');
expect(mockExecuteFunctions.helpers.request).toHaveBeenCalledWith(
expect.objectContaining({
headers: expect.objectContaining({
Authorization: 'Bearer mock-access-token',
}),
}),
);
expect(result).toEqual({ success: true });
});
it('should call request when noCredentials equals true', async () => {
const result = await googleApiRequest.call(
mockExecuteFunctions,
'GET',
'/test-resource',
{},
{},
undefined,
true,
);
expect(mockExecuteFunctions.helpers.request).toHaveBeenCalledTimes(1);
expect(mockExecuteFunctions.helpers.request).toHaveBeenCalledWith({
headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
json: true,
method: 'GET',
qs: {},
qsStringifyOptions: { arrayFormat: 'repeat' },
uri: 'https://chat.googleapis.com/test-resource',
});
expect(result).toEqual({ success: true });
});
});
@@ -0,0 +1,62 @@
import type { MockProxy } from 'jest-mock-extended';
import { mock } from 'jest-mock-extended';
import { type INode, SEND_AND_WAIT_OPERATION, type IExecuteFunctions } from 'n8n-workflow';
import * as genericFunctions from '../../GenericFunctions';
import { GoogleChat } from '../../GoogleChat.node';
jest.mock('../../GenericFunctions', () => {
const originalModule = jest.requireActual('../../GenericFunctions');
return {
...originalModule,
googleApiRequest: jest.fn(),
};
});
describe('Test GoogleChat, message => sendAndWait', () => {
let googleChat: GoogleChat;
let mockExecuteFunctions: MockProxy<IExecuteFunctions>;
beforeEach(() => {
googleChat = new GoogleChat();
mockExecuteFunctions = mock<IExecuteFunctions>();
});
afterEach(() => {
jest.clearAllMocks();
});
it('should send message and put execution to wait', async () => {
const items = [{ json: { data: 'test' } }];
//node
mockExecuteFunctions.getInputData.mockReturnValue(items);
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('message');
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce(SEND_AND_WAIT_OPERATION);
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('spaceID');
mockExecuteFunctions.getNode.mockReturnValue(mock<INode>());
mockExecuteFunctions.getInstanceId.mockReturnValue('instanceId');
//getSendAndWaitConfig
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('my message');
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('my subject');
mockExecuteFunctions.getSignedResumeUrl.mockReturnValue(
'http://localhost/waiting-webhook/nodeID?approved=true&signature=abc',
);
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({}); // approvalOptions
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({}); // options
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('approval');
// configureWaitTillDate
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({}); //options.limitWaitTime.values
const result = await googleChat.execute.call(mockExecuteFunctions);
expect(result).toEqual([items]);
expect(genericFunctions.googleApiRequest).toHaveBeenCalledTimes(1);
expect(mockExecuteFunctions.putExecutionToWait).toHaveBeenCalledTimes(1);
expect(genericFunctions.googleApiRequest).toHaveBeenCalledWith('POST', '/v1/spaceID/messages', {
text: 'my message\n\n\n*<http://localhost/waiting-webhook/nodeID?approved=true&signature=abc|Approve>*\n\n_This_ _message_ _was_ _sent_ _automatically_ _with_ _<https://n8n.io/?utm_source=n8n-internal&utm_medium=powered_by&utm_campaign=n8n-nodes-base.googleChat_instanceId|n8n>_',
});
});
});