mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-09-07 14:49:31 -06:00
cacheGroupMetadata
This commit is contained in:
parent
8034e7f587
commit
9633412ef6
@ -55,9 +55,11 @@ import qrcode, { QRCodeToDataURLOptions } from 'qrcode';
|
|||||||
import qrcodeTerminal from 'qrcode-terminal';
|
import qrcodeTerminal from 'qrcode-terminal';
|
||||||
import sharp from 'sharp';
|
import sharp from 'sharp';
|
||||||
|
|
||||||
|
import { CacheEngine } from '../../../cache/cacheengine';
|
||||||
import {
|
import {
|
||||||
CacheConf,
|
CacheConf,
|
||||||
ConfigService,
|
ConfigService,
|
||||||
|
configService,
|
||||||
ConfigSessionPhone,
|
ConfigSessionPhone,
|
||||||
Database,
|
Database,
|
||||||
Log,
|
Log,
|
||||||
@ -130,6 +132,8 @@ import { Events, MessageSubtype, TypeMediaMessage, wa } from '../../types/wa.typ
|
|||||||
import { CacheService } from './../cache.service';
|
import { CacheService } from './../cache.service';
|
||||||
import { ChannelStartupService } from './../channel.service';
|
import { ChannelStartupService } from './../channel.service';
|
||||||
|
|
||||||
|
const groupMetadataCache = new CacheService(new CacheEngine(configService, 'groups').getEngine());
|
||||||
|
|
||||||
export class BaileysStartupService extends ChannelStartupService {
|
export class BaileysStartupService extends ChannelStartupService {
|
||||||
constructor(
|
constructor(
|
||||||
public readonly configService: ConfigService,
|
public readonly configService: ConfigService,
|
||||||
@ -190,7 +194,7 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
for (const group of groups) {
|
for (const group of groups) {
|
||||||
await this.updateGroupMetadataCache(group.id);
|
await this.updateGroupMetadataCache(group.id);
|
||||||
}
|
}
|
||||||
}, 60000);
|
}, 3600000);
|
||||||
}
|
}
|
||||||
|
|
||||||
public get connectionStatus() {
|
public get connectionStatus() {
|
||||||
@ -660,12 +664,8 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('phoneNumber', phoneNumber);
|
|
||||||
|
|
||||||
const parsedPhoneNumber = parsePhoneNumber(phoneNumber);
|
const parsedPhoneNumber = parsePhoneNumber(phoneNumber);
|
||||||
|
|
||||||
console.log('parsedPhoneNumber', parsedPhoneNumber);
|
|
||||||
|
|
||||||
if (!parsedPhoneNumber?.isValid()) {
|
if (!parsedPhoneNumber?.isValid()) {
|
||||||
this.logger.error('Phone number invalid');
|
this.logger.error('Phone number invalid');
|
||||||
return;
|
return;
|
||||||
@ -687,7 +687,6 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
try {
|
try {
|
||||||
const response = await this.client.requestRegistrationCode(registration);
|
const response = await this.client.requestRegistrationCode(registration);
|
||||||
|
|
||||||
console.log('response', response);
|
|
||||||
if (['ok', 'sent'].includes(response?.status)) {
|
if (['ok', 'sent'].includes(response?.status)) {
|
||||||
this.logger.verbose('Registration code sent successfully');
|
this.logger.verbose('Registration code sent successfully');
|
||||||
|
|
||||||
@ -701,9 +700,8 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
public async receiveMobileCode(code: string) {
|
public async receiveMobileCode(code: string) {
|
||||||
await this.client
|
await this.client
|
||||||
.register(code.replace(/["']/g, '').trim().toLowerCase())
|
.register(code.replace(/["']/g, '').trim().toLowerCase())
|
||||||
.then(async (response) => {
|
.then(async () => {
|
||||||
this.logger.verbose('Registration code received successfully');
|
this.logger.verbose('Registration code received successfully');
|
||||||
console.log(response);
|
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
this.logger.error(error);
|
this.logger.error(error);
|
||||||
@ -3199,8 +3197,7 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
private async updateGroupMetadataCache(groupJid: string) {
|
private async updateGroupMetadataCache(groupJid: string) {
|
||||||
try {
|
try {
|
||||||
const meta = await this.client.groupMetadata(groupJid);
|
const meta = await this.client.groupMetadata(groupJid);
|
||||||
console.log('updateGroupMetadataCache', groupJid);
|
await groupMetadataCache.set(groupJid, {
|
||||||
await this.baileysCache.set(`group-metadata-${groupJid}`, {
|
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
data: meta,
|
data: meta,
|
||||||
});
|
});
|
||||||
@ -3214,16 +3211,13 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
private async getGroupMetadataCache(groupJid: string) {
|
private async getGroupMetadataCache(groupJid: string) {
|
||||||
if (!isJidGroup(groupJid)) return null;
|
if (!isJidGroup(groupJid)) return null;
|
||||||
|
|
||||||
console.log('getGroupMetadataCache', groupJid);
|
if (await groupMetadataCache.has(groupJid)) {
|
||||||
if (this.baileysCache.has(`group-metadata-${groupJid}`)) {
|
const meta = await groupMetadataCache.get(groupJid);
|
||||||
console.log('has cache');
|
|
||||||
const meta = await this.baileysCache.get(`group-metadata-${groupJid}`);
|
|
||||||
|
|
||||||
if (Date.now() - meta.timestamp > 60000) {
|
if (Date.now() - meta.timestamp > 3600000) {
|
||||||
await this.updateGroupMetadataCache(groupJid);
|
await this.updateGroupMetadataCache(groupJid);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('meta.data', meta.data);
|
|
||||||
return meta.data;
|
return meta.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user