-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Fix: Support media extraction from templateMessage in getBase64FromMediaMessage #1715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fix: Support media extraction from templateMessage in getBase64FromMediaMessage #1715
Conversation
…diaMessage ### 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://..." } } } } }
Reviewer's GuideEnhance media extraction in getBase64FromMediaMessage by detecting and normalizing media embedded within templateMessage structures before falling back to the existing logic. Sequence diagram for media extraction from templateMessage in getBase64FromMediaMessagesequenceDiagram
participant Caller
participant BaileysService
participant Template
Caller->>BaileysService: getBase64FromMediaMessage(msg)
alt msg contains templateMessage
BaileysService->>Template: Access hydratedTemplate or hydratedFourRowTemplate
alt Template contains supported media type
BaileysService->>BaileysService: Extract mediaMessage and mediaType
BaileysService->>BaileysService: Normalize msg.message
else Template does not contain supported media
BaileysService->>Caller: Throw error
end
else msg does not contain templateMessage
BaileysService->>BaileysService: Fallback to existing media extraction logic
alt No supported media type found
BaileysService->>Caller: Throw error
end
end
BaileysService-->>Caller: Return base64 media or error
Class diagram for updated media extraction logic in BaileysStartupServiceclassDiagram
class BaileysStartupService {
+getBase64FromMediaMessage(msg)
}
class Message {
+templateMessage
+imageMessage
+videoMessage
+documentMessage
}
class TemplateMessage {
+hydratedTemplate
+hydratedFourRowTemplate
}
class HydratedTemplate {
+imageMessage
+videoMessage
+documentMessage
}
BaileysStartupService --> Message
Message --> TemplateMessage
TemplateMessage --> HydratedTemplate
HydratedTemplate --> Message
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @AlexisJusviack - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts:3441` </location>
<code_context>
- mediaType = type;
- break;
+ if (msg.message?.templateMessage) {
+ const template =
+ msg.message.templateMessage.hydratedTemplate || msg.message.templateMessage.hydratedFourRowTemplate;
+
</code_context>
<issue_to_address>
Potential edge case if both hydratedTemplate and hydratedFourRowTemplate are undefined.
Accessing template[type] without verifying that template is defined may cause a runtime error. Please add a check to ensure template is defined before using it.
</issue_to_address>
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
mediaType = type; | ||
break; | ||
if (msg.message?.templateMessage) { | ||
const template = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: Potential edge case if both hydratedTemplate and hydratedFourRowTemplate are undefined.
Accessing template[type] without verifying that template is defined may cause a runtime error. Please add a check to ensure template is defined before using it.
Fix: Add support for templateMessage media in getBase64FromMediaMessage
What this does
Adds support to download media from
templateMessage
structures ingetBase64FromMediaMessage
, by checking forhydratedTemplate
andhydratedFourRowTemplate
.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 correctmediaMessage
andmediaType
. Then it proceeds as usual with the download logic.Example message