Skip to content

Commit 7110180

Browse files
committed
Refactor N8n integration: update schema exports, improve import order, and enhance service logic
- Added export for N8n schema in chatbot.schema.ts. - Improved import order in n8n.dto.ts and n8n.router.ts for better readability. - Refactored variable declarations in n8n.service.ts for consistency and clarity.
1 parent 38f089f commit 7110180

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

src/api/integrations/chatbot/chatbot.schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ export * from '@api/integrations/chatbot/chatwoot/validate/chatwoot.schema';
22
export * from '@api/integrations/chatbot/dify/validate/dify.schema';
33
export * from '@api/integrations/chatbot/evolutionBot/validate/evolutionBot.schema';
44
export * from '@api/integrations/chatbot/flowise/validate/flowise.schema';
5+
export * from '@api/integrations/chatbot/n8n/validate/n8n.schema';
56
export * from '@api/integrations/chatbot/openai/validate/openai.schema';
67
export * from '@api/integrations/chatbot/typebot/validate/typebot.schema';
7-
export * from '@api/integrations/chatbot/n8n/validate/n8n.schema';

src/api/integrations/chatbot/n8n/dto/n8n.dto.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TriggerType, TriggerOperator } from '@prisma/client';
1+
import { TriggerOperator, TriggerType } from '@prisma/client';
22

33
export class N8nDto {
44
enabled?: boolean;

src/api/integrations/chatbot/n8n/routes/n8n.router.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import { RouterBroker } from '@api/abstract/abstract.router';
22
import { IgnoreJidDto } from '@api/dto/chatbot.dto';
33
import { InstanceDto } from '@api/dto/instance.dto';
4-
import { N8nDto, N8nSettingDto } from '../dto/n8n.dto';
54
import { HttpStatus } from '@api/routes/index.router';
65
import { n8nController } from '@api/server.module';
76
import {
7+
instanceSchema,
88
n8nIgnoreJidSchema,
99
n8nSchema,
1010
n8nSettingSchema,
1111
n8nStatusSchema,
12-
instanceSchema,
1312
} from '@validate/validate.schema';
1413
import { RequestHandler, Router } from 'express';
1514

15+
import { N8nDto, N8nSettingDto } from '../dto/n8n.dto';
16+
1617
export class N8nRouter extends RouterBroker {
1718
constructor(...guards: RequestHandler[]) {
1819
super();

src/api/integrations/chatbot/n8n/services/n8n.service.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1+
import { InstanceDto } from '@api/dto/instance.dto';
12
import { PrismaRepository } from '@api/repository/repository.service';
3+
import { WAMonitoringService } from '@api/services/monitor.service';
24
import { Logger } from '@config/logger.config';
35
import { IntegrationSession, N8n, N8nSetting } from '@prisma/client';
46
import { sendTelemetry } from '@utils/sendTelemetry';
57
import axios from 'axios';
6-
import { InstanceDto } from '@api/dto/instance.dto';
8+
79
import { N8nDto } from '../dto/n8n.dto';
8-
import { WAMonitoringService } from '@api/services/monitor.service';
910

1011
export class N8nService {
1112
private readonly logger = new Logger('N8nService');
1213
private readonly waMonitor: WAMonitoringService;
1314

1415
constructor(
1516
waMonitor: WAMonitoringService,
16-
private readonly prismaRepository: PrismaRepository
17+
private readonly prismaRepository: PrismaRepository,
1718
) {
1819
this.waMonitor = waMonitor;
1920
}
@@ -164,7 +165,7 @@ export class N8nService {
164165
content: string,
165166
) {
166167
try {
167-
let endpoint: string = n8n.webhookUrl;
168+
const endpoint: string = n8n.webhookUrl;
168169
const payload: any = {
169170
chatInput: content,
170171
sessionId: session.sessionId,
@@ -210,7 +211,7 @@ export class N8nService {
210211
return null;
211212
};
212213
while ((match = linkRegex.exec(message)) !== null) {
213-
const [fullMatch, exclMark, altText, url] = match;
214+
const [altText, url] = match;
214215
const mediaType = getMediaType(url);
215216
const beforeText = message.slice(lastIndex, match.index);
216217
if (beforeText) {

0 commit comments

Comments
 (0)