From c7aa4ff3383d9c5e461f80a832cfb36bb0a2bd35 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Thu, 9 Dec 2021 12:27:31 +0200 Subject: [PATCH] Update whatsmeow --- commands.go | 14 ++++++++------ go.mod | 2 +- go.sum | 4 ++-- provisioning.go | 17 +++++++++++------ 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/commands.go b/commands.go index f87191f..8d996cf 100644 --- a/commands.go +++ b/commands.go @@ -509,17 +509,19 @@ func (handler *CommandHandler) CommandLogin(ce *CommandEvent) { var qrEventID id.EventID for item := range qrChan { - switch item { - case whatsmeow.QRChannelSuccess: + switch item.Code { + case whatsmeow.QRChannelSuccess.Code: jid := ce.User.Client.Store.ID ce.Reply("Successfully logged in as +%s (device #%d)", jid.User, jid.Device) - case whatsmeow.QRChannelTimeout: + case whatsmeow.QRChannelTimeout.Code: ce.Reply("QR code timed out. Please restart the login.") - case whatsmeow.QRChannelErrUnexpectedEvent: + case whatsmeow.QRChannelErrUnexpectedEvent.Code: ce.Reply("Failed to log in: unexpected connection event from server") - case whatsmeow.QRChannelScannedWithoutMultidevice: + case whatsmeow.QRChannelScannedWithoutMultidevice.Code: ce.Reply("Please enable the WhatsApp multidevice beta and scan the QR code again.") - default: + case "error": + ce.Reply("Failed to log in: %v", item.Error) + case "code": qrEventID = ce.User.sendQR(ce, item.Code, qrEventID) } } diff --git a/go.mod b/go.mod index 610ec9d..a924d99 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/mattn/go-sqlite3 v1.14.9 github.com/prometheus/client_golang v1.11.0 github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e - go.mau.fi/whatsmeow v0.0.0-20211207132757-b21b68de1c7f + go.mau.fi/whatsmeow v0.0.0-20211208205700-2099a06b395b golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d google.golang.org/protobuf v1.27.1 gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b diff --git a/go.sum b/go.sum index a75c766..95fe195 100644 --- a/go.sum +++ b/go.sum @@ -139,8 +139,8 @@ github.com/tidwall/sjson v1.2.3 h1:5+deguEhHSEjmuICXZ21uSSsXotWMA0orU783+Z7Cp8= github.com/tidwall/sjson v1.2.3/go.mod h1:5WdjKx3AQMvCJ4RG6/2UYT7dLrGvJUV1x4jdTAyGvZs= go.mau.fi/libsignal v0.0.0-20211109153248-a67163214910 h1:9FFhG0OmkuMau5UEaTgiUQ+7cSbtbOQ7hiWKdN8OI3I= go.mau.fi/libsignal v0.0.0-20211109153248-a67163214910/go.mod h1:AufGrvVh+00Nc07Jm4hTquh7yleZyn20tKJI2wCPAKg= -go.mau.fi/whatsmeow v0.0.0-20211207132757-b21b68de1c7f h1:hfOvmS7GU/8k7K0bq+E8ErxR0c822wLXpfOKF8003fE= -go.mau.fi/whatsmeow v0.0.0-20211207132757-b21b68de1c7f/go.mod h1:8jUjOAi3xtGubxcZgG8uSHpAdyQXBRbWAfxkctX/4y4= +go.mau.fi/whatsmeow v0.0.0-20211208205700-2099a06b395b h1:Fx3OyhOuAeaieM6cD3ejsUov4csIeTDag3xQ7X7gF1c= +go.mau.fi/whatsmeow v0.0.0-20211208205700-2099a06b395b/go.mod h1:8jUjOAi3xtGubxcZgG8uSHpAdyQXBRbWAfxkctX/4y4= golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= 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= diff --git a/provisioning.go b/provisioning.go index 9bb9f66..24566f3 100644 --- a/provisioning.go +++ b/provisioning.go @@ -307,8 +307,8 @@ func (prov *ProvisioningAPI) Login(w http.ResponseWriter, r *http.Request) { for { select { case evt := <-qrChan: - switch evt { - case whatsmeow.QRChannelSuccess: + switch evt.Code { + case whatsmeow.QRChannelSuccess.Code: jid := user.Client.Store.ID user.log.Debugln("Successful login as", jid, "via provisioning API") _ = c.WriteJSON(map[string]interface{}{ @@ -316,25 +316,30 @@ func (prov *ProvisioningAPI) Login(w http.ResponseWriter, r *http.Request) { "jid": jid, "phone": fmt.Sprintf("+%s", jid.User), }) - case whatsmeow.QRChannelTimeout: + case whatsmeow.QRChannelTimeout.Code: user.log.Debugln("Login via provisioning API timed out") _ = c.WriteJSON(Error{ Error: "QR code scan timed out. Please try again.", ErrCode: "login timed out", }) - case whatsmeow.QRChannelErrUnexpectedEvent: + case whatsmeow.QRChannelErrUnexpectedEvent.Code: user.log.Debugln("Login via provisioning API failed due to unexpected event") _ = c.WriteJSON(Error{ Error: "Got unexpected event while waiting for QRs, perhaps you're already logged in?", ErrCode: "unexpected event", }) - case whatsmeow.QRChannelScannedWithoutMultidevice: + case whatsmeow.QRChannelScannedWithoutMultidevice.Code: _ = c.WriteJSON(Error{ Error: "Please enable the WhatsApp multidevice beta and scan the QR code again.", ErrCode: "multidevice not enabled", }) continue - default: + case "error": + _ = c.WriteJSON(Error{ + Error: "Fatal error while logging in", + ErrCode: "fatal error", + }) + case "code": _ = c.WriteJSON(map[string]interface{}{ "code": evt.Code, "timeout": int(evt.Timeout.Seconds()),