Conversation
📝 WalkthroughWalkthroughThis PR extends message reaction support across the service layer. The client service now resolves reaction message keys from the data store when Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
loadKeyreturnsnull/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) } }
| case 'reaction': | ||
| response.react = { | ||
| text: payload.reaction.emoji, | ||
| key: payload.reaction.key | ||
| } | ||
| break |
There was a problem hiding this comment.
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.
| 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.
Summary by CodeRabbit