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
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 25 additions and 11 deletions

View file

@ -1,4 +1,6 @@
import { Node, NodeConnectionType } from 'n8n-workflow';
import type { BaseChatMemory } from '@langchain/community/memory/chat_memory';
import { pick } from 'lodash';
import { Node, NodeConnectionType, commonCORSParameters } from 'n8n-workflow';
import type {
IDataObject,
IWebhookFunctions,
@ -10,10 +12,8 @@ import type {
INodeProperties,
} from 'n8n-workflow';
import { pick } from 'lodash';
import type { BaseChatMemory } from '@langchain/community/memory/chat_memory';
import { createPage } from './templates';
import { validateAuth } from './GenericFunctions';
import { createPage } from './templates';
import type { LoadPreviousSessionChatOption } from './types';
const CHAT_TRIGGER_PATH_IDENTIFIER = 'chat';
@ -56,7 +56,6 @@ export class ChatTrigger extends Node {
],
},
},
supportsCORS: true,
maxNodes: 1,
inputs: `={{ (() => {
if (!['hostedChat', 'webhook'].includes($parameter.mode)) {
@ -241,6 +240,15 @@ export class ChatTrigger extends Node {
placeholder: 'Add Field',
default: {},
options: [
// CORS parameters are only valid for when chat is used in hosted or webhook mode
...commonCORSParameters.map((p) => ({
...p,
displayOptions: {
show: {
'/mode': ['hostedChat', 'webhook'],
},
},
})),
{
...allowFileUploadsOption,
displayOptions: {

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 &&
({ type, parameters, typeVersion, webhookId }) =>
(parameters?.path === path &&
(parameters?.httpMethod ?? 'GET') === httpMethod &&
'webhook' in this.nodeTypes.getByNameAndVersion(type, typeVersion),
'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;
}

View file

@ -259,7 +259,7 @@ const commonPollingParameters: INodeProperties[] = [
},
];
const commonCORSParameters: INodeProperties[] = [
export const commonCORSParameters: INodeProperties[] = [
{
displayName: 'Allowed Origins (CORS)',
name: 'allowedOrigins',