From 0e85916fa141cc9f107a190cbe75de3943d4f709 Mon Sep 17 00:00:00 2001 From: Muhammad Faisal Alfaruqi Date: Tue, 21 Apr 2020 10:36:04 +0700 Subject: [PATCH 1/2] Fix Set Client Web Version --- conn.go | 1 + session.go | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/conn.go b/conn.go index 26df39da..4dbd68cb 100644 --- a/conn.go +++ b/conn.go @@ -90,6 +90,7 @@ type Conn struct { longClientName string shortClientName string + clientVersion string loginSessionLock sync.RWMutex Proxy func(*http.Request) (*url.URL, error) diff --git a/session.go b/session.go index b4690d21..f026df7d 100644 --- a/session.go +++ b/session.go @@ -107,7 +107,7 @@ func CheckCurrentServerVersion() ([]int, error) { } b64ClientId := base64.StdEncoding.EncodeToString(clientId) - login := []interface{}{"admin", "init", waVersion, []string{wac.longClientName, wac.shortClientName}, b64ClientId, true} + login := []interface{}{"admin", "init", waVersion, []string{wac.longClientName, wac.shortClientName, wac.clientVersion}, b64ClientId, true} loginChan, err := wac.writeJson(login) if err != nil { return nil, fmt.Errorf("error writing login: %s", err.Error()) @@ -141,11 +141,11 @@ func CheckCurrentServerVersion() ([]int, error) { SetClientName sets the long and short client names that are sent to WhatsApp when logging in and displayed in the WhatsApp Web device list. As the values are only sent when logging in, changing them after logging in is not possible. */ -func (wac *Conn) SetClientName(long, short string) error { +func (wac *Conn) SetClientName(long, short, version string) error { if wac.session != nil && (wac.session.EncKey != nil || wac.session.MacKey != nil) { return fmt.Errorf("cannot change client name after logging in") } - wac.longClientName, wac.shortClientName = long, short + wac.longClientName, wac.shortClientName, wac.clientVersion = long, short, version return nil } @@ -213,7 +213,7 @@ func (wac *Conn) Login(qrChan chan<- string) (Session, error) { } session.ClientId = base64.StdEncoding.EncodeToString(clientId) - login := []interface{}{"admin", "init", waVersion, []string{wac.longClientName, wac.shortClientName}, session.ClientId, true} + login := []interface{}{"admin", "init", waVersion, []string{wac.longClientName, wac.shortClientName, wac.clientVersion}, session.ClientId, true} loginChan, err := wac.writeJson(login) if err != nil { return session, fmt.Errorf("error writing login: %v\n", err) @@ -369,7 +369,7 @@ func (wac *Conn) Restore() error { wac.listener.Unlock() //admin init - init := []interface{}{"admin", "init", waVersion, []string{wac.longClientName, wac.shortClientName}, wac.session.ClientId, true} + init := []interface{}{"admin", "init", waVersion, []string{wac.longClientName, wac.shortClientName, wac.clientVersion}, wac.session.ClientId, true} initChan, err := wac.writeJson(init) if err != nil { return fmt.Errorf("error writing admin init: %v\n", err) From dc42e176fd53a3243f28566eb900ec8891529c6c Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Tue, 21 Apr 2020 09:06:25 +0300 Subject: [PATCH 2/2] Add default value for clientVersion --- conn.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/conn.go b/conn.go index 4dbd68cb..f8b57443 100644 --- a/conn.go +++ b/conn.go @@ -122,6 +122,7 @@ func NewConn(timeout time.Duration) (*Conn, error) { longClientName: "github.com/rhymen/go-whatsapp", shortClientName: "go-whatsapp", + clientVersion: "0.1.0", } return wac, wac.connect() } @@ -136,6 +137,7 @@ func NewConnWithProxy(timeout time.Duration, proxy func(*http.Request) (*url.URL longClientName: "github.com/rhymen/go-whatsapp", shortClientName: "go-whatsapp", + clientVersion: "0.1.0", Proxy: proxy, } return wac, wac.connect()