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

Not getting Last message in the findChats Endpoint

Open arnavgupta00 opened this issue 8 months ago • 0 comments

Welcome!

  • [x] Yes, I have searched for similar issues on GitHub and found none.

What did you do?

When ever i was requesting the findChats endpoint it always returned no lastMessage endpoint, below is the code snippet

curl --location 'http://localhost:8080/chat/findChats/oravox-test-arnav' \
--header 'Content-Type: application/json' \
--header 'apikey: 429683C4C977415CAAFCCE10F7D57E11' \
--data '{}'

Response:

[
    {
        "id": "cmak0b....gpr12fw",
        "remoteJid": "[email protected]",
        "pushName": "",
        "profilePicUrl": "https://pps.whatsapp.net/v/........",
        "updatedAt": "2025-05-11T19:20:54.000Z",
        "windowStart": "2025-05-11T18:48:17.069Z",
        "windowExpires": "2025-05-12T18:48:17.069Z",
        "windowActive": true
    }...
]

Now to fix this i searched the codebase and found very small bug, upon console logging i found out the "fetchChats" in Channel Services

The contact object is wrongly parsed (the keys are incorrect), the detailed screenshots are given below

HOW DID I SOLVE IT

  1. REPLACED THE CURRENT lastMessage with the below snippet
const lastMessage = contact.lastmessageid
          ? {
              id: contact.lastmessageid,
              key: contact.lastmessage_key,
              pushName: contact.lastmessagepushname,
              participant: contact.lastmessageparticipant,
              messageType: contact.lastmessagemessageyype,
              message: contact.lastmessagemessage,
              contextInfo: contact.lastmessagecontextinfo,
              source: contact.lastmessagesource,
              messageTimestamp: contact.lastmessagemessagetimestamp,
              instanceId: contact.lastmessageinstanceid,
              sessionId: contact.lastmessagesessionid,
              status: contact.lastmessagestatus,
            }
          : undefined;


What did you expect?

a object of lastMessage

What did you observe instead of what you expected?

No lastMessage

Screenshots/Videos

how it looks like on console logging

Image

how it is actually called

Image

Which version of the API are you using?

2.2.3

What is your environment?

Linux

Other environment specifications

RTX 4060, i7

If applicable, paste the log output

Image

Additional Notes

Hope this helps! I'm a big admirer of your work—thanks for all the effort you’ve put into this project.

arnavgupta00 avatar May 11 '25 20:05 arnavgupta00