Merge pull request #957 from fmedeiros95/v2.0.0

Escutar a configuração do webhook para midias recebidas
This commit is contained in:
Davidson Gomes 2024-10-09 17:03:41 -03:00 committed by GitHub
commit 7cb5d10fc9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 39 additions and 22 deletions

View File

@ -598,6 +598,7 @@ export class BaileysStartupService extends ChannelStartupService {
try {
this.loadChatwoot();
this.loadSettings();
this.loadWebhook();
this.loadProxy();
return await this.createClient(number);
@ -1152,18 +1153,20 @@ export class BaileysStartupService extends ChannelStartupService {
}
}
if (isMedia && !this.configService.get<S3>('S3').ENABLE) {
const buffer = await downloadMediaMessage(
{ key: received.key, message: received?.message },
'buffer',
{},
{
logger: P({ level: 'error' }) as any,
reuploadRequest: this.client.updateMediaMessage,
},
);
if (this.localWebhook.enabled) {
if (isMedia && this.localWebhook.webhookBase64) {
const buffer = await downloadMediaMessage(
{ key: received.key, message: received?.message },
'buffer',
{},
{
logger: P({ level: 'error' }) as any,
reuploadRequest: this.client.updateMediaMessage,
},
);
messageRaw.message.base64 = buffer ? buffer.toString('base64') : undefined;
messageRaw.message.base64 = buffer ? buffer.toString('base64') : undefined;
}
}
this.logger.log(messageRaw);
@ -2070,18 +2073,20 @@ export class BaileysStartupService extends ChannelStartupService {
}
}
if (isMedia && !this.configService.get<S3>('S3').ENABLE) {
const buffer = await downloadMediaMessage(
{ key: messageRaw.key, message: messageRaw?.message },
'buffer',
{},
{
logger: P({ level: 'error' }) as any,
reuploadRequest: this.client.updateMediaMessage,
},
);
if (this.localWebhook.enabled) {
if (isMedia && this.localWebhook.webhookBase64) {
const buffer = await downloadMediaMessage(
{ key: messageRaw.key, message: messageRaw?.message },
'buffer',
{},
{
logger: P({ level: 'error' }) as any,
reuploadRequest: this.client.updateMediaMessage,
},
);
messageRaw.message.base64 = buffer ? buffer.toString('base64') : undefined;
messageRaw.message.base64 = buffer ? buffer.toString('base64') : undefined;
}
}
this.logger.log(messageRaw);

View File

@ -34,6 +34,7 @@ export class ChannelStartupService {
public readonly localChatwoot: wa.LocalChatwoot = {};
public readonly localProxy: wa.LocalProxy = {};
public readonly localSettings: wa.LocalSettings = {};
public readonly localWebhook: wa.LocalWebHook = {};
public chatwootService = new ChatwootService(
waMonitor,
@ -124,6 +125,17 @@ export class ChannelStartupService {
return this.instance.wuid;
}
public async loadWebhook() {
const data = await this.prismaRepository.webhook.findUnique({
where: {
instanceId: this.instanceId,
},
});
this.localWebhook.enabled = data?.enabled;
this.localWebhook.webhookBase64 = data?.webhookBase64;
}
public async loadSettings() {
const data = await this.prismaRepository.setting.findUnique({
where: {