Browse Source

Update go-whatsapp to handle unknown ping responses

Tulir Asokan 5 years ago
parent
commit
63a1a77f26
4 changed files with 7 additions and 11 deletions
  1. 2 8
      commands.go
  2. 1 1
      go.mod
  3. 2 0
      go.sum
  4. 2 2
      provisioning.go

+ 2 - 8
commands.go

@@ -412,19 +412,13 @@ func (handler *CommandHandler) CommandPing(ce *CommandEvent) {
 		}
 	} else if ce.User.Conn == nil {
 		ce.Reply("You don't have a WhatsApp connection.")
-	} else if ok, err := ce.User.Conn.AdminTest(); err != nil {
+	} else if err := ce.User.Conn.AdminTest(); err != nil {
 		if ce.User.IsLoginInProgress() {
 			ce.Reply("Connection not OK: %v, but login in progress", err)
 		} else {
 			ce.Reply("Connection not OK: %v", err)
 		}
-	} else if !ok {
-		if ce.User.IsLoginInProgress() {
-			ce.Reply("Connection not OK, but no error received and login in progress")
-		} else {
-			ce.Reply("Connection not OK, but no error received")
-		}
-	} else {
+	}  else {
 		ce.Reply("Connection to WhatsApp OK")
 	}
 }

+ 1 - 1
go.mod

@@ -19,4 +19,4 @@ require (
 	github.com/prometheus/client_golang v1.6.0
 )
 
-replace github.com/Rhymen/go-whatsapp => github.com/tulir/go-whatsapp v0.3.0
+replace github.com/Rhymen/go-whatsapp => github.com/tulir/go-whatsapp v0.3.1

+ 2 - 0
go.sum

@@ -116,6 +116,8 @@ github.com/tulir/go-whatsapp v0.2.9 h1:hagfBU+oqFzXw3Wb4U/ugR2kOZAzJDq3RVIzyz74c
 github.com/tulir/go-whatsapp v0.2.9/go.mod h1:gyw9zGup1/Y3ZQUueZaqz3iR/WX9a2Lth4aqEbXjkok=
 github.com/tulir/go-whatsapp v0.3.0 h1:68aLiPNaWDWMnH3WMw/z2as6KsmBnCMyn+Lkk5i1v70=
 github.com/tulir/go-whatsapp v0.3.0/go.mod h1:7yGOBdWidM6gsmbAFwgkwHEIhzVrm01+6UbImpMWfTM=
+github.com/tulir/go-whatsapp v0.3.1 h1:WEiRaG1zlmS0+MHwPbURqQEy3ZqofJ9UgS+UZD1KAOQ=
+github.com/tulir/go-whatsapp v0.3.1/go.mod h1:7yGOBdWidM6gsmbAFwgkwHEIhzVrm01+6UbImpMWfTM=
 golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=

+ 2 - 2
provisioning.go

@@ -247,9 +247,9 @@ func (prov *ProvisioningAPI) Ping(w http.ResponseWriter, r *http.Request) {
 			"is_logged_in":         user.Conn.IsLoggedIn(),
 			"is_login_in_progress": user.Conn.IsLoginInProgress(),
 		}
-		ok, err := user.Conn.AdminTest()
+		err := user.Conn.AdminTest()
 		wa["ping"] = map[string]interface{}{
-			"ok":  ok,
+			"ok":  err == nil,
 			"err": err,
 		}
 	}