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

Open Beginner friendly
#2,796 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 4 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
postgresql, typescript
Domain
api, backend, database

Research direction

Start in src/api/services/channel.service.ts at fetchMessages, where the issue identifies the count and findMany queries as dropping the false filter. Read those query conditions and check for tests covering where.key.fromMe; done means both queries apply the filter when its value is false, and the endpoint returns only received messages.

Written by the indexing model from the issue text.

Description

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.

Dominant language
TypeScript
Stars
10.2k
Forks
7.5k
Avg merge
6d 19h
Merged PRs (30d)
4

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from evolution-foundation/evolution-api

All issues in evolution-foundation/evolution-api

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.