diff --git a/client.go b/client.go index f2009fb..a54fca4 100644 --- a/client.go +++ b/client.go @@ -27,6 +27,7 @@ type whatsappClient interface { Disconnect() MarkRead([]string, time.Time, types.JID, types.JID) error SendMessage(context.Context, types.JID, string, *waProto.Message) (whatsmeow.SendResponse, error) + SendPresence(types.Presence) error } type Client struct { @@ -79,6 +80,9 @@ func (c *Client) disconnect() { } func (c Client) handler(evt interface{}) { + // #nosec + c.c.SendPresence(types.PresenceAvailable) + switch v := evt.(type) { case *events.Message: c.handleMessage(v) diff --git a/client_test.go b/client_test.go index c735100..30955b5 100644 --- a/client_test.go +++ b/client_test.go @@ -13,9 +13,10 @@ import ( ) type dummyClient struct { - err bool - read bool - msg string + err bool + read bool + msg string + presence bool } func (dummyClient) AddEventHandler(handler whatsmeow.EventHandler) uint32 { return 1 } @@ -59,6 +60,12 @@ func (c *dummyClient) SendMessage(_ context.Context, _ types.JID, _ string, msg return } +func (c *dummyClient) SendPresence(types.Presence) error { + c.presence = true + + return nil +} + func TestNew(t *testing.T) { defer func() { err := recover() @@ -113,6 +120,12 @@ func TestClient_Handle(t *testing.T) { } }) + t.Run("presence is set", func(t *testing.T) { + if !test.wc.presence { + t.Error("presence was not set") + } + }) + t.Run("correct message is sent", func(t *testing.T) { if test.expectResponse != test.wc.msg { t.Errorf("expected %q, received %q", test.expectResponse, test.wc.msg)