matterbridge icon indicating copy to clipboard operation
matterbridge copied to clipboard

WhatsApp Version out of date

Open Schattenkanzler opened this issue 7 months ago • 35 comments

Describe the bug I get an error regarding an outdated version of WhatsApp since yesterday.

To Reproduce Just start matterbridge.

Expected behavior A connection to WhatsApp and successfull forwarding.

Screenshots/debug logs $ ./matterbridge [0000] INFO main: Running version 1.26.1-dev [0000] INFO main: WARNING: THIS IS A DEVELOPMENT VERSION. Things may break. [0000] INFO router: Parsing gateway Forwarder [0000] INFO router: Starting bridge: telegram.mytelegram [0000] INFO telegram: Connecting [0000] INFO telegram: Connection succeeded [0000] INFO telegram: telegram.mytelegram: joining (ID: telegram.mytelegram) [0000] INFO router: Starting bridge: whatsapp.mywhatsapp [0000] INFO whatsapp: WhatsApp connection successful 10:16:10.398 [Client/Socket ERROR] Error reading from websocket: websocket: close 1006 (abnormal closure): unexpected EOF 10:16:10.398 [Client ERROR] Client outdated (405) connect failure (client version: 2.3000.1015853550) [0006] FATAL main: Starting gateway failed: Bridge whatsapp.mywhatsapp failed to start: failed to get list of joined groups: websocket disconnected before info query returned response

Environment (please complete the following information):

  • OS: Rocky Linux 9.5 (Blue Onyx)
  • Matterbridge version: 1.26.1-dev

Schattenkanzler avatar May 28 '25 08:05 Schattenkanzler

Can confirm. Same issue as https://github.com/42wim/matterbridge/issues/2232 Most likely caused by an outdated version of https://github.com/tulir/whatsmeow

Vetgans avatar May 28 '25 13:05 Vetgans

Same here

Hunv avatar May 28 '25 21:05 Hunv

go.mod references go.mau.fi/whatsmeow v0.0.0-20240821142752-3d63c6fcc1a7 which is 9 months old, current is from yesterday.

uwedisch avatar May 28 '25 23:05 uwedisch

OK, for everyone who wants to update whatsmeow manually follow the following steps. I have no clou about go and dependency. Thats the reason why I am not creating a pull request. Disclaimer: All the following steps were suggested by claude.ai and were verified by me:

Manual update of whatsmeow Library to current version (Updated 2025-09-24)

I expect you have git and go installed. Run the following commands to download the matterbridge repo, update whatsmeow and the references in the go project.

git clone https://github.com/42wim/matterbridge.git
cd matterbridge
go get -u go.mau.fi/whatsmeow@latest
go mod tidy
go mod vendor

Update the code as whatsmeow has breaking changes:

In bridge/whatsappmulti/handlers.go: At the very beginning at the import section add the line

"context"

After that at line 246:

// Replace
data, err := b.wc.Download(imsg)
// with
data, err := b.wc.Download(context.Background(), imsg)

After that at line 313:

// Replace
data, err := b.wc.Download(imsg)
// with
data, err := b.wc.Download(context.Background(), imsg)

After that at line 370:

// Replace
data, err := b.wc.Download(imsg)
// with
data, err := b.wc.Download(context.Background(), imsg)

After that at line 424:

// Replace
data, err := b.wc.Download(imsg)
// with
data, err := b.wc.Download(context.Background(), imsg)

In bridge/whatsappmulti/whatsapp.go: In line 125

// Replace
b.contacts, err = b.wc.Store.Contacts.GetAllContacts()
// with
b.contacts, err = b.wc.Store.Contacts.GetAllContacts(context.Background())

In line 130 (new since 2025-09-24)

// Replace
groups, err := b.wc.GetJoinedGroups()
// with
groups, err := b.wc.GetJoinedGroups(context.Background())

In bridge/whatsappmulti/helper.go: At the very beginning at the import section add the line

"context"

In line 27:

