mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-20 12:22:21 -06:00
feat: Added ignoreJids in chatwoot settings
This commit is contained in:
@@ -16,4 +16,5 @@ export class ChatwootDto {
|
||||
autoCreate?: boolean;
|
||||
organization?: string;
|
||||
logo?: string;
|
||||
ignoreJids?: string[];
|
||||
}
|
||||
|
||||
@@ -1738,6 +1738,36 @@ export class ChatwootService {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (this.provider?.ignoreJids && this.provider?.ignoreJids.length > 0) {
|
||||
const ignoreJids: any = this.provider?.ignoreJids;
|
||||
|
||||
let ignoreGroups = false;
|
||||
let ignoreContacts = false;
|
||||
|
||||
if (ignoreJids.includes('@g.us')) {
|
||||
ignoreGroups = true;
|
||||
}
|
||||
|
||||
if (ignoreJids.includes('@s.whatsapp.net')) {
|
||||
ignoreContacts = true;
|
||||
}
|
||||
|
||||
if (ignoreGroups && body?.key?.remoteJid.endsWith('@g.us')) {
|
||||
this.logger.warn('Ignoring message from group: ' + body?.key?.remoteJid);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ignoreContacts && body?.key?.remoteJid.endsWith('@s.whatsapp.net')) {
|
||||
this.logger.warn('Ignoring message from contact: ' + body?.key?.remoteJid);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ignoreJids.includes(body?.key?.remoteJid)) {
|
||||
this.logger.warn('Ignoring message from jid: ' + body?.key?.remoteJid);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (event === 'contact.is_not_in_wpp') {
|
||||
const getConversation = await this.createConversation(instance, body);
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ export const chatwootSchema: JSONSchema7 = {
|
||||
mergeBrazilContacts: { type: 'boolean', enum: [true, false] },
|
||||
importMessages: { type: 'boolean', enum: [true, false] },
|
||||
daysLimitImportMessages: { type: 'number' },
|
||||
ignoreJids: { type: 'array', items: { type: 'string' } },
|
||||
},
|
||||
required: ['enabled', 'accountId', 'token', 'url', 'signMsg', 'reopenConversation', 'conversationPending'],
|
||||
...isNotEmpty('enabled', 'accountId', 'token', 'url', 'signMsg', 'reopenConversation', 'conversationPending'),
|
||||
|
||||
@@ -345,6 +345,7 @@ export class ChannelStartupService {
|
||||
daysLimitImportMessages: data.daysLimitImportMessages,
|
||||
organization: data.organization,
|
||||
logo: data.logo,
|
||||
ignoreJids: data.ignoreJids,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -369,6 +370,9 @@ export class ChannelStartupService {
|
||||
importContacts: data.importContacts,
|
||||
importMessages: data.importMessages,
|
||||
daysLimitImportMessages: data.daysLimitImportMessages,
|
||||
organization: data.organization,
|
||||
logo: data.logo,
|
||||
ignoreJids: data.ignoreJids,
|
||||
instanceId: this.instanceId,
|
||||
},
|
||||
});
|
||||
@@ -378,7 +382,7 @@ export class ChannelStartupService {
|
||||
this.clearCacheChatwoot();
|
||||
}
|
||||
|
||||
public async findChatwoot() {
|
||||
public async findChatwoot(): Promise<ChatwootDto> {
|
||||
if (!this.configService.get<Chatwoot>('CHATWOOT').ENABLED) {
|
||||
return null;
|
||||
}
|
||||
@@ -393,6 +397,8 @@ export class ChannelStartupService {
|
||||
return null;
|
||||
}
|
||||
|
||||
const ignoreJidsArray = Array.isArray(data.ignoreJids) ? data.ignoreJids.map((event) => String(event)) : [];
|
||||
|
||||
return {
|
||||
enabled: data.enabled,
|
||||
accountId: data.accountId,
|
||||
@@ -407,6 +413,9 @@ export class ChannelStartupService {
|
||||
importContacts: data.importContacts,
|
||||
importMessages: data.importMessages,
|
||||
daysLimitImportMessages: data.daysLimitImportMessages,
|
||||
organization: data.organization,
|
||||
logo: data.logo,
|
||||
ignoreJids: ignoreJidsArray,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user