tulir / whatsmeow

Go library for the WhatsApp web multidevice API
https://go.mau.fi/whatsmeow
Mozilla Public License 2.0
2.29k stars 430 forks source link

How to detect message sent from another device but same account as whatsmeow #580

Closed SingIetOxygen closed 6 months ago

SingIetOxygen commented 6 months ago

The idea i have is to make the Whatsmeow read previous messages(to fill a form) only if from another device(same account as whatsmeow) sent a message. But i dont know if detecting when another device has sent messages is possible.

SoursopID commented 6 months ago

You can check the Device ID in incoming message event, events.Message.Info.Sender.Device. The JID would be seen like this 1234567890:<ID>@whatsapp.net.

"The Device ID always increases whenever we pair a new device. If the Device is 0, it means it is sent from the mobile app where our phone number was originally registered."

Ref : https://github.com/tulir/whatsmeow/blob/01b0547014dc47a63ddce5c1287f64c7d1dc26a4/types/jid.go#L54-L62