fix(Chat Trigger Node): Fix Allowed Origins paramter (#11011)

This commit is contained in:
oleg
2024-09-30 15:42:37 +02:00
committed by GitHub
parent d2238b9eac
commit b5f4afe12e
3 changed files with 25 additions and 11 deletions

View File

@@ -1,5 +1,5 @@
import type { Response } from 'express';
import { Workflow, NodeHelpers } from 'n8n-workflow';
import { Workflow, NodeHelpers, CHAT_TRIGGER_NODE_TYPE } from 'n8n-workflow';
import type { INode, IWebhookData, IHttpRequestMethods } from 'n8n-workflow';
import { Service } from 'typedi';
@@ -47,12 +47,18 @@ export class LiveWebhooks implements IWebhookManager {
select: ['nodes'],
});
const isChatWebhookNode = (type: string, webhookId?: string) =>
type === CHAT_TRIGGER_NODE_TYPE && `${webhookId}/chat` === path;
const nodes = workflowData?.nodes;
const webhookNode = nodes?.find(
({ type, parameters, typeVersion }) =>
parameters?.path === path &&
(parameters?.httpMethod ?? 'GET') === httpMethod &&
'webhook' in this.nodeTypes.getByNameAndVersion(type, typeVersion),
({ type, parameters, typeVersion, webhookId }) =>
(parameters?.path === path &&
(parameters?.httpMethod ?? 'GET') === httpMethod &&
'webhook' in this.nodeTypes.getByNameAndVersion(type, typeVersion)) ||
// Chat Trigger has doesn't have configurable path and is always using POST, so
// we need to use webhookId for matching
isChatWebhookNode(type, webhookId),
);
return webhookNode?.parameters?.options as WebhookAccessControlOptions;
}