Skip to content

Commit 07cccb7

Browse files
Merge pull request #1599 from splusoficial/develop
fix: ajuste na validacao dos bots e pausar sessao
2 parents 5f0862a + 029d68e commit 07cccb7

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,12 @@ export abstract class BaseChatbotController<BotType = any, BotData extends BaseC
880880
return;
881881
}
882882

883+
// Skip if session exists and status is paused
884+
if (session && session.status === 'paused') {
885+
this.logger.warn(`Session for ${remoteJid} is paused, skipping message processing`);
886+
return;
887+
}
888+
883889
// Merged settings
884890
const mergedSettings = {
885891
...settings,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,13 @@ export class ChatbotController {
194194
instance: InstanceDto,
195195
session?: IntegrationSession,
196196
) {
197-
let findBot: null;
197+
let findBot: any = null;
198198

199199
if (!session) {
200200
findBot = await findBotByTrigger(botRepository, content, instance.instanceId);
201201

202202
if (!findBot) {
203-
return;
203+
return null;
204204
}
205205
} else {
206206
findBot = await botRepository.findFirst({

src/utils/findBotByTrigger.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
import { advancedOperatorsSearch } from './advancedOperatorsSearch';
22

33
export const findBotByTrigger = async (botRepository: any, content: string, instanceId: string) => {
4-
// Check for triggerType 'all'
5-
const findTriggerAll = await botRepository.findFirst({
4+
// Check for triggerType 'all' or 'none' (both should match any message)
5+
const findTriggerAllOrNone = await botRepository.findFirst({
66
where: {
77
enabled: true,
8-
triggerType: 'all',
8+
triggerType: {
9+
in: ['all', 'none'],
10+
},
911
instanceId: instanceId,
1012
},
1113
});
1214

13-
if (findTriggerAll) return findTriggerAll;
15+
if (findTriggerAllOrNone) {
16+
return findTriggerAllOrNone;
17+
}
1418

1519
const findTriggerAdvanced = await botRepository.findMany({
1620
where: {
@@ -36,7 +40,9 @@ export const findBotByTrigger = async (botRepository: any, content: string, inst
3640
},
3741
});
3842

39-
if (findTriggerEquals) return findTriggerEquals;
43+
if (findTriggerEquals) {
44+
return findTriggerEquals;
45+
}
4046

4147
// Check for regex match
4248
const findRegex = await botRepository.findMany({

0 commit comments

Comments
 (0)