[BUG] /chat/findMessages ignores where.key.fromMe when value is false

Aperta Adatta ai principianti
#2,796 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 4 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
postgresql, typescript
Ambito
api, backend, database

Direzione di ricerca

Inizia in src/api/services/channel.service.ts, in fetchMessages, dove l’issue segnala che le query count e findMany scartano il filtro per false. Leggi le condizioni di queste query e verifica se ci sono test che coprono where.key.fromMe; il lavoro è completato quando entrambe le query applicano il filtro se il suo valore è false e l’endpoint restituisce solo i messaggi ricevuti.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Welcome!
  • Yes, I have searched for similar issues on GitHub and found none.

Related: #1797 reported this same bug and was closed as completed on 2025-09-09, but no fix was merged. The code is unchanged on main, develop and 2.4.0-rc2.

What did you do?

Called POST /chat/findMessages/{instance} to get only received messages:

{
  "where": {
    "key": {
      "fromMe": false
    }
  }
}
What did you expect?

Only messages with key.fromMe === false are returned.

What did you observe instead of what you expected?

The filter is ignored. The response has every message of the instance (total is the full count, and records include fromMe: true). fromMe: true works.

Cause, in src/api/services/channel.service.ts (fetchMessages, both the count and the findMany query):

keyFilters?.fromMe ? { key: { path: ['fromMe'], equals: keyFilters?.fromMe } } : {},

false is falsy, so the condition becomes {} and the filter is dropped. Suggested fix:

keyFilters?.fromMe !== undefined ? { key: { path: ['fromMe'], equals: keyFilters.fromMe } } : {},

Checked on a real instance: the API returns 48569 records with fromMe: false, while the database has 39762 rows where key->>'fromMe' = 'false'.

Which version of the API are you using?

2.1.1. Same code on main (2.3.7), develop and 2.4.0-rc2 (lines 627 and 651).

What is your environment?

Docker

Other environment specifications

Image evoapicloud/evolution-api:v2.1.1, PostgreSQL 16.

Additional Notes

Workaround until fixed: query the Message table directly, or filter on the client side.

Lingua principale
TypeScript
Stelle
10.2k
Fork
7.5k
Merge medio
6g 19h
PR unite (30g)
4

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di evolution-foundation/evolution-api

Tutte le issue di evolution-foundation/evolution-api

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.