mirror of
https://github.com/tulir/mautrix-whatsapp
synced 2024-12-14 09:23:51 +01:00
Include obfuscated phone number in retry receipt metrics
This commit is contained in:
parent
6634f004ed
commit
e062ddc51a
3 changed files with 15 additions and 4 deletions
2
go.mod
2
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-20220516104204-543fb5c66590
|
||||
go.mau.fi/whatsmeow v0.0.0-20220517155948-4947ef2b038c
|
||||
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
|
||||
|
|
4
go.sum
4
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-20220516104204-543fb5c66590 h1:x0nYRxvlIuvFRPMhogUoydf2OKvFFibr2PZVU3Bt7y8=
|
||||
go.mau.fi/whatsmeow v0.0.0-20220516104204-543fb5c66590/go.mod h1:iUBgOLNaqShLrR17u0kIiRptIGFH+nbT1tRhaWBEX/c=
|
||||
go.mau.fi/whatsmeow v0.0.0-20220517155948-4947ef2b038c h1:DhU4/rx9u8eQNrOgrMUfKsjrn3fnsoIO5OyS+aw2kHI=
|
||||
go.mau.fi/whatsmeow v0.0.0-20220517155948-4947ef2b038c/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=
|
||||
|
|
13
user.go
13
user.go
|
@ -18,6 +18,9 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"crypto/hmac"
|
||||
"crypto/sha256"
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
@ -332,12 +335,19 @@ func (w *waLogger) Sub(module string) waLog.Logger { return &waLogger{l:
|
|||
|
||||
var ErrAlreadyLoggedIn = errors.New("already logged in")
|
||||
|
||||
func (user *User) obfuscateJID(jid types.JID) string {
|
||||
// Turn the first 4 bytes of HMAC-SHA256(hs_token, phone) into a number and replace the middle of the actual phone with that deterministic random number.
|
||||
randomNumber := binary.BigEndian.Uint32(hmac.New(sha256.New, []byte(user.bridge.Config.AppService.HSToken)).Sum([]byte(jid.User))[:4])
|
||||
return fmt.Sprintf("+%s-%d-%s:%d", jid.User[:1], randomNumber, jid.User[len(jid.User)-2:], jid.Device)
|
||||
}
|
||||
|
||||
func (user *User) createClient(sess *store.Device) {
|
||||
user.Client = whatsmeow.NewClient(sess, &waLogger{user.log.Sub("Client")})
|
||||
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 {
|
||||
user.Client.GetMessageForRetry = func(requester, to types.JID, id types.MessageID) *waProto.Message {
|
||||
Segment.Track(user.MXID, "WhatsApp incoming retry (message not found)", map[string]interface{}{
|
||||
"requester": user.obfuscateJID(requester),
|
||||
"messageID": id,
|
||||
})
|
||||
user.bridge.Metrics.TrackRetryReceipt(0, false)
|
||||
|
@ -345,6 +355,7 @@ func (user *User) createClient(sess *store.Device) {
|
|||
}
|
||||
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{}{
|
||||
"requester": user.obfuscateJID(receipt.Sender),
|
||||
"messageID": messageID,
|
||||
"retryCount": retryCount,
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue