From 46ba3981c14406f0a03f1fa05841dcf85f519aa6 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Mon, 16 May 2022 13:46:32 +0300 Subject: [PATCH] Add Segment events for retry receipts and undecryptable messages --- go.mod | 2 +- go.sum | 4 ++-- portal.go | 6 ++++++ user.go | 7 ++++++- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index fbd6c8b..8e0ae40 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/prometheus/client_golang v1.12.2-0.20220514081015-5d584e2717ef github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e github.com/tidwall/gjson v1.14.1 - go.mau.fi/whatsmeow v0.0.0-20220516085410-82a500b502d9 + go.mau.fi/whatsmeow v0.0.0-20220516104204-543fb5c66590 golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9 golang.org/x/net v0.0.0-20220513224357-95641704303c google.golang.org/protobuf v1.28.0 diff --git a/go.sum b/go.sum index 9c9bb55..db48798 100644 --- a/go.sum +++ b/go.sum @@ -62,8 +62,8 @@ github.com/yuin/goldmark v1.4.12 h1:6hffw6vALvEDqJ19dOJvJKOoAOKe4NDaTqvd2sktGN0= github.com/yuin/goldmark v1.4.12/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.mau.fi/libsignal v0.0.0-20220425070825-c40c839ee6a0 h1:3IQF2bgAyibdo77hTejwuJe4jlypj9QaE4xCQuxrThM= go.mau.fi/libsignal v0.0.0-20220425070825-c40c839ee6a0/go.mod h1:kBOXTvYyDG/q1Ihgvd4J6WenGPh7wtEGvPKF6vmf5ak= -go.mau.fi/whatsmeow v0.0.0-20220516085410-82a500b502d9 h1:6PrnvfTZvcsOn5NMNSc4Ek/41wguZUNQJcBu1BzyB5Y= -go.mau.fi/whatsmeow v0.0.0-20220516085410-82a500b502d9/go.mod h1:iUBgOLNaqShLrR17u0kIiRptIGFH+nbT1tRhaWBEX/c= +go.mau.fi/whatsmeow v0.0.0-20220516104204-543fb5c66590 h1:x0nYRxvlIuvFRPMhogUoydf2OKvFFibr2PZVU3Bt7y8= +go.mau.fi/whatsmeow v0.0.0-20220516104204-543fb5c66590/go.mod h1:iUBgOLNaqShLrR17u0kIiRptIGFH+nbT1tRhaWBEX/c= golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220513210258-46612604a0f9 h1:NUzdAbFtCJSXU20AOXgeqaUwg8Ypg4MPYmL+d+rsB5c= golang.org/x/crypto v0.0.0-20220513210258-46612604a0f9/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= diff --git a/portal.go b/portal.go index bc3915a..e886849 100644 --- a/portal.go +++ b/portal.go @@ -550,6 +550,9 @@ func (portal *Portal) handleUndecryptableMessage(source *User, evt *events.Undec portal.log.Debugfln("Not handling %s (undecryptable): message is duplicate", evt.Info.ID) return } + Segment.Track(source.MXID, "WhatsApp undecryptable message", map[string]interface{}{ + "messageID": evt.Info.ID, + }) intent := portal.getMessageIntent(source, &evt.Info) if !intent.IsCustomPuppet && portal.IsPrivateChat() && evt.Info.Sender.User == portal.Key.Receiver.User { portal.log.Debugfln("Not handling %s (undecryptable): user doesn't have double puppeting enabled", evt.Info.ID) @@ -614,6 +617,9 @@ func (portal *Portal) handleMessage(source *User, evt *events.Message) { existingMsg := portal.bridge.DB.Message.GetByJID(portal.Key, msgID) if existingMsg != nil { if existingMsg.Error == database.MsgErrDecryptionFailed { + Segment.Track(source.MXID, "WhatsApp undecryptable message resolved", map[string]interface{}{ + "messageID": evt.Info.ID, + }) portal.log.Debugfln("Got decryptable version of previously undecryptable message %s (%s)", msgID, msgType) } else { portal.log.Debugfln("Not handling %s (%s): message is duplicate", msgID, msgType) diff --git a/user.go b/user.go index 51ee1d0..aaadeca 100644 --- a/user.go +++ b/user.go @@ -337,10 +337,15 @@ func (user *User) createClient(sess *store.Device) { user.Client.AddEventHandler(user.HandleEvent) user.Client.SetForceActiveDeliveryReceipts(user.bridge.Config.Bridge.ForceActiveDeliveryReceipts) user.Client.GetMessageForRetry = func(to types.JID, id types.MessageID) *waProto.Message { + Segment.Track(user.MXID, "WhatsApp incoming retry (message not found)") user.bridge.Metrics.TrackRetryReceipt(0, false) return nil } - user.Client.PreRetryCallback = func(receipt *events.Receipt, retryCount int, msg *waProto.Message) bool { + user.Client.PreRetryCallback = func(receipt *events.Receipt, messageID types.MessageID, retryCount int, msg *waProto.Message) bool { + Segment.Track(user.MXID, "WhatsApp incoming retry (accepted)", map[string]interface{}{ + "messageID": messageID, + "retryCount": retryCount, + }) user.bridge.Metrics.TrackRetryReceipt(retryCount, true) return true }