mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-26 18:38:39 -06:00
Fixes media messaging saving and uploading to S3 on WPP Biz API
This commit is contained in:
parent
df1c805ef0
commit
acb4268bc9
@ -300,12 +300,13 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
remoteJid: this.phoneNumber,
|
remoteJid: this.phoneNumber,
|
||||||
fromMe: received.messages[0].from === received.metadata.phone_number_id,
|
fromMe: received.messages[0].from === received.metadata.phone_number_id,
|
||||||
};
|
};
|
||||||
if (
|
|
||||||
|
const isMedia =
|
||||||
received?.messages[0].document ||
|
received?.messages[0].document ||
|
||||||
received?.messages[0].image ||
|
received?.messages[0].image ||
|
||||||
received?.messages[0].audio ||
|
received?.messages[0].audio ||
|
||||||
received?.messages[0].video
|
received?.messages[0].video;
|
||||||
) {
|
|
||||||
messageRaw = {
|
messageRaw = {
|
||||||
key,
|
key,
|
||||||
pushName,
|
pushName,
|
||||||
@ -317,11 +318,17 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
instanceId: this.instanceId,
|
instanceId: this.instanceId,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (this.configService.get<Database>('DATABASE').SAVE_DATA.NEW_MESSAGE) {
|
||||||
|
const msg = await this.prismaRepository.message.create({
|
||||||
|
data: messageRaw,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (isMedia) {
|
||||||
if (this.configService.get<S3>('S3').ENABLE) {
|
if (this.configService.get<S3>('S3').ENABLE) {
|
||||||
try {
|
try {
|
||||||
const message: any = received;
|
const message: any = received;
|
||||||
|
|
||||||
const id = message.messages[0][message.messages[0].type].id;
|
const id = messageRaw.message[messageRaw.messageType].id;
|
||||||
let urlServer = this.configService.get<WaBusiness>('WA_BUSINESS').URL;
|
let urlServer = this.configService.get<WaBusiness>('WA_BUSINESS').URL;
|
||||||
const version = this.configService.get<WaBusiness>('WA_BUSINESS').VERSION;
|
const version = this.configService.get<WaBusiness>('WA_BUSINESS').VERSION;
|
||||||
urlServer = `${urlServer}/${version}/${id}`;
|
urlServer = `${urlServer}/${version}/${id}`;
|
||||||
@ -338,7 +345,7 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
? 'audio'
|
? 'audio'
|
||||||
: 'video';
|
: 'video';
|
||||||
|
|
||||||
const mimetype = result.headers['content-type'];
|
const mimetype = result.data.mime_type;
|
||||||
|
|
||||||
const contentDisposition = result.headers['content-disposition'];
|
const contentDisposition = result.headers['content-disposition'];
|
||||||
let fileName = `${message.messages[0].id}.${mimetype.split('/')[1]}`;
|
let fileName = `${message.messages[0].id}.${mimetype.split('/')[1]}`;
|
||||||
@ -359,17 +366,17 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
|
|
||||||
await this.prismaRepository.media.create({
|
await this.prismaRepository.media.create({
|
||||||
data: {
|
data: {
|
||||||
messageId: received.messages[0].id,
|
messageId: msg.id,
|
||||||
instanceId: this.instanceId,
|
instanceId: this.instanceId,
|
||||||
type: mediaType,
|
type: mediaType,
|
||||||
fileName: fullName,
|
fileName: fullName,
|
||||||
mimetype,
|
mimetype
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const mediaUrl = await s3Service.getObjectUrl(fullName);
|
const mediaUrl = await s3Service.getObjectUrl(fullName);
|
||||||
|
|
||||||
messageRaw.message.mediaUrl = mediaUrl;
|
messageRaw.message.mediaUrl = mediaUrl;
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error(['Error on upload file to minio', error?.message, error?.stack]);
|
this.logger.error(['Error on upload file to minio', error?.message, error?.stack]);
|
||||||
}
|
}
|
||||||
@ -378,6 +385,7 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
|
|
||||||
messageRaw.message.base64 = buffer.toString('base64');
|
messageRaw.message.base64 = buffer.toString('base64');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else if (received?.messages[0].interactive) {
|
} else if (received?.messages[0].interactive) {
|
||||||
messageRaw = {
|
messageRaw = {
|
||||||
key,
|
key,
|
||||||
|
Loading…
Reference in New Issue
Block a user