evolution-api icon indicating copy to clipboard operation
evolution-api copied to clipboard

fix: unify remoteJid filtering using OR with remoteJidAlt

Open rodps opened this issue 2 weeks ago • 1 comments

📋 Description

Quando sincronizamos o nosso whatsapp com o Evolution, as mensagens ficam salvas com o seguinte formato da propriedade 'key':

{ "id": "AC5D7F832B92FA9393B492D9F9B88C20", "fromMe": true, "remoteJid": "[email protected]" }

porém, quando recebemos novas mensagens nos eventos upsert, as mensagens salvas ficam com o seguinte formato:

{ "id": "AC5D7F832B92FA9393B492D9F9B88C20", "fromMe": true, "remoteJid": "267628186730669@lid", "participant": "", "remoteJidAlt": "[email protected]", "addressingMode": "lid" }

Como é possível observar, o remoteJid é salvo com o endereçamento LID e o JID fica na propriedade remoteJidAlt

A alteração proposta pretende corrigir o filtro de busca de mensagens para considerar tanto o remoteJid quando o remoteJidAlt dentro da cláusula OR da função fetchMessages. Atualmente a busca só funciona filtrando por remoteJid ou remoteJidAlt, e não os dois ao mesmo tempo. Por exemplo, se eu quiser filtrar pela requisição abaixo eu não consigo:

{ "where": { "key": { "remoteJid": "[email protected]" "remoteJidAlt": "[email protected]" } } }

Isso busca somente as mensagens com o remoteJid indicado, e não com o remoteJidAlt também.

O objetivo da modificação seria atribuir uma condição OR das duas propriedades: se existir remoteJid OU remoteJidAlt com o valor especificado.

🔗 Related Issue

Closes #(issue_number)

🧪 Type of Change

  • [X] 🐛 Bug fix (non-breaking change which fixes an issue)
  • [ ] ✨ New feature (non-breaking change which adds functionality)
  • [ ] 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [ ] 📚 Documentation update
  • [ ] 🔧 Refactoring (no functional changes)
  • [ ] ⚡ Performance improvement
  • [ ] 🧹 Code cleanup
  • [ ] 🔒 Security fix

🧪 Testing

  • [X] Manual testing completed
  • [X] Functionality verified in development environment
  • [X] No breaking changes introduced
  • [ ] Tested with different connection types (if applicable)

📸 Screenshots (if applicable)

✅ Checklist

  • [X] My code follows the project's style guidelines
  • [X] I have performed a self-review of my code
  • [ ] I have commented my code, particularly in hard-to-understand areas
  • [ ] I have made corresponding changes to the documentation
  • [X] My changes generate no new warnings
  • [ X I have manually tested my changes thoroughly
  • [X] I have verified the changes work with different scenarios
  • [ ] Any dependent changes have been merged and published

📝 Additional Notes

Summary by Sourcery

Bug Fixes:

  • Fix message queries that failed to return results when filtering simultaneously by remoteJid and remoteJidAlt by consolidating these conditions into one OR clause.

rodps avatar Nov 23 '25 22:11 rodps