Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/services/client_baileys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,15 @@ export class ClientBaileys implements Client {
logger.debug('Quoted message %s!', JSON.stringify(quoted))
}
}

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
}
}
if (payload?.ttl) {
disappearingMessagesInChat = payload.ttl
}
Expand Down
6 changes: 6 additions & 0 deletions src/services/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,12 @@ export const toBaileysMessageContent = (payload: any, customMessageCharactersFun
case 'text':
response.text = customMessageCharactersFunction(payload.text.body)
break
case 'reaction':
response.react = {
text: payload.reaction.emoji,
key: payload.reaction.key
}
break
Comment on lines +234 to +239
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.

case 'interactive':
// Build payload according to whaileys / baileys interactive format
// If there are sections -> build a list message (title, buttonText, sections)
Expand Down