mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-25 18:08:40 -06:00
LN6qDBu9 - add message to contact database
This commit is contained in:
parent
8410d179cc
commit
e7c803fdd1
@ -8,6 +8,7 @@ export class ContactRaw {
|
|||||||
id?: string;
|
id?: string;
|
||||||
profilePictureUrl?: string;
|
profilePictureUrl?: string;
|
||||||
owner: string;
|
owner: string;
|
||||||
|
lastMessage?: object;
|
||||||
}
|
}
|
||||||
|
|
||||||
type ContactRawBoolean<T> = {
|
type ContactRawBoolean<T> = {
|
||||||
@ -21,6 +22,7 @@ const contactSchema = new Schema<ContactRaw>({
|
|||||||
id: { type: String, required: true, minlength: 1 },
|
id: { type: String, required: true, minlength: 1 },
|
||||||
profilePictureUrl: { type: String, minlength: 1 },
|
profilePictureUrl: { type: String, minlength: 1 },
|
||||||
owner: { type: String, required: true, minlength: 1 },
|
owner: { type: String, required: true, minlength: 1 },
|
||||||
|
lastMessage: { type: Object },
|
||||||
});
|
});
|
||||||
|
|
||||||
export const ContactModel = dbserver?.model(ContactRaw.name, contactSchema, 'contacts');
|
export const ContactModel = dbserver?.model(ContactRaw.name, contactSchema, 'contacts');
|
||||||
|
@ -143,7 +143,7 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
public readonly cache: CacheService,
|
public readonly cache: CacheService,
|
||||||
public readonly chatwootCache: CacheService,
|
public readonly chatwootCache: CacheService,
|
||||||
public readonly baileysCache: CacheService,
|
public readonly baileysCache: CacheService,
|
||||||
private readonly providerFiles: ProviderFiles,
|
private readonly providerFiles: ProviderFiles
|
||||||
) {
|
) {
|
||||||
super(configService, eventEmitter, repository, chatwootCache);
|
super(configService, eventEmitter, repository, chatwootCache);
|
||||||
this.logger.verbose('BaileysStartupService initialized');
|
this.logger.verbose('BaileysStartupService initialized');
|
||||||
@ -1100,7 +1100,9 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
received.messageTimestamp = received.messageTimestamp?.toNumber();
|
received.messageTimestamp = received.messageTimestamp?.toNumber();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settings?.groups_ignore && received.key.remoteJid.includes('@g.us')) {
|
const isGroup = received.key.remoteJid.includes('@g.us')
|
||||||
|
|
||||||
|
if (settings?.groups_ignore && isGroup) {
|
||||||
this.logger.verbose('group ignored');
|
this.logger.verbose('group ignored');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1225,11 +1227,23 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
where: { owner: this.instance.name, id: received.key.remoteJid },
|
where: { owner: this.instance.name, id: received.key.remoteJid },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const sender = received.pushName
|
||||||
|
|
||||||
|
if (isGroup){
|
||||||
|
const group = await waMonitor.waInstances[this.instance.name].findGroup({ groupJid: received.key.remoteJid }, 'inner')
|
||||||
|
received.pushName = group ? group.subject : null
|
||||||
|
}
|
||||||
|
|
||||||
|
const lastMessage = {...messageRaw, sender: sender}
|
||||||
|
if ('base64' in lastMessage.message)
|
||||||
|
delete lastMessage.message.base64
|
||||||
|
|
||||||
const contactRaw: ContactRaw = {
|
const contactRaw: ContactRaw = {
|
||||||
id: received.key.remoteJid,
|
id: received.key.remoteJid,
|
||||||
pushName: received.pushName,
|
pushName: received.pushName,
|
||||||
profilePictureUrl: (await this.profilePicture(received.key.remoteJid)).profilePictureUrl,
|
profilePictureUrl: (await this.profilePicture(received.key.remoteJid)).profilePictureUrl,
|
||||||
owner: this.instance.name,
|
owner: this.instance.name,
|
||||||
|
lastMessage: lastMessage
|
||||||
};
|
};
|
||||||
|
|
||||||
if (contactRaw.id === 'status@broadcast') {
|
if (contactRaw.id === 'status@broadcast') {
|
||||||
@ -1241,13 +1255,14 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
this.logger.verbose('Contact found in database');
|
this.logger.verbose('Contact found in database');
|
||||||
const contactRaw: ContactRaw = {
|
const contactRaw: ContactRaw = {
|
||||||
id: received.key.remoteJid,
|
id: received.key.remoteJid,
|
||||||
pushName: contact[0].pushName || received.pushName,
|
pushName: isGroup ? received.pushName : contact[0].pushName || received.pushName,
|
||||||
profilePictureUrl: (await this.profilePicture(received.key.remoteJid)).profilePictureUrl,
|
profilePictureUrl: (await this.profilePicture(received.key.remoteJid)).profilePictureUrl,
|
||||||
owner: this.instance.name,
|
owner: this.instance.name,
|
||||||
|
lastMessage: lastMessage
|
||||||
};
|
};
|
||||||
|
|
||||||
if (received?.key?.fromMe === true){
|
if (received?.key?.fromMe === true && !isGroup){
|
||||||
contactRaw.pushName = null
|
contactRaw.pushName = contact[0].pushName
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger.verbose('Sending data to webhook in event CONTACTS_UPDATE');
|
this.logger.verbose('Sending data to webhook in event CONTACTS_UPDATE');
|
||||||
@ -1263,7 +1278,7 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
|
|
||||||
this.logger.verbose('Updating contact in database');
|
this.logger.verbose('Updating contact in database');
|
||||||
|
|
||||||
if(contactRaw.pushName)
|
//if(contactRaw.pushName)
|
||||||
await this.repository.contact.update([contactRaw], this.instance.name, database.SAVE_DATA.CONTACTS);
|
await this.repository.contact.update([contactRaw], this.instance.name, database.SAVE_DATA.CONTACTS);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1275,7 +1290,7 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
|
|
||||||
this.logger.verbose('Inserting contact in database');
|
this.logger.verbose('Inserting contact in database');
|
||||||
|
|
||||||
if (received?.key?.fromMe === true)
|
if (received?.key?.fromMe === true && !isGroup)
|
||||||
contactRaw.pushName = null;
|
contactRaw.pushName = null;
|
||||||
|
|
||||||
this.repository.contact.insert([contactRaw], this.instance.name, database.SAVE_DATA.CONTACTS);
|
this.repository.contact.insert([contactRaw], this.instance.name, database.SAVE_DATA.CONTACTS);
|
||||||
|
Loading…
Reference in New Issue
Block a user