Skip to content

Commit b5f4afe

Browse files
authored
fix(Chat Trigger Node): Fix Allowed Origins paramter (n8n-io#11011)
1 parent d2238b9 commit b5f4afe

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

packages/@n8n/nodes-langchain/nodes/trigger/ChatTrigger/ChatTrigger.node.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { Node, NodeConnectionType } from 'n8n-workflow';
1+
import type { BaseChatMemory } from '@langchain/community/memory/chat_memory';
2+
import { pick } from 'lodash';
3+
import { Node, NodeConnectionType, commonCORSParameters } from 'n8n-workflow';
24
import type {
35
IDataObject,
46
IWebhookFunctions,
@@ -10,10 +12,8 @@ import type {
1012
INodeProperties,
1113
} from 'n8n-workflow';
1214

13-
import { pick } from 'lodash';
14-
import type { BaseChatMemory } from '@langchain/community/memory/chat_memory';
15-
import { createPage } from './templates';
1615
import { validateAuth } from './GenericFunctions';
16+
import { createPage } from './templates';
1717
import type { LoadPreviousSessionChatOption } from './types';
1818

1919
const CHAT_TRIGGER_PATH_IDENTIFIER = 'chat';
@@ -56,7 +56,6 @@ export class ChatTrigger extends Node {
5656
],
5757
},
5858
},
59-
supportsCORS: true,
6059
maxNodes: 1,
6160
inputs: `={{ (() => {
6261
if (!['hostedChat', 'webhook'].includes($parameter.mode)) {
@@ -241,6 +240,15 @@ export class ChatTrigger extends Node {
241240
placeholder: 'Add Field',
242241
default: {},
243242
options: [
243+
// CORS parameters are only valid for when chat is used in hosted or webhook mode
244+
...commonCORSParameters.map((p) => ({
245+
...p,
246+
displayOptions: {
247+
show: {
248+
'/mode': ['hostedChat', 'webhook'],
249+
},
250+
},
251+
})),
244252
{
245253
...allowFileUploadsOption,
246254
displayOptions: {

packages/cli/src/webhooks/live-webhooks.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Response } from 'express';
2-
import { Workflow, NodeHelpers } from 'n8n-workflow';
2+
import { Workflow, NodeHelpers, CHAT_TRIGGER_NODE_TYPE } from 'n8n-workflow';
33
import type { INode, IWebhookData, IHttpRequestMethods } from 'n8n-workflow';
44
import { Service } from 'typedi';
55

@@ -47,12 +47,18 @@ export class LiveWebhooks implements IWebhookManager {
4747
select: ['nodes'],
4848
});
4949

50+
const isChatWebhookNode = (type: string, webhookId?: string) =>
51+
type === CHAT_TRIGGER_NODE_TYPE && `${webhookId}/chat` === path;
52+
5053
const nodes = workflowData?.nodes;
5154
const webhookNode = nodes?.find(
52-
({ type, parameters, typeVersion }) =>
53-
parameters?.path === path &&
54-
(parameters?.httpMethod ?? 'GET') === httpMethod &&
55-
'webhook' in this.nodeTypes.getByNameAndVersion(type, typeVersion),
55+
({ type, parameters, typeVersion, webhookId }) =>
56+
(parameters?.path === path &&
57+
(parameters?.httpMethod ?? 'GET') === httpMethod &&
58+
'webhook' in this.nodeTypes.getByNameAndVersion(type, typeVersion)) ||
59+
// Chat Trigger has doesn't have configurable path and is always using POST, so
60+
// we need to use webhookId for matching
61+
isChatWebhookNode(type, webhookId),
5662
);
5763
return webhookNode?.parameters?.options as WebhookAccessControlOptions;
5864
}

packages/workflow/src/NodeHelpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ const commonPollingParameters: INodeProperties[] = [
259259
},
260260
];
261261

262-
const commonCORSParameters: INodeProperties[] = [
262+
export const commonCORSParameters: INodeProperties[] = [
263263
{
264264
displayName: 'Allowed Origins (CORS)',
265265
name: 'allowedOrigins',

0 commit comments

Comments
 (0)