Merge branch 'ev2' into v2.0.0

This commit is contained in:
Stênio Aníbal
2024-08-14 17:02:40 -03:00
16 changed files with 604 additions and 414 deletions

View File

@@ -1,4 +1,11 @@
import { proto, WAPresence, WAPrivacyOnlineValue, WAPrivacyValue, WAReadReceiptsValue } from 'baileys';
import {
proto,
WAPresence,
WAPrivacyGroupAddValue,
WAPrivacyOnlineValue,
WAPrivacyValue,
WAReadReceiptsValue,
} from 'baileys';
export class OnWhatsAppDto {
constructor(
@@ -84,7 +91,7 @@ export class PrivacySettingDto {
status: WAPrivacyValue;
online: WAPrivacyOnlineValue;
last: WAPrivacyValue;
groupadd: WAPrivacyValue;
groupadd: WAPrivacyGroupAddValue;
}
export class DeleteMessage {

View File

@@ -16,4 +16,5 @@ export class ChatwootDto {
autoCreate?: boolean;
organization?: string;
logo?: string;
ignoreJids?: string[];
}

View File

@@ -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);

View File

@@ -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'),

View File

@@ -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,
};
}

View File

@@ -35,7 +35,6 @@ import {
Options,
SendAudioDto,
SendContactDto,
SendListDto,
SendLocationDto,
SendMediaDto,
SendPollDto,
@@ -1560,7 +1559,7 @@ export class BaileysStartupService extends ChannelStartupService {
if (events['messaging-history.set']) {
const payload = events['messaging-history.set'];
this.messageHandle['messaging-history.set'](payload);
this.messageHandle['messaging-history.set'](payload as any);
}
if (events['messages.upsert']) {
@@ -2617,27 +2616,8 @@ export class BaileysStartupService extends ChannelStartupService {
);
}
public async listMessage(data: SendListDto) {
return await this.sendMessageWithTyping(
data.number,
{
listMessage: {
title: data.title,
description: data?.description,
buttonText: data?.buttonText,
footerText: data?.footerText,
sections: data.sections,
listType: 2,
},
},
{
delay: data?.delay,
presence: 'composing',
quoted: data?.quoted,
mentionsEveryOne: data?.mentionsEveryOne,
mentioned: data?.mentioned,
},
);
public async listMessage() {
throw new BadRequestException('Method not available on WhatsApp Baileys');
}
public async contactMessage(data: SendContactDto) {
@@ -3443,38 +3423,36 @@ export class BaileysStartupService extends ChannelStartupService {
}
public async fetchAllGroups(getParticipants: GetParticipant) {
try {
const fetch = Object.values(await this?.client?.groupFetchAllParticipating());
let groups = [];
for (const group of fetch) {
const picture = await this.profilePicture(group.id);
const fetch = Object.values(await this?.client?.groupFetchAllParticipating());
const result = {
id: group.id,
subject: group.subject,
subjectOwner: group.subjectOwner,
subjectTime: group.subjectTime,
pictureUrl: picture.profilePictureUrl,
size: group.participants.length,
creation: group.creation,
owner: group.owner,
desc: group.desc,
descId: group.descId,
restrict: group.restrict,
announce: group.announce,
};
let groups = [];
for (const group of fetch) {
const picture = null;
// const picture = await this.profilePicture(group.id);
if (getParticipants.getParticipants == 'true') {
result['participants'] = group.participants;
}
const result = {
id: group.id,
subject: group.subject,
subjectOwner: group.subjectOwner,
subjectTime: group.subjectTime,
pictureUrl: picture?.profilePictureUrl,
size: group.participants.length,
creation: group.creation,
owner: group.owner,
desc: group.desc,
descId: group.descId,
restrict: group.restrict,
announce: group.announce,
};
groups = [...groups, result];
if (getParticipants.getParticipants == 'true') {
result['participants'] = group.participants;
}
return groups;
} catch (error) {
throw new NotFoundException('Error fetching group', error.toString());
groups = [...groups, result];
}
return groups;
}
public async inviteCode(id: GroupJid) {