tulir / whatsmeow

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

Access client instance on eventHandler #108

Closed rvp98 closed 2 years ago

rvp98 commented 2 years ago

I read in the docs that i can be done by wrap the handler in another struct, but im sorry i still little bit confused> Can someone show me some snippet how to implementing this please

type MyClient struct { WAClient *whatsmeow.Client eventHandlerID uint32 }

func (mycli *MyClient) register() { mycli.eventHandlerID = mycli.WAClient.AddEventHandler(mycli.myEventHandler) }

func (mycli *MyClient) myEventHandler(evt interface{}) { // Handle event and access mycli.WAClient }

tulir commented 2 years ago

That is the implementation. Then you just create a MyClient with a whatsmeow.Client instance and call .register().