// Replace
if _, err := b.wc.Store.Contacts.GetAllContacts(); err != nil {
// with
if _, err := b.wc.Store.Contacts.GetAllContacts(context.Background()); err != nil {

In line 31:

// Replace
allcontacts, err := b.wc.Store.Contacts.GetAllContacts()
// with
allcontacts, err := b.wc.Store.Contacts.GetAllContacts(context.Background())

In line 140:

// Replace
storeContainer, err := sqlstore.New("sqlite", "file:"+b.Config.GetString("sessionfile")+".db?_pragma=foreign_keys(1)&_pragma=busy_timeout=10000", nil)
// with
storeContainer, err := sqlstore.New(context.Background(), "sqlite", "file:"+b.Config.GetString("sessionfile")+".db?_pragma=foreign_keys(1)&_pragma=busy_timeout=10000", nil)

In Line 145:

//Replace 
device, err = storeContainer.GetFirstDevice()
// with
device, err = storeContainer.GetFirstDevice(context.Background())

After all that changes run this command (adjust the tags by your needs):

go build -tags nomsteams,whatsappmulti

You will have the file matterbridge in your current directory, which is the binary of the matterbridge with the update whatsmeow library. Eventually you also need to delete the session file in your matterbridge folder and reauthenticate with the QR code after.

Hunv avatar May 29 '25 10:05 Hunv

I've submitted a pull request with the necessary changes:

https://github.com/42wim/matterbridge/pull/2234

redbullpeter avatar May 29 '25 11:05 redbullpeter

I've submitted a pull request with the necessary changes:

#2234

Let's hope that this will be merged soon.

Hunv avatar May 29 '25 11:05 Hunv

I got things working again with updating Go as well, followed by the modifications made by Hunv and redbullpeter:

git clone https://github.com/redbullpeter/matterbridge.git cd matterbridge go get -u go.mau.fi/whatsmeow@latest go mod tidy go mod vendor CGO_ENABLED=0 go install -tags whatsappmulti,nomsteams,nozulip ./

You will find the new matterbridge file in the go/bin folder. The 'go mod' commands are necessary as well, just cloning https://github.com/redbullpeter/matterbridge is not enough.

Now everything seems to be working fine again.

Vetgans avatar May 30 '25 10:05 Vetgans

@Vetgans - The master version of my repo includes some other changes. If you want the vanilla version with just the whatsmeow updates you need to use the https://github.com/redbullpeter/matterbridge/tree/whatsmeow-update-(202505027-0b502af) branch.

redbullpeter avatar May 30 '25 10:05 redbullpeter

Now everything seems to be working fine again.

Messages are sent to other platforms, but the return to WhatsApp function no longer seems to work. It also doesn't work with audio or quoting messages.

weskerty avatar Jun 01 '25 10:06 weskerty

Now everything seems to be working fine again.

Messages are sent to other platforms, but the return to WhatsApp function no longer seems to work. It also doesn't work with audio or quoting messages.

@weskerty : I did not the changes @Vetgans did. Just the ones I noted. With that I receive message (which is the only function I need at the moment).

Hunv avatar Jun 01 '25 11:06 Hunv

After following i still got this issue

[0014] INFO main: Gateway(s) started successfully. Now relaying messages 00:40:25.928 [Client INFO] Uploading 50 new prekeys to server 00:40:26.891 [Client WARN] Received stream end frame 00:40:26.891 [Client INFO] Got device removed stream error, sending LoggedOut event and deleting session 00:40:27.031 [Client/Socket ERROR] Error reading from websocket: websocket: close 1006 (abnormal closure): unexpected EOF

SOLUTION JUST USE WHATSAPP BUSINESS FOR THIS

djambred avatar Jul 20 '25 17:07 djambred

Is there a solution for WhatsApp? All the forks I've tried either fail with WhatsApp or fail to compile because the imports point to this repository.

weskerty avatar Sep 19 '25 16:09 weskerty

@weskerty have you tried this pull request https://github.com/42wim/matterbridge/pull/2234 or my manual way https://github.com/42wim/matterbridge/issues/2233#issuecomment-2918927731 ?

Hunv avatar Sep 19 '25 17:09 Hunv

same problem now with whatsapp @Hunv @redbullpeter help hehe

fabio841 avatar Sep 23 '25 12:09 fabio841

same problem now with whatsapp @Hunv @redbullpeter help hehe

Have you tried the mentioned workarounds?

Hunv avatar Sep 23 '25 15:09 Hunv

At first sight, the same as before: https://github.com/tulir/whatsmeow outdated

Vetgans avatar Sep 23 '25 17:09 Vetgans

Worked fine since today with the workarounds Now I got an error

[Client/Socket ERROR] Error reading from websocket: websocket: close 1006 (abnormal closure): unexpected EOF

jpuig-wq avatar Sep 23 '25 17:09 jpuig-wq

Ok, it is also not working for me anymore. I can try to fix it tomorrow.

Hunv avatar Sep 23 '25 17:09 Hunv

@fabio841 @Vetgans @jpuig-wq @weskerty I fixed it and updated my steps at https://github.com/42wim/matterbridge/issues/2233#issuecomment-2918927731 There is one new additional change in the whatsapp.go file (line 130)

@redbullpeter : Maybe you can also update your pull request?

Hunv avatar Sep 24 '25 11:09 Hunv

I would think I followed everything correctly, but it shows me this error.

# github.com/42wim/matterbridge/bridge/whatsappmulti
bridge/whatsappmulti/whatsapp.go:130:2: declared and not used: groups

I made the change on that line to groups, err := b.wc.GetJoinedGroups(context.Background())

weskerty avatar Sep 24 '25 19:09 weskerty

I would think I followed everything correctly, but it shows me this error.

# github.com/42wim/matterbridge/bridge/whatsappmulti
bridge/whatsappmulti/whatsapp.go:130:2: declared and not used: groups

I made the change on that line to groups, err := b.wc.GetJoinedGroups(context.Background())

The correct line should be

    b.joinedGroups, err = b.wc.GetJoinedGroups(context.Background())

With that correction, it's working now.

ccabrerar avatar Sep 24 '25 19:09 ccabrerar

I would think I followed everything correctly, but it shows me this error.

# github.com/42wim/matterbridge/bridge/whatsappmulti
bridge/whatsappmulti/whatsapp.go:130:2: declared and not used: groups

I made the change on that line to groups, err := b.wc.GetJoinedGroups(context.Background())

The correct line should be

    b.joinedGroups, err = b.wc.GetJoinedGroups(context.Background())

With that correction, it's working now.

Interesting. For me it worked like I descibed it.

Hunv avatar Sep 25 '25 07:09 Hunv

if work can you update any fork and send link of .git file ? Thanks

fabio841 avatar Sep 25 '25 15:09 fabio841

###############################################################################
# SOLUZIONE COMPLETA: FIX "Client outdated (405)" + pulizia WARN avatar (A)
# - Clona redbullpeter/matterbridge
# - Aggiorna whatsmeow a commit recente
# - Forza WA Web version “latest” a runtime (niente più 405)
# - Adegua API (context, sqlstore.New, Download)
# - Silenzia WARN sugli avatar (WARN->DEBUG)
# - Compila in ~/go/bin/matterbridge
###############################################################################

### 0) Installa Go 1.24.6 portable e usa quello per la build
sudo rm -rf /usr/local/go
cd /usr/local && sudo wget -q https://go.dev/dl/go1.24.6.linux-amd64.tar.gz && sudo tar -xzf go1.24.6.linux-amd64.tar.gz
export PATH=/usr/local/go/bin:$PATH
go version   # deve stampare go1.24.6

### 1) Stop & backup del binario attuale (se esiste)
pkill -f matterbridge 2>/dev/null || true
mkdir -p ~/go/bin
[ -x ~/go/bin/matterbridge ] && cp ~/go/bin/matterbridge ~/go/bin/matterbridge.bak.$(date +%F-%H%M)

### 2) Clona il fork pulito e prepara un branch di lavoro
cd /opt
rm -rf matterbridge-fix
git clone https://github.com/redbullpeter/matterbridge.git matterbridge-fix
cd matterbridge-fix
git checkout -b wa-autofix-$(date +%Y%m%d%H%M)

### 3) Sistema go.mod (normalizza versione Go e porta a 1.24)
sed -i 's/^go\./go /' go.mod || true
sed -i -E 's/^go ([0-9]+\.[0-9]+)\.0$/go \1/' go.mod
sed -i -E 's/^go [0-9]+\.[0-9]+$/go 1.24/' go.mod

### 4) Aggiorna whatsmeow a commit recente e allinea mod (NO vendor)
go get go.mau.fi/whatsmeow@258fd9454b95
go mod tidy

### 5) PATCH: forza WA Web version “latest” in Connect() (anti-405)
file="bridge/whatsappmulti/whatsapp.go"

# importa i pacchetti se mancano (senza duplicare import)
grep -q '"context"' "$file" || sed -i '/^import (/a \ \t"context"' "$file"
grep -q '"net/http"' "$file" || sed -i '/^import (/a \ \t"net/http"' "$file"
grep -q 'go.mau.fi/whatsmeow"' "$file" || sed -i '/^import (/a \ \t"go.mau.fi/whatsmeow"' "$file"
grep -q 'waStore "go.mau.fi/whatsmeow/store"' "$file" || sed -i '/^import (/a \ \twaStore "go.mau.fi/whatsmeow/store"' "$file"
sed -i '/wastore "go.mau.fi\/whatsmeow\/store"/d' "$file" || true

# inserisci il blocco all'inizio di: func (b *Bwhatsapp) Connect() error {
awk '{
  print
  if ($0 ~ /^func \(b \*Bwhatsapp\) Connect\(\) error \{$/ && !p) {
    print "\t// Force latest WA web version to avoid 405"
    print "\tif ver, err := whatsmeow.GetLatestVersion(context.Background(), http.DefaultClient); err == nil {"
    print "\t\twaStore.SetWAVersion(*ver)"
    print "\t\tb.Log.Infof(\"Using WA web version %s\", ver.String())"
    print "\t} else {"
    print "\t\tb.Log.Warnf(\"Couldn\\x27t fetch latest WA version: %v\", err)"
    print "\t}"
    p=1
  }
}' "$file" > "$file.new" && mv "$file.new" "$file"

### 6) PATCH: adegua alle API nuove (idempotente/sicuro da rilanciare)
# GetAllContacts / GetJoinedGroups richiedono context
sed -i 's/GetAllContacts()/GetAllContacts(context.Background())/g' bridge/whatsappmulti/whatsapp.go bridge/whatsappmulti/helpers.go
sed -i 's/GetJoinedGroups()/GetJoinedGroups(context.Background())/g' bridge/whatsappmulti/whatsapp.go 2>/dev/null || true

# Download(...) richiede (context, whatsmeow.DownloadableMessage)
# - rimuovi doppi context, se ti capitano:
sed -i 's/\.Download(context\.Background(), context\.Background(), /\.Download(context.Background(), /g' bridge/whatsappmulti/handlers.go
# - aggiungi il context SOLO alle chiamate che passano direttamente *waE2E.<Msg>
sed -i 's/\.Download(\s*\*waE2E\./.Download(context.Background(), *waE2E./g' bridge/whatsappmulti/handlers.go

# sqlstore.New ora è: sqlstore.New(context, driver, dsn, logger)
# importa logger moderno e sostituisci vecchie firme con logger Noop
grep -q 'waLog "go.mau.fi/whatsmeow/util/log"' bridge/whatsappmulti/helpers.go || \
  sed -i '/^import (/a \ \twaLog "go.mau.fi/whatsmeow/util/log"' bridge/whatsappmulti/helpers.go
sed -E -i 's/sqlstore\.New\(([^,]+), ([^,]+), *nil\)/sqlstore.New(context.Background(), \1, \2, waLog.Noop)/g' bridge/whatsappmulti/helpers.go

# GetFirstDevice richiede context
sed -i 's/GetFirstDevice()/GetFirstDevice(context.Background())/g' bridge/whatsappmulti/helpers.go

### 7) OPZIONE A: silenzia i warning avatar (WARN/INFO -> DEBUG)
sed -i 's/b\.Log\.Warnf("Could not get profile photo of %s: %v", jid, err)/b.Log.Debugf("Could not get profile photo of %s: %v", jid, err)/' bridge/whatsappmulti/whatsapp.go
sed -E -i 's/b\.Log\.Info\("Getting user avatars\.\."\)/b.Log.Debug("Getting user avatars..")/' bridge/whatsappmulti/whatsapp.go
sed -E -i 's/b\.Log\.Info\("Finished getting avatars\.\."\)/b.Log.Debug("Finished getting avatars..")/' bridge/whatsappmulti/whatsapp.go

### 8) Build (ignoriamo vendor; binario in ~/go/bin)
CGO_ENABLED=0 /usr/local/go/bin/go build -tags whatsappmulti,nomsteams,nozulip -o ~/go/bin/matterbridge

### 9) Verifica che linki la whatsmeow aggiornata
ls -lh ~/go/bin/matterbridge
/usr/local/go/bin/go version -m ~/go/bin/matterbridge | egrep 'matterbridge|whatsmeow'

### 10) Avvio (stessa cartella del tuo matterbridge.toml + session)
cd ~/go/bin
./matterbridge -conf ./matterbridge.toml

# (facoltativo: background con log su file)
# nohup ./matterbridge -conf ./matterbridge.toml > /var/log/matterbridge.log 2>&1 &
# tail -f /var/log/matterbridge.log

solve, confirm pls

fabio841 avatar Sep 25 '25 20:09 fabio841

I would think I followed everything correctly, but it shows me this error.

# github.com/42wim/matterbridge/bridge/whatsappmulti
bridge/whatsappmulti/whatsapp.go:130:2: declared and not used: groups

I made the change on that line to groups, err := b.wc.GetJoinedGroups(context.Background())

The correct line should be

    b.joinedGroups, err = b.wc.GetJoinedGroups(context.Background())

With that correction, it's working now.

Interesting. For me it worked like I descibed it.

https://github.com/42wim/matterbridge/blob/master/bridge/whatsappmulti/whatsapp.go#L130

It is b.joinedGroups

Always has been. Likely a copy-pasta failure, because indeed code iterates over b.joinedGroups whereas "groups" is not really used anywhere.

pazkero avatar Sep 25 '25 23:09 pazkero

if work can you update any fork and send link of .git file ? Thanks

https://github.com/Vetgans/matterbridge.git

So: git clone https://github.com/Vetgans/matterbridge.git cd matterbridge go get -u go.mau.fi/whatsmeow@latest go mod tidy go mod vendor CGO_ENABLED=0 go install -tags whatsappmulti,nomsteams,nozulip ./

works for me

Vetgans avatar Sep 26 '25 21:09 Vetgans

if work can you update any fork and send link of .git file ? Thanks

https://github.com/Vetgans/matterbridge.git

So: git clone https://github.com/Vetgans/matterbridge.git cd matterbridge go get -u go.mau.fi/whatsmeow@latest go mod tidy go mod vendor CGO_ENABLED=0 go install -tags whatsappmulti,nomsteams,nozulip ./

works for me

I built a docker from that fork and bridged a Telegram <> WhatsApp groups. WhatsApp -> Telegram it's working, but not the other way around. Are you able to send messages to WhatsApp?

Megver83 avatar Sep 29 '25 02:09 Megver83

Yes.

I only use Matrix <-> Whatsapp bridges, and just tested it: It works in both directions. So the problem is probably on the Telegram-side of the bridge? If so, i can't help you with that since i don't use it. I didn't implement any changes or commits to the Telegram-bridge.

As far as i know, with Matterbridge it is not possible to sent direct messages to Whatsapp-users, only to Whatsapp-groups. Are you by any chance trying to DM someone on Whatsapp? Because that won't work.

Vetgans avatar Sep 29 '25 18:09 Vetgans

Even though I'm allowed to log in to WhatsApp, it seems that messages are no longer working Out of 500 messages, it only forwards 10 to other platforms.

weskerty avatar Sep 30 '25 13:09 weskerty

So the problem is probably on the Telegram-side of the bridge? If so, i can't help you with that since i don't use it. I didn't implement any changes or commits to the Telegram-bridge.

I just tested it with a different Telegram group and it worked. Idk if the group has a problem or maybe the Telegram bridge needs an update, but doesn't look like a WhatsApp issue.

Megver83 avatar Oct 01 '25 01:10 Megver83