fix: handle undefined ephemeralMessage for iOS PTT audio messages#2552
Open
gabrielgz0 wants to merge 1 commit into
Open
fix: handle undefined ephemeralMessage for iOS PTT audio messages#2552gabrielgz0 wants to merge 1 commit into
gabrielgz0 wants to merge 1 commit into
Conversation
Contributor
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdds defensive checks and safer unwrapping for WhatsApp Baileys ephemeral audio messages to prevent crashes when File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The new
if (!msg.message)check appears redundant with the existingif (!msg?.message)guard just above it; consider consolidating to a single null/undefined check to avoid duplication. - Since you're now depending on
msg.message[subtype]?.messagespecifically, it might be safer to narrow the loop to only subtypes known to wrap a.messageto avoid silently skipping other container shapes in the future.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new `if (!msg.message)` check appears redundant with the existing `if (!msg?.message)` guard just above it; consider consolidating to a single null/undefined check to avoid duplication.
- Since you're now depending on `msg.message[subtype]?.message` specifically, it might be safer to narrow the loop to only subtypes known to wrap a `.message` to avoid silently skipping other container shapes in the future.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
…4FromMediaMessage
c69d13d to
75506ca
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix a crash in
POST /chat/getBase64FromMediaMessage/{instance}when processing iOS audio messages wrapped inephemeralMessagewithout the expected.messageproperty.Problem
When an iPhone sends an audio message, the Baileys
messages.upsertevent delivers it wrapped in anephemeralMessagecontainer. The service iterates over knownMessageSubtypevalues and unwraps them:iOS ephemeral messages can have
ephemeralMessageas a truthy object without a standard.messageproperty inside. When that happens:msg.message = undefined(.messagedoesn't exist on the subtype)msg.message[subtype]->TypeError: Cannot read properties of undefined (reading 'ephemeralMessage')This also crashes when
msg.messageitself isundefined(e.g., passing a message object without valid content).Error response
{"status":400,"error":"Bad Request","response":{"message":["TypeError: Cannot read properties of undefined (reading 'ephemeralMessage')"]}}Changes
File:
src/api/integrations/channel/whatsapp/whatsapp.baileys.service.tsmsg.message-- returns"Message not found"instead of crashingmsg.message[subtype]?.messageensures unwrapping only happens when.messageactually exists, preventingmsg.messagefrom being set toundefinedTesting
Scenarios verified
ephemeralMessagesem.message"The message is not of the media type"message: null"Message not found"messageContextInfoapenasnull(skip)"Message not found"ephemeralMessagecom audio validoaudioMessagedireto (DB format)Checks
npm run lint:checkcleantsc --noEmitcleanCloses #2550
Summary by Sourcery
Bug Fixes: