devlikeapro / waha

WAHA - WhatsApp HTTP API (REST API) that you can configure in a click!
https://waha.devlike.pro/
Apache License 2.0
813 stars 248 forks source link

[BUG][WEBJS] - payload._data.self missing in Webhook body #304

Closed KKshitiz closed 1 month ago

KKshitiz commented 2 months ago

Describe the bug

The message.any event doesn't contain the payload._data.self field which was there earlier

Version

{
  "version":"2024.4.3",
  "engine":"WEBJS",
  "tier":"PLUS",
  "browser":"/usr/bin/google-chrome-stable"
 }

To Reproduce Steps to reproduce the behavior:

  1. Scan the QR code and log in
  2. Send a message from the host device (where WhatsApp app is installed)
  3. Check the payload._data for self field in the message.any event body

Expected behavior

The payload should contain the _data.self field as described in your docs Message payload

patron:ADVANCED

KKshitiz commented 2 months ago

Hi @allburov, any updates on this? It's been a week 😃

patron:ADVANCED

allburov commented 2 months ago

Check the payload._data for self field

What was exactly in that field?

patron:PRO

allburov commented 2 months ago
 "self": "in",

I see, what did you use it for? We've never used that field :D

patron:PRO

allburov commented 2 months ago

I see, there were two possible values - in and out , and it showed the direction of message.any, right?

You can use fromMe for that -

fromMe == true // out
fromMe == false // in

patron:PRO

KKshitiz commented 2 months ago

Actually, no. Basically, the webhook events for all the sent messages are triggered, even if they are from the host device or any of the linked devices.

This field used to indicate whether the message was sent from the current device which is logged in (WAHA application in this case) and not from any other device.

I used this for integration with our custom messaging systems.

Any idea why the field was removed or if there's an alternative to this?

patron:ADVANCED

allburov commented 2 months ago

I'm looking at this, weird one.

The fix from app side is to remember which messages you've sent from the session in your database here, kinda reimplementing self logic in application code using database

patron:PRO

allburov commented 2 months ago

Yep, looks like whatsapp itself don't accept that and implementing it on app side is the only way to solve it :(

The extra options https://github.com/devlikeapro/whatsapp-http-api/issues/272 (I thought we could add self: out or another attribute there on out messages from the library to detect them later) doesn't' work - no my_custom_key gets back in the original payload (likely WhatsApp start to cleanup the payload on WhatsApp Web before encrypting it)

patron:PRO

allburov commented 2 months ago

I've left a comment here https://github.com/devlikeapro/whatsapp-http-api/issues/272#issuecomment-2093987668 Would the extra that you can add like this solve your problem?

                "quotedMsg": {
                    "self": "out"
                },

You could check that field and if it's not present - it's likely self: in, not out message. I'm not sure about the solution stability - it can be changed in WhatsApp Web pretty easily, so we'll have to come up with something new :( The "external database" approach looks more stable, IMO

I haven't tested it with realy "reply" message yet also

patron:PRO

KKshitiz commented 2 months ago

Thanks for the reply @allburov.

As a temporary hack, I've made some changes to our messaging systems but we need a permanent solution. It'll be great if we can get the "external database" solution working or even the extra field working somehow.

patron:ADVANCED

allburov commented 1 month ago

be great if we can get the "external database" solution working

I meant YOUR application database :D So when you're using HTTP API /sendText - you save the message id in the database and then compare it when receiving message.any event. Sorry for misunderstanding. It could be added as a part in MongoDB storage tho :thinking: Do you use it?

patron:PRO

KKshitiz commented 1 month ago

@allburov Ok cool, thanks a lot for the help

patron:ADVANCED