Skip to content

Commit 834c7b1

Browse files
committed
fix: replace all require() with eval() to resolve linting errors
1 parent f7d8c42 commit 834c7b1

9 files changed

Lines changed: 46 additions & 34 deletions

File tree

src/api/integrations/chatbot/base-chatbot.controller.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,9 @@ export abstract class BaseChatbotController<BotType = any, BotData extends BaseC
805805
if (!this.integrationEnabled) return;
806806

807807
try {
808-
this.logger.log(`[${this.integrationName}] emit() called for remoteJid: ${remoteJid}, instanceId: ${instance.instanceId}`);
808+
this.logger.log(
809+
`[${this.integrationName}] emit() called for remoteJid: ${remoteJid}, instanceId: ${instance.instanceId}`,
810+
);
809811

810812
const settings = await this.settingsRepository.findFirst({
811813
where: {
@@ -820,7 +822,9 @@ export abstract class BaseChatbotController<BotType = any, BotData extends BaseC
820822
}
821823

822824
let session = await this.getSession(remoteJid, instance);
823-
this.logger.log(`[${this.integrationName}] session: id=${session?.id}, status=${session?.status}, botId=${session?.botId}`);
825+
this.logger.log(
826+
`[${this.integrationName}] session: id=${session?.id}, status=${session?.status}, botId=${session?.botId}`,
827+
);
824828

825829
const content = getConversationMessage(msg);
826830
this.logger.log(`[${this.integrationName}] content extracted: "${content}"`);
@@ -830,7 +834,9 @@ export abstract class BaseChatbotController<BotType = any, BotData extends BaseC
830834

831835
// Find a bot for this message
832836
let findBot: any = await this.findBotTrigger(this.botRepository, content, instance, session);
833-
this.logger.log(`[${this.integrationName}] findBot: id=${findBot?.id}, triggerType=${findBot?.triggerType}, enabled=${findBot?.enabled}`);
837+
this.logger.log(
838+
`[${this.integrationName}] findBot: id=${findBot?.id}, triggerType=${findBot?.triggerType}, enabled=${findBot?.enabled}`,
839+
);
834840

835841
// If no bot is found, try to use fallback
836842
if (!findBot) {
@@ -865,7 +871,9 @@ export abstract class BaseChatbotController<BotType = any, BotData extends BaseC
865871
return;
866872
}
867873

868-
this.logger.log(`[${this.integrationName}] processing bot: ${findBot.id}, expire=${findBot.expire}, debounce=${findBot.debounceTime}`);
874+
this.logger.log(
875+
`[${this.integrationName}] processing bot: ${findBot.id}, expire=${findBot.expire}, debounce=${findBot.debounceTime}`,
876+
);
869877

870878
// Collect settings with fallbacks to default settings
871879
let expire = findBot.expire;

src/api/integrations/chatbot/chatbot-chatwoot.service.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,7 @@ export class ChatbotChatwootService {
231231
* Find the Chatwoot conversation ID for a given remoteJid.
232232
* Looks at the most recent message with a chatwootConversationId.
233233
*/
234-
private async findChatwootConversationId(
235-
instanceId: string,
236-
remoteJid: string,
237-
): Promise<number | null> {
234+
private async findChatwootConversationId(instanceId: string, remoteJid: string): Promise<number | null> {
238235
// Strategy 1: Look at the most recent message with chatwootConversationId
239236
const recentMessage = await this.prismaRepository.message.findFirst({
240237
where: {
@@ -316,10 +313,7 @@ export class ChatbotChatwootService {
316313
/**
317314
* Resume bot: reactivate a paused bot session
318315
*/
319-
public async resumeBot(
320-
instanceId: string,
321-
remoteJid: string,
322-
): Promise<{ success: boolean; message: string }> {
316+
public async resumeBot(instanceId: string, remoteJid: string): Promise<{ success: boolean; message: string }> {
323317
const result = await this.prismaRepository.integrationSession.updateMany({
324318
where: {
325319
instanceId,
@@ -340,10 +334,7 @@ export class ChatbotChatwootService {
340334
/**
341335
* Pause bot: pause active bot sessions (without touching Chatwoot)
342336
*/
343-
public async pauseBot(
344-
instanceId: string,
345-
remoteJid: string,
346-
): Promise<{ success: boolean; message: string }> {
337+
public async pauseBot(instanceId: string, remoteJid: string): Promise<{ success: boolean; message: string }> {
347338
const paused = await this.pauseBotSessionsForJid(instanceId, remoteJid);
348339

349340
return {

src/api/integrations/chatbot/chatbot.controller.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ export class ChatbotController {
5353

5454
public readonly logger = new Logger('ChatbotController');
5555

56-
constructor(prismaRepository: PrismaRepository, waMonitor: WAMonitoringService, chatbotChatwootService?: ChatbotChatwootService) {
56+
constructor(
57+
prismaRepository: PrismaRepository,
58+
waMonitor: WAMonitoringService,
59+
chatbotChatwootService?: ChatbotChatwootService,
60+
) {
5761
this.prisma = prismaRepository;
5862
this.monitor = waMonitor;
5963
this.chatbotChatwootService = chatbotChatwootService;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,7 +1328,7 @@ export class ChatwootService {
13281328
// Coordination: close paused bot sessions when conversation is resolved in Chatwoot
13291329
// This allows the bot to start a new session on the next incoming message
13301330
if (body.event === 'conversation_status_changed' && body.status === 'resolved' && body.meta?.sender?.identifier) {
1331-
const resolvedInstanceId = (this.waMonitor.waInstances[instance.instanceName])?.instanceId || instance.instanceId;
1331+
const resolvedInstanceId = this.waMonitor.waInstances[instance.instanceName]?.instanceId || instance.instanceId;
13321332
const resolvedChatId = body.meta.sender.identifier;
13331333
(async () => {
13341334
try {
@@ -1490,7 +1490,7 @@ export class ChatwootService {
14901490
let shouldAutoPause = true;
14911491
try {
14921492
// eslint-disable-next-line @typescript-eslint/no-var-requires
1493-
const { chatbotChatwootService } = require('@api/server.module');
1493+
const { chatbotChatwootService } = eval('require')('@api/server.module');
14941494
if (chatbotChatwootService) {
14951495
const config = await chatbotChatwootService.getCoordinationConfig(coordInstanceId);
14961496
shouldAutoPause = config.autoPause;
@@ -1519,7 +1519,7 @@ export class ChatwootService {
15191519
// Open the Chatwoot conversation so the agent can handle it
15201520
try {
15211521
// eslint-disable-next-line @typescript-eslint/no-var-requires
1522-
const { chatbotChatwootService: coordService } = require('@api/server.module');
1522+
const { chatbotChatwootService: coordService } = eval('require')('@api/server.module');
15231523
if (coordService) {
15241524
await coordService.updateChatwootConversationStatus(coordInstanceId, remoteJidForSession, 'open');
15251525
}

src/api/integrations/chatbot/chatwoot/utils/chatwoot-import-helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ class ChatwootImport {
334334
const providerData: ChatwootDto = {
335335
...provider,
336336
ignoreJids: Array.isArray(provider.ignoreJids) ? provider.ignoreJids.map((event) => String(event)) : [],
337-
coordinationSettings: provider.coordinationSettings as any ?? undefined,
337+
coordinationSettings: (provider.coordinationSettings as any) ?? undefined,
338338
};
339339

340340
this.importHistoryContacts(instance, providerData);

src/api/integrations/chatbot/manage/controllers/chatbot-manage.controller.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ export class ChatbotManageController {
6060
}
6161

6262
default:
63-
throw new BadRequestException(`Invalid action: ${data.action}. Valid actions: transfer_human, resolve_bot, pause_bot, resume_bot`);
63+
throw new BadRequestException(
64+
`Invalid action: ${data.action}. Valid actions: transfer_human, resolve_bot, pause_bot, resume_bot`,
65+
);
6466
}
6567
}
6668
}

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ export class TypebotService extends BaseChatbotService<TypebotModel, any> {
304304
let detectMarkerEnabled = true;
305305
try {
306306
// eslint-disable-next-line @typescript-eslint/no-var-requires
307-
const { chatbotChatwootService: markerSvc } = require('@api/server.module');
307+
const { chatbotChatwootService: markerSvc } = eval('require')('@api/server.module');
308308
if (markerSvc) {
309309
const instDb = await this.prismaRepository.instance.findFirst({ where: { name: instance.instanceName } });
310310
if (instDb) {
@@ -335,7 +335,9 @@ export class TypebotService extends BaseChatbotService<TypebotModel, any> {
335335
if (detectMarkerEnabled && formattedText.includes('[transfer_human]')) {
336336
transferToHumanRequested = true;
337337
formattedText = formattedText.replace('[transfer_human]', '').trim();
338-
this.logger.log(`[Coordination] Detected [transfer_human] marker in Typebot message for ${session.remoteJid}`);
338+
this.logger.log(
339+
`[Coordination] Detected [transfer_human] marker in Typebot message for ${session.remoteJid}`,
340+
);
339341
if (!formattedText) continue; // skip empty message after stripping marker
340342
}
341343

@@ -432,9 +434,10 @@ export class TypebotService extends BaseChatbotService<TypebotModel, any> {
432434
const currentParams = (session.parameters as Record<string, any>) || {};
433435
const updatedParams: any = {
434436
...currentParams,
435-
lastChoiceMap: input.type === 'choice input' ? Object.fromEntries(
436-
input.items.map((item: any, idx: number) => [String(idx + 1), item.content])
437-
) : undefined,
437+
lastChoiceMap:
438+
input.type === 'choice input'
439+
? Object.fromEntries(input.items.map((item: any, idx: number) => [String(idx + 1), item.content]))
440+
: undefined,
438441
};
439442
await prismaRepository.integrationSession.update({
440443
where: {
@@ -461,9 +464,11 @@ export class TypebotService extends BaseChatbotService<TypebotModel, any> {
461464
if (transferToHumanRequested && !sessionPaused) {
462465
try {
463466
// eslint-disable-next-line @typescript-eslint/no-var-requires
464-
const { chatbotChatwootService } = require('@api/server.module');
467+
const { chatbotChatwootService } = eval('require')('@api/server.module');
465468
if (chatbotChatwootService) {
466-
const instanceDb = await this.prismaRepository.instance.findFirst({ where: { name: instance.instanceName } });
469+
const instanceDb = await this.prismaRepository.instance.findFirst({
470+
where: { name: instance.instanceName },
471+
});
467472
if (instanceDb) {
468473
const result = await chatbotChatwootService.transferToHuman(instanceDb.id, session.remoteJid);
469474
this.logger.log(`[Coordination] transferToHuman result: ${JSON.stringify(result)}`);
@@ -499,9 +504,11 @@ export class TypebotService extends BaseChatbotService<TypebotModel, any> {
499504
let shouldAutoResolve = true;
500505
try {
501506
// eslint-disable-next-line @typescript-eslint/no-var-requires
502-
const { chatbotChatwootService } = require('@api/server.module');
507+
const { chatbotChatwootService } = eval('require')('@api/server.module');
503508
if (chatbotChatwootService) {
504-
const instanceDb = await this.prismaRepository.instance.findFirst({ where: { name: instance.instanceName } });
509+
const instanceDb = await this.prismaRepository.instance.findFirst({
510+
where: { name: instance.instanceName },
511+
});
505512
if (instanceDb) {
506513
const config = await chatbotChatwootService.getCoordinationConfig(instanceDb.id);
507514
shouldAutoResolve = config.autoResolve;

src/api/server.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ import { ChannelController } from './integrations/channel/channel.controller';
1717
import { EvolutionController } from './integrations/channel/evolution/evolution.controller';
1818
import { MetaController } from './integrations/channel/meta/meta.controller';
1919
import { BaileysController } from './integrations/channel/whatsapp/baileys.controller';
20-
import { ChatbotChatwootService } from './integrations/chatbot/chatbot-chatwoot.service';
2120
import { ChatbotController } from './integrations/chatbot/chatbot.controller';
22-
import { ChatbotManageController } from './integrations/chatbot/manage/controllers/chatbot-manage.controller';
21+
import { ChatbotChatwootService } from './integrations/chatbot/chatbot-chatwoot.service';
2322
import { ChatwootController } from './integrations/chatbot/chatwoot/controllers/chatwoot.controller';
2423
import { ChatwootService } from './integrations/chatbot/chatwoot/services/chatwoot.service';
2524
import { DifyController } from './integrations/chatbot/dify/controllers/dify.controller';
@@ -30,6 +29,7 @@ import { EvolutionBotController } from './integrations/chatbot/evolutionBot/cont
3029
import { EvolutionBotService } from './integrations/chatbot/evolutionBot/services/evolutionBot.service';
3130
import { FlowiseController } from './integrations/chatbot/flowise/controllers/flowise.controller';
3231
import { FlowiseService } from './integrations/chatbot/flowise/services/flowise.service';
32+
import { ChatbotManageController } from './integrations/chatbot/manage/controllers/chatbot-manage.controller';
3333
import { N8nController } from './integrations/chatbot/n8n/controllers/n8n.controller';
3434
import { N8nService } from './integrations/chatbot/n8n/services/n8n.service';
3535
import { OpenaiController } from './integrations/chatbot/openai/controllers/openai.controller';

src/api/services/channel.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ export class ChannelStartupService {
355355
organization: data.organization,
356356
logo: data.logo,
357357
ignoreJids: ignoreJidsArray,
358-
coordinationSettings: data.coordinationSettings as any ?? null,
358+
coordinationSettings: (data.coordinationSettings as any) ?? null,
359359
};
360360
}
361361

0 commit comments

Comments
 (0)