Explorar o código

Add Segment events for retry receipts and undecryptable messages

Tulir Asokan %!s(int64=3) %!d(string=hai) anos
pai
achega
46ba3981c1
Modificáronse 4 ficheiros con 15 adicións e 4 borrados
  1. 1 1
      go.mod
  2. 2 2
      go.sum
  3. 6 0
      portal.go
  4. 6 1
      user.go

+ 1 - 1
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

+ 2 - 2
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=

+ 6 - 0
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)

+ 6 - 1
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
 	}