[core] fix(Chatwoot): sanitize attachment base64 content in consumer … - #2202
Open
danielkv wants to merge 1 commit into
Open
[core] fix(Chatwoot): sanitize attachment base64 content in consumer …#2202danielkv wants to merge 1 commit into
danielkv wants to merge 1 commit into
Conversation
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
Fixes high Redis memory usage caused by storing full base64-encoded media attachments in BullMQ job
returnvaluefields within the Chatwoot integration consumer.Problem
When a WhatsApp media message (e.g., a 150MB PDF or video) is processed by
WAHAMessageAnyConsumer:MessageBaseHandler.handle()callsbuildChatWootMessage(), which reads the media file into a base64 string underattachments[].content.conversation.send(message),handle()returnsmessagedirectly.processJob()into Redis underbull:chatwoot.waha:<jobId>(returnvalue).REMOVE_ON_COMPLETE_AGE/COUNT).Solution
Sanitize
attachments[].contentto an empty string ('') in the object returned byhandle().conversation.send): Receives the fullmessageobject with valid base64 media content intact.filename,encoding) with emptycontent, reducing job footprint in Redis from hundreds of MBs to ~500 bytes.Changes Included
src/apps/chatwoot/consumers/waha/base.ts: UpdatedMessageBaseHandler.handle()return value to sanitizeattachments[].content.src/apps/chatwoot/consumers/waha/base.test.ts: Added unit test verifying thatconversation.send()receives the original base64 payload while the returned job result strips it.Tested
corepack yarn lintcorepack yarn buildVerification
Ran unit tests locally:
Output: