forked from MirrorHub/mautrix-whatsapp
Update whatsmeow and add bridge state events for keepalive timeouts
This commit is contained in:
parent
dd2919fbdb
commit
8ff1896b18
7 changed files with 10 additions and 12 deletions
|
@ -51,7 +51,7 @@ const (
|
|||
WAUnknownLogout BridgeErrorCode = "wa-unknown-logout"
|
||||
WANotConnected BridgeErrorCode = "wa-not-connected"
|
||||
WAConnecting BridgeErrorCode = "wa-connecting"
|
||||
WAServerTimeout BridgeErrorCode = "wa-server-timeout"
|
||||
WAKeepaliveTimeout BridgeErrorCode = "wa-keepalive-timeout"
|
||||
WAPhoneOffline BridgeErrorCode = "wa-phone-offline"
|
||||
WAConnectionFailed BridgeErrorCode = "wa-connection-failed"
|
||||
)
|
||||
|
@ -62,7 +62,7 @@ var bridgeHumanErrors = map[BridgeErrorCode]string{
|
|||
WAUnknownLogout: "You were logged out for an unknown reason. Relogin to continue using the bridge.",
|
||||
WANotConnected: "You're not connected to WhatsApp",
|
||||
WAConnecting: "Reconnecting to WhatsApp...",
|
||||
WAServerTimeout: "The WhatsApp web servers are not responding. The bridge will try to reconnect.",
|
||||
WAKeepaliveTimeout: "The WhatsApp web servers are not responding. The bridge will try to reconnect.",
|
||||
WAPhoneOffline: "Your phone hasn't been seen in over 12 days. The bridge is currently connected, but will get disconnected if you don't open the app soon.",
|
||||
WAConnectionFailed: "Connecting to the WhatsApp web servers failed.",
|
||||
}
|
||||
|
|
|
@ -73,8 +73,6 @@ type Config struct {
|
|||
WhatsApp struct {
|
||||
OSName string `yaml:"os_name"`
|
||||
BrowserName string `yaml:"browser_name"`
|
||||
|
||||
DebugDecodeBeforeSend bool `yaml:"debug_decode_before_send"`
|
||||
} `yaml:"whatsapp"`
|
||||
|
||||
Bridge BridgeConfig `yaml:"bridge"`
|
||||
|
|
|
@ -69,7 +69,6 @@ func (helper *UpgradeHelper) doUpgrade() {
|
|||
|
||||
helper.Copy(Str, "whatsapp", "os_name")
|
||||
helper.Copy(Str, "whatsapp", "browser_name")
|
||||
helper.Copy(Bool, "whatsapp", "debug_decode_before_send")
|
||||
|
||||
helper.Copy(Str, "bridge", "username_template")
|
||||
helper.Copy(Str, "bridge", "displayname_template")
|
||||
|
|
|
@ -91,8 +91,6 @@ whatsapp:
|
|||
# Must be "unknown" for a generic icon or a valid browser name if you want a specific icon.
|
||||
# List of valid browser names: https://github.com/tulir/whatsmeow/blob/8b34d886d543b72e5f4699cf5b2797f68d598f78/binary/proto/def.proto#L38-L51
|
||||
browser_name: unknown
|
||||
# Decode outgoing binary XML payloads to try to make sure they're valid before sending to WhatsApp.
|
||||
debug_decode_before_send: false
|
||||
|
||||
# Bridge config
|
||||
bridge:
|
||||
|
|
2
go.mod
2
go.mod
|
@ -10,7 +10,7 @@ require (
|
|||
github.com/prometheus/client_golang v1.11.1
|
||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
|
||||
github.com/tidwall/gjson v1.14.1
|
||||
go.mau.fi/whatsmeow v0.0.0-20220510114652-699782a7676d
|
||||
go.mau.fi/whatsmeow v0.0.0-20220511110201-77436aebeef5
|
||||
golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9
|
||||
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4
|
||||
google.golang.org/protobuf v1.28.0
|
||||
|
|
4
go.sum
4
go.sum
|
@ -120,8 +120,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-20220510114652-699782a7676d h1:Q8duSiMtzGXch0f92adZ4GOdaz/DY+PkBz+pRx4nKW0=
|
||||
go.mau.fi/whatsmeow v0.0.0-20220510114652-699782a7676d/go.mod h1:iUBgOLNaqShLrR17u0kIiRptIGFH+nbT1tRhaWBEX/c=
|
||||
go.mau.fi/whatsmeow v0.0.0-20220511110201-77436aebeef5 h1:zrNeB6/DcJa+GsWuwrv8r5lDxHOS/2ROOmMJbQ5lR2I=
|
||||
go.mau.fi/whatsmeow v0.0.0-20220511110201-77436aebeef5/go.mod h1:iUBgOLNaqShLrR17u0kIiRptIGFH+nbT1tRhaWBEX/c=
|
||||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
|
|
7
user.go
7
user.go
|
@ -334,8 +334,6 @@ var ErrAlreadyLoggedIn = errors.New("already logged in")
|
|||
|
||||
func (user *User) createClient(sess *store.Device) {
|
||||
user.Client = whatsmeow.NewClient(sess, &waLogger{user.log.Sub("Client")})
|
||||
user.Client.DebugDecodeBeforeSend = user.bridge.Config.WhatsApp.DebugDecodeBeforeSend
|
||||
user.Client.OneMessageAtATime = user.bridge.Config.WhatsApp.DebugDecodeBeforeSend
|
||||
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 {
|
||||
|
@ -741,6 +739,11 @@ func (user *User) HandleEvent(event interface{}) {
|
|||
}
|
||||
case *events.AppState:
|
||||
// Ignore
|
||||
case *events.KeepAliveTimeout:
|
||||
go user.sendBridgeState(BridgeState{StateEvent: StateTransientDisconnect, Error: WAKeepaliveTimeout})
|
||||
case *events.KeepAliveRestored:
|
||||
user.log.Infof("Keepalive restored after timeouts, sending connected event")
|
||||
go user.sendBridgeState(BridgeState{StateEvent: StateConnected})
|
||||
default:
|
||||
user.log.Debugfln("Unknown type of event in HandleEvent: %T", v)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue