Skip to content

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

Open

Description

@Swampertian

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions