Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/api/integrations/chatbot/base-chatbot.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,12 @@ export abstract class BaseChatbotController<BotType = any, BotData extends BaseC
return;
}

// Skip if session exists and status is paused
if (session && session.status === 'paused') {
this.logger.warn(`Session for ${remoteJid} is paused, skipping message processing`);
return;
}

// Merged settings
const mergedSettings = {
...settings,
Expand Down
4 changes: 2 additions & 2 deletions src/api/integrations/chatbot/chatbot.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,13 @@ export class ChatbotController {
instance: InstanceDto,
session?: IntegrationSession,
) {
let findBot: null;
let findBot: any = null;

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

if (!findBot) {
return;
return null;
}
} else {
findBot = await botRepository.findFirst({
Expand Down
16 changes: 11 additions & 5 deletions src/utils/findBotByTrigger.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import { advancedOperatorsSearch } from './advancedOperatorsSearch';

export const findBotByTrigger = async (botRepository: any, content: string, instanceId: string) => {
// Check for triggerType 'all'
const findTriggerAll = await botRepository.findFirst({
// Check for triggerType 'all' or 'none' (both should match any message)
const findTriggerAllOrNone = await botRepository.findFirst({
where: {
enabled: true,
triggerType: 'all',
triggerType: {
in: ['all', 'none'],
},
instanceId: instanceId,
},
});

if (findTriggerAll) return findTriggerAll;
if (findTriggerAllOrNone) {
return findTriggerAllOrNone;
}

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

if (findTriggerEquals) return findTriggerEquals;
if (findTriggerEquals) {
return findTriggerEquals;
}

// Check for regex match
const findRegex = await botRepository.findMany({
Expand Down