mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-11 04:47:29 -08:00
fix(Chat Trigger Node): Fix Allowed Origins paramter (#11011)
This commit is contained in:
parent
d2238b9eac
commit
b5f4afe12e
|
@ -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 {
|
import type {
|
||||||
IDataObject,
|
IDataObject,
|
||||||
IWebhookFunctions,
|
IWebhookFunctions,
|
||||||
|
@ -10,10 +12,8 @@ import type {
|
||||||
INodeProperties,
|
INodeProperties,
|
||||||
} from 'n8n-workflow';
|
} 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 { validateAuth } from './GenericFunctions';
|
||||||
|
import { createPage } from './templates';
|
||||||
import type { LoadPreviousSessionChatOption } from './types';
|
import type { LoadPreviousSessionChatOption } from './types';
|
||||||
|
|
||||||
const CHAT_TRIGGER_PATH_IDENTIFIER = 'chat';
|
const CHAT_TRIGGER_PATH_IDENTIFIER = 'chat';
|
||||||
|
@ -56,7 +56,6 @@ export class ChatTrigger extends Node {
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
supportsCORS: true,
|
|
||||||
maxNodes: 1,
|
maxNodes: 1,
|
||||||
inputs: `={{ (() => {
|
inputs: `={{ (() => {
|
||||||
if (!['hostedChat', 'webhook'].includes($parameter.mode)) {
|
if (!['hostedChat', 'webhook'].includes($parameter.mode)) {
|
||||||
|
@ -241,6 +240,15 @@ export class ChatTrigger extends Node {
|
||||||
placeholder: 'Add Field',
|
placeholder: 'Add Field',
|
||||||
default: {},
|
default: {},
|
||||||
options: [
|
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,
|
...allowFileUploadsOption,
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import type { Response } from 'express';
|
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 type { INode, IWebhookData, IHttpRequestMethods } from 'n8n-workflow';
|
||||||
import { Service } from 'typedi';
|
import { Service } from 'typedi';
|
||||||
|
|
||||||
|
@ -47,12 +47,18 @@ export class LiveWebhooks implements IWebhookManager {
|
||||||
select: ['nodes'],
|
select: ['nodes'],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const isChatWebhookNode = (type: string, webhookId?: string) =>
|
||||||
|
type === CHAT_TRIGGER_NODE_TYPE && `${webhookId}/chat` === path;
|
||||||
|
|
||||||
const nodes = workflowData?.nodes;
|
const nodes = workflowData?.nodes;
|
||||||
const webhookNode = nodes?.find(
|
const webhookNode = nodes?.find(
|
||||||
({ type, parameters, typeVersion }) =>
|
({ type, parameters, typeVersion, webhookId }) =>
|
||||||
parameters?.path === path &&
|
(parameters?.path === path &&
|
||||||
(parameters?.httpMethod ?? 'GET') === httpMethod &&
|
(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;
|
return webhookNode?.parameters?.options as WebhookAccessControlOptions;
|
||||||
}
|
}
|
||||||
|
|
|
@ -259,7 +259,7 @@ const commonPollingParameters: INodeProperties[] = [
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const commonCORSParameters: INodeProperties[] = [
|
export const commonCORSParameters: INodeProperties[] = [
|
||||||
{
|
{
|
||||||
displayName: 'Allowed Origins (CORS)',
|
displayName: 'Allowed Origins (CORS)',
|
||||||
name: 'allowedOrigins',
|
name: 'allowedOrigins',
|
||||||
|
|
Loading…
Reference in a new issue