Fix/Adjust remote message key handling in WhatsApp service to include alternative JID #1955
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.
The 'messages.upsert' event handler was not correctly handling the 'remoteJid' for messages that contained an alternative identifier ('remoteJidAlt'), such as those from LIDs ('@lid'). This resulted in webhooks being sent and internal processing using a temporary JID instead of the user's real JID.
The logic to replace 'remoteJid' with 'remoteJidAlt' already existed in the 'messages.update' handler but was missing from 'messages.upsert'.
This commit introduces a check in the 'messages.upsert' flow. After the message is prepared, the code now checks if the 'remoteJid' contains '@lid' and if 'remoteJidAlt' is present. If both are true, the 'remoteJid' of the message object ('messageRaw') is updated before being sent to webhooks, logs, and the chatbot controller.
This ensures consistency in JID handling across the application, guaranteeing that the correct contact identifier is used in all processing flows.
Summary by Sourcery
Bug Fixes: