mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-11 02:49:36 -06:00
Fix: Support media extraction from templateMessage in getBase64FromMediaMessage
### Fix: Add support for templateMessage media in getBase64FromMediaMessage
#### What this does
Adds support to download media from `templateMessage` structures in `getBase64FromMediaMessage`, by checking for `hydratedTemplate` and `hydratedFourRowTemplate`.
#### Why it's needed
Currently, media inside templates (e.g. `imageMessage`, `videoMessage`, `documentMessage`) is not processed by the method, which leads to errors or media being skipped.
#### How it works
If a `templateMessage` is detected, the code looks into the inner hydrated template and assigns the correct `mediaMessage` and `mediaType`. Then it proceeds as usual with the download logic.
#### Example message
```json
{
"message": {
"templateMessage": {
"hydratedTemplate": {
"imageMessage": {
"mimetype": "image/jpeg",
"fileLength": 123456,
"url": "https://..."
}
}
}
}
}
This commit is contained in:
parent
39606240da
commit
bd35d7977c
@ -3437,6 +3437,23 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
let mediaMessage: any;
|
let mediaMessage: any;
|
||||||
let mediaType: string;
|
let mediaType: string;
|
||||||
|
|
||||||
|
if (msg.message?.templateMessage) {
|
||||||
|
const template =
|
||||||
|
msg.message.templateMessage.hydratedTemplate || msg.message.templateMessage.hydratedFourRowTemplate;
|
||||||
|
|
||||||
|
for (const type of TypeMediaMessage) {
|
||||||
|
if (template[type]) {
|
||||||
|
mediaMessage = template[type];
|
||||||
|
mediaType = type;
|
||||||
|
msg.message = { [type]: { ...template[type], url: template[type].staticUrl } };
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mediaMessage) {
|
||||||
|
throw 'Template message does not contain a supported media type';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
for (const type of TypeMediaMessage) {
|
for (const type of TypeMediaMessage) {
|
||||||
mediaMessage = msg.message[type];
|
mediaMessage = msg.message[type];
|
||||||
if (mediaMessage) {
|
if (mediaMessage) {
|
||||||
@ -3448,6 +3465,7 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
if (!mediaMessage) {
|
if (!mediaMessage) {
|
||||||
throw 'The message is not of the media type';
|
throw 'The message is not of the media type';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof mediaMessage['mediaKey'] === 'object') {
|
if (typeof mediaMessage['mediaKey'] === 'object') {
|
||||||
msg.message = JSON.parse(JSON.stringify(msg.message));
|
msg.message = JSON.parse(JSON.stringify(msg.message));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user