mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-20 02:06:43 -06:00
fix: adjustin cloud api send audio and video
This commit is contained in:
parent
427c994993
commit
5998fcf940
@ -800,6 +800,7 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
}
|
}
|
||||||
if (message['media']) {
|
if (message['media']) {
|
||||||
const isImage = message['mimetype']?.startsWith('image/');
|
const isImage = message['mimetype']?.startsWith('image/');
|
||||||
|
const isVideo = message['mimetype']?.startsWith('video/');
|
||||||
|
|
||||||
content = {
|
content = {
|
||||||
messaging_product: 'whatsapp',
|
messaging_product: 'whatsapp',
|
||||||
@ -809,7 +810,7 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
[message['mediaType']]: {
|
[message['mediaType']]: {
|
||||||
[message['type']]: message['id'],
|
[message['type']]: message['id'],
|
||||||
preview_url: linkPreview,
|
preview_url: linkPreview,
|
||||||
...(message['fileName'] && !isImage && { filename: message['fileName'] }),
|
...(message['fileName'] && !isImage && !isVideo && { filename: message['fileName'] }),
|
||||||
caption: message['caption'],
|
caption: message['caption'],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -977,8 +978,9 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
|
|
||||||
private async getIdMedia(mediaMessage: any) {
|
private async getIdMedia(mediaMessage: any) {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
|
const media = mediaMessage.media || mediaMessage.audio;
|
||||||
|
|
||||||
const fileStream = createReadStream(mediaMessage.media);
|
const fileStream = createReadStream(media);
|
||||||
|
|
||||||
formData.append('file', fileStream, { filename: 'media', contentType: mediaMessage.mimetype });
|
formData.append('file', fileStream, { filename: 'media', contentType: mediaMessage.mimetype });
|
||||||
formData.append('typeFile', mediaMessage.mimetype);
|
formData.append('typeFile', mediaMessage.mimetype);
|
||||||
@ -1079,7 +1081,7 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
const prepareMedia: any = {
|
const prepareMedia: any = {
|
||||||
fileName: `${hash}.mp3`,
|
fileName: `${hash}.mp3`,
|
||||||
mediaType: 'audio',
|
mediaType: 'audio',
|
||||||
media: audio,
|
audio,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (isURL(audio)) {
|
if (isURL(audio)) {
|
||||||
@ -1101,15 +1103,7 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
public async audioWhatsapp(data: SendAudioDto, file?: any, isIntegration = false) {
|
public async audioWhatsapp(data: SendAudioDto, file?: any, isIntegration = false) {
|
||||||
const mediaData: SendAudioDto = { ...data };
|
const mediaData: SendAudioDto = { ...data };
|
||||||
|
|
||||||
if (file?.buffer) {
|
if (file) mediaData.audio = file.buffer.toString('base64');
|
||||||
mediaData.audio = file.buffer.toString('base64');
|
|
||||||
} else if (isURL(mediaData.audio)) {
|
|
||||||
// DO NOTHING
|
|
||||||
// mediaData.audio = mediaData.audio;
|
|
||||||
} else {
|
|
||||||
console.error('El archivo no tiene buffer o file es undefined');
|
|
||||||
throw new Error('File or buffer is undefined');
|
|
||||||
}
|
|
||||||
|
|
||||||
const message = await this.processAudio(mediaData.audio, data.number);
|
const message = await this.processAudio(mediaData.audio, data.number);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user