Skip to content

Conversation

@clairton
Copy link
Owner

@clairton clairton commented Feb 8, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Improved message reaction handling by ensuring reactions are properly linked to their corresponding messages before further processing and TTL/disappearing message behavior.

@coderabbitai
Copy link

coderabbitai bot commented Feb 8, 2026

📝 Walkthrough

Walkthrough

This PR extends message reaction support across the service layer. The client service now resolves reaction message keys from the data store when payload.reaction.message_id exists, while the transformer maps reaction payloads to Baileys-compatible format by extracting emoji and key data.

Changes

Cohort / File(s) Summary
Message Reaction Handling
src/services/client_baileys.ts, src/services/transformer.ts
Added support for processing message reactions: client service resolves reaction keys from data store, and transformer maps reaction payloads to Baileys format with emoji and key properties.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A reaction hops through the service layer so fine,
Keys resolved from the store, perfectly aligned,
Baileys format awaits with emoji delight,
Messages linked to their reactions—pure right! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'support reaction payload' directly and specifically describes the main change: adding support for reaction message payloads in the codebase.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/reaction

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/services/transformer.ts`:
- Around line 234-239: In the 'reaction' branch of transformer.ts (case
'reaction'), add a guard for payload.reaction.key so you don't produce a
response.react with key: undefined; explicitly check payload.reaction.key (and
payload.reaction) and either throw a clear error (e.g., "reaction target key
unresolved") or return a failed result so callers (client_baileys.ts
message-resolution flow) can surface the failure, rather than emitting { react:
{ text, key: undefined } } which Baileys will drop.
🧹 Nitpick comments (1)
src/services/client_baileys.ts (1)

508-516: Log a warning when the reaction target key is not found.

When loadKey returns null/undefined, the code silently continues, and the reaction will be sent without a valid target key. This will result in either a Baileys error or a no-op, with no indication in logs of why the reaction failed.

Suggested improvement
           if (payload?.reaction?.message_id) {
             logger.debug('Reacted message id %s', payload?.reaction?.message_id)
             const key = await this.store?.dataStore?.loadKey(payload?.reaction?.message_id)
             if (key) {
               logger.debug('Reacted message baileys id %s!', key?.id)
               payload.reaction.key = key
+            } else {
+              logger.warn('Reaction target key not found for message_id %s', payload.reaction.message_id)
             }
           }

Comment on lines +234 to +239
case 'reaction':
response.react = {
text: payload.reaction.emoji,
key: payload.reaction.key
}
break
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

No guard when payload.reaction.key is unresolved.

If the referenced message isn't found in the data store (see client_baileys.ts lines 509-516), payload.reaction.key will be undefined. This will produce { react: { text: "👍", key: undefined } }, which Baileys will likely reject or silently drop.

Consider adding a guard here or in client_baileys.ts to fail fast with a clear error when the reaction target key can't be resolved.

Example guard in transformer
     case 'reaction':
+      if (!payload.reaction?.key) {
+        throw new Error('Reaction key is required to send a reaction')
+      }
       response.react = {
         text: payload.reaction.emoji,
         key: payload.reaction.key
       }
       break
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
case 'reaction':
response.react = {
text: payload.reaction.emoji,
key: payload.reaction.key
}
break
case 'reaction':
if (!payload.reaction?.key) {
throw new Error('Reaction key is required to send a reaction')
}
response.react = {
text: payload.reaction.emoji,
key: payload.reaction.key
}
break
🤖 Prompt for AI Agents
In `@src/services/transformer.ts` around lines 234 - 239, In the 'reaction' branch
of transformer.ts (case 'reaction'), add a guard for payload.reaction.key so you
don't produce a response.react with key: undefined; explicitly check
payload.reaction.key (and payload.reaction) and either throw a clear error
(e.g., "reaction target key unresolved") or return a failed result so callers
(client_baileys.ts message-resolution flow) can surface the failure, rather than
emitting { react: { text, key: undefined } } which Baileys will drop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant