feat: add BaileysMessageProcessor for improved message handling and integrate rxjs for asynchronous processing

This commit is contained in:
Santosl2
2025-07-15 21:35:25 -03:00
parent 39606240da
commit 89d4d341f6
4 changed files with 72 additions and 1 deletions

View File

@@ -147,6 +147,7 @@ import sharp from 'sharp';
import { PassThrough, Readable } from 'stream';
import { v4 } from 'uuid';
import { BaileysMessageProcessor } from './baileysMessage.processor';
import { useVoiceCallsBaileys } from './voiceCalls/useVoiceCallsBaileys';
const groupMetadataCache = new CacheService(new CacheEngine(configService, 'groups').getEngine());
@@ -212,6 +213,8 @@ async function getVideoDuration(input: Buffer | string | Readable): Promise<numb
}
export class BaileysStartupService extends ChannelStartupService {
private messageProcessor = new BaileysMessageProcessor();
constructor(
public readonly configService: ConfigService,
public readonly eventEmitter: EventEmitter2,
@@ -223,6 +226,9 @@ export class BaileysStartupService extends ChannelStartupService {
) {
super(configService, eventEmitter, prismaRepository, chatwootCache);
this.instance.qrcode = { count: 0 };
this.messageProcessor.mount({
onMessageReceive: this.messageHandle['messages.upsert'].bind(this), // Bind the method to the current context
});
this.authStateProvider = new AuthStateProvider(this.providerFiles);
}
@@ -242,6 +248,7 @@ export class BaileysStartupService extends ChannelStartupService {
}
public async logoutInstance() {
this.messageProcessor.onDestroy();
await this.client?.logout('Log out instance: ' + this.instanceName);
this.client?.ws?.close();
@@ -1618,7 +1625,9 @@ export class BaileysStartupService extends ChannelStartupService {
if (events['messages.upsert']) {
const payload = events['messages.upsert'];
this.messageHandle['messages.upsert'](payload, settings);
this.messageProcessor.processMessage(payload, settings);
// this.messageHandle['messages.upsert'](payload, settings);
}
if (events['messages.update']) {