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 {
|
||||
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: {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -259,7 +259,7 @@ const commonPollingParameters: INodeProperties[] = [
|
|||
},
|
||||
];
|
||||
|
||||
const commonCORSParameters: INodeProperties[] = [
|
||||
export const commonCORSParameters: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Allowed Origins (CORS)',
|
||||
name: 'allowedOrigins',
|
||||
|
|
Loading…
Reference in a new issue