42wim / matterbridge

bridge between mattermost, IRC, gitter, xmpp, slack, discord, telegram, rocketchat, twitch, ssh-chat, zulip, whatsapp, keybase, matrix, microsoft teams, nextcloud, mumble, vk and more with REST API (mattermost not required!)
Apache License 2.0
6.45k stars 605 forks source link

Can not send Messages via Bridge with WhatsApp #1337

Closed allilengyi closed 3 years ago

allilengyi commented 3 years ago

Describe the bug I have a semi-working bridge connecting Telegram, Matrix, XMPP and Whatsapp.. Receiving messages via bridge works for all. Sending messages via bridge only for Telegram, Matrix, XMPP

To Reproduce Create a Bridge between Whatsapp and Telegram, Matrix or XMPP

Expected behavior Messages sent with WhatsApp are sent via matterbridge.

Screenshots/debug logs In the logs you can see, that whatsapp receives messages (here send from matrix)

[0013] DEBUG whatsapp:     [Send:bridge/whatsapp/whatsapp.go:350] => Sending config.Message{Text:"Für Whatsapp", Channel:"xxxx-xxxx@g.us", Username:"[matrix] @tommy: ", UserID:"@tommy:privacytools.io", Avatar:"", Account:"matrix.privacytools", Event:"", Protocol:"matrix", Gateway:"bridge", ParentID:"", Timestamp:time.Time{wall:0xbfeeff2af8505323, ext:12868891372, loc:(*time.Location)(0x334ea00)}, ID:"", Extra:map[string][]interface {}(nil)}

But when typing a message in Whatsapp nothing appears in the log. The log file:

[0000]  INFO router:       [Start:gateway/router.go:66] Parsing gateway bridge
[0000]  INFO router:       [Start:gateway/router.go:75] Starting bridge: whatsapp.wabot 
[0000] DEBUG whatsapp:     [Connect:bridge/whatsapp/whatsapp.go:68] Connecting to WhatsApp..
[0000] DEBUG whatsapp:     [Connect:bridge/whatsapp/whatsapp.go:77] WhatsApp connection successful
[0000] DEBUG whatsapp:     [Connect:bridge/whatsapp/whatsapp.go:85] Restoring WhatsApp session..
[0001] DEBUG whatsapp:     [Connect:bridge/whatsapp/whatsapp.go:96] Session restored successfully!
[0001] ERROR whatsapp:     [HandleError:bridge/whatsapp/handlers.go:39] message type not implemented
[0001] ERROR whatsapp:     [HandleError:bridge/whatsapp/handlers.go:39] message type not implemented
[0001] ERROR whatsapp:     [HandleError:bridge/whatsapp/handlers.go:39] message type not implemented
[0001] ERROR whatsapp:     [HandleError:bridge/whatsapp/handlers.go:39] message type not implemented
[0001] ERROR whatsapp:     [HandleError:bridge/whatsapp/handlers.go:39] message type not implemented
[0001] ERROR whatsapp:     [HandleError:bridge/whatsapp/handlers.go:39] message type not implemented
[0001] ERROR whatsapp:     [HandleError:bridge/whatsapp/handlers.go:39] message type not implemented
[0001] ERROR whatsapp:     [HandleError:bridge/whatsapp/handlers.go:39] message type not implemented
[0002] ERROR whatsapp:     [HandleError:bridge/whatsapp/handlers.go:39] message type not implemented
[0002]  INFO whatsapp:     [joinChannels:bridge/bridge.go:77] whatsapp.wabot: joining xxxx-xxxx@g.us (ID: xxxx-xxxx@g.uswhatsapp.wabot)
[0002]  INFO router:       [Start:gateway/router.go:75] Starting bridge: xmpp.blabber 
[0002]  INFO xmpp:         [Connect:bridge/xmpp/xmpp.go:41] Connecting blabber.im:5222
[0002] DEBUG whatsapp:     [func1:bridge/whatsapp/whatsapp.go:126] Getting user avatars..
[0003]  INFO xmpp:         [Connect:bridge/xmpp/xmpp.go:47] Connection succeeded
[0003]  INFO xmpp:         [joinChannels:bridge/bridge.go:77] xmpp.blabber: joining bridge-test (ID: bridge-testxmpp.blabber)
[0003]  INFO router:       [Start:gateway/router.go:75] Starting bridge: matrix.privacytools 
[0003]  INFO matrix:       [Connect:bridge/matrix/matrix.go:76] Connecting https://chat.privacytools.io
[0003] DEBUG xmpp:         [handleXMPP:bridge/xmpp/xmpp.go:237] == Receiving xmpp.Chat{Remote:"bridge-test@conference.blabber.im", Type:"groupchat", Text:"", Subject:"", Thread:"", Ooburl:"", Oobdesc:"", ID:"", ReplaceID:"", Roster:xmpp.Roster(nil), Other:[]string{}, OtherElem:[]xmpp.XMLElement(nil), Stamp:time.Time{wall:0x0, ext:0, loc:(*time.Location)(nil)}}
[0005]  INFO matrix:       [Connect:bridge/matrix/matrix.go:92] Connection succeeded
[0005]  INFO matrix:       [joinChannels:bridge/bridge.go:77] matrix.privacytools: joining #bridge-test:privacytools.io (ID: #bridge-test:privacytools.iomatrix.privacytools)
[0005]  INFO router:       [Start:gateway/router.go:75] Starting bridge: telegram.tgbot 
[0005]  INFO telegram:     [Connect:bridge/telegram/telegram.go:46] Connecting
[0005]  INFO telegram:     [Connect:bridge/telegram/telegram.go:59] Connection succeeded
[0005]  INFO telegram:     [joinChannels:bridge/bridge.go:77] telegram.tgbot: joining -1001111111 (ID: -1001111111telegram.tgbot)
[0005]  INFO main:         [main:matterbridge.go:70] Gateway(s) started succesfully. Now relaying messages
[0012] DEBUG matrix:       [handleEvent:bridge/matrix/matrix.go:282] == Receiving event: &gomatrix.Event{StateKey:(*string)(nil), Sender:"@tommy:privacytools.io", Type:"m.room.message", Timestamp:1608221994428, ID:"$YSovQFDQMU4JF6kUgY5Pkj9pHppkCqhmoLxAb0ajAfQ", RoomID:"!pWIPPSfgfrfCcMwsOo:privacytools.io", Redacts:"", Unsigned:map[string]interface {}{"age":1503}, Content:map[string]interface {}{"body":"Für Whatsapp", "msgtype":"m.text"}, PrevContent:map[string]interface {}(nil)}
[0012] DEBUG matrix:       [handleEvent:bridge/matrix/matrix.go:342] <= Sending message from @tommy:privacytools.io on matrix.privacytools to gateway
[0012] DEBUG gateway:      [SendMessage:gateway/gateway.go:472] => Sending config.Message{Text:"Für Whatsapp", Channel:"#bridge-test:privacytools.io", Username:"tommy", UserID:"@tommy:privacytools.io", Avatar:"", Account:"matrix.privacytools", Event:"", Protocol:"matrix", Gateway:"bridge", ParentID:"", Timestamp:time.Time{wall:0xbfeeff2af8505323, ext:12868891372, loc:(*time.Location)(0x334ea00)}, ID:"$YSovQFDQMU4JF6kUgY5Pkj9pHppkCqhmoLxAb0ajAfQ", Extra:map[string][]interface {}(nil)} from matrix.privacytools (#bridge-test:privacytools.io) to xmpp.blabber (bridge-test)
[0012] DEBUG xmpp:         [Send:bridge/xmpp/xmpp.go:76] => Receiving config.Message{Text:"Für Whatsapp", Channel:"bridge-test", Username:"[matrix] <tommy> ", UserID:"@tommy:privacytools.io", Avatar:"", Account:"matrix.privacytools", Event:"", Protocol:"matrix", Gateway:"bridge", ParentID:"", Timestamp:time.Time{wall:0xbfeeff2af8505323, ext:12868891372, loc:(*time.Location)(0x334ea00)}, ID:"", Extra:map[string][]interface {}(nil)}
[0012] DEBUG xmpp:         [Send:bridge/xmpp/xmpp.go:112] => Sending message config.Message{Text:"Für Whatsapp", Channel:"bridge-test", Username:"[matrix] <tommy> ", UserID:"@tommy:privacytools.io", Avatar:"", Account:"matrix.privacytools", Event:"", Protocol:"matrix", Gateway:"bridge", ParentID:"", Timestamp:time.Time{wall:0xbfeeff2af8505323, ext:12868891372, loc:(*time.Location)(0x334ea00)}, ID:"", Extra:map[string][]interface {}(nil)}
[0012] DEBUG gateway:      [SendMessage:gateway/gateway.go:491] mID xmpp.blabber: bvdoaatjcrc8r9087dg0
[0012] DEBUG gateway:      [func1:gateway/gateway.go:481] => Send from matrix.privacytools (#bridge-test:privacytools.io) to xmpp.blabber (bridge-test) took 490.099µs
[0012] DEBUG gateway:      [SendMessage:gateway/gateway.go:472] => Sending config.Message{Text:"Für Whatsapp", Channel:"#bridge-test:privacytools.io", Username:"tommy", UserID:"@tommy:privacytools.io", Avatar:"", Account:"matrix.privacytools", Event:"", Protocol:"matrix", Gateway:"bridge", ParentID:"", Timestamp:time.Time{wall:0xbfeeff2af8505323, ext:12868891372, loc:(*time.Location)(0x334ea00)}, ID:"$YSovQFDQMU4JF6kUgY5Pkj9pHppkCqhmoLxAb0ajAfQ", Extra:map[string][]interface {}(nil)} from matrix.privacytools (#bridge-test:privacytools.io) to telegram.tgbot (-1001111111)
[0012] DEBUG telegram:     [Send:bridge/telegram/telegram.go:73] => Receiving config.Message{Text:"Für Whatsapp", Channel:"-1001111111", Username:"(matrix) &lt;tommy&gt; ", UserID:"@tommy:privacytools.io", Avatar:"", Account:"matrix.privacytools", Event:"", Protocol:"matrix", Gateway:"bridge", ParentID:"", Timestamp:time.Time{wall:0xbfeeff2af8505323, ext:12868891372, loc:(*time.Location)(0x334ea00)}, ID:"", Extra:map[string][]interface {}(nil)}
[0012] DEBUG telegram:     [sendMessage:bridge/telegram/telegram.go:148] Using mode HTML - nick only
[0012] DEBUG xmpp:         [handleXMPP:bridge/xmpp/xmpp.go:237] == Receiving xmpp.Chat{Remote:"bridge-test@conference.blabber.im/xmppbot", Type:"groupchat", Text:"[matrix] <tommy> Für Whatsapp", Subject:"", Thread:"", Ooburl:"", Oobdesc:"", ID:"bvdoaatjcrc8r9087dg0", ReplaceID:"", Roster:xmpp.Roster(nil), Other:[]string{"", ""}, OtherElem:[]xmpp.XMLElement{xmpp.XMLElement{XMLName:xml.Name{Space:"urn:xmpp:mam:tmp", Local:"archived"}, InnerXML:""}, xmpp.XMLElement{XMLName:xml.Name{Space:"urn:xmpp:sid:0", Local:"stanza-id"}, InnerXML:""}}, Stamp:time.Time{wall:0x0, ext:0, loc:(*time.Location)(nil)}}
[0013] DEBUG gateway:      [SendMessage:gateway/gateway.go:491] mID telegram.tgbot: 94
[0013] DEBUG gateway:      [func1:gateway/gateway.go:481] => Send from matrix.privacytools (#bridge-test:privacytools.io) to telegram.tgbot (-1001111111) took 238.948811ms
[0013] DEBUG gateway:      [SendMessage:gateway/gateway.go:472] => Sending config.Message{Text:"Für Whatsapp", Channel:"#bridge-test:privacytools.io", Username:"tommy", UserID:"@tommy:privacytools.io", Avatar:"", Account:"matrix.privacytools", Event:"", Protocol:"matrix", Gateway:"bridge", ParentID:"", Timestamp:time.Time{wall:0xbfeeff2af8505323, ext:12868891372, loc:(*time.Location)(0x334ea00)}, ID:"$YSovQFDQMU4JF6kUgY5Pkj9pHppkCqhmoLxAb0ajAfQ", Extra:map[string][]interface {}(nil)} from matrix.privacytools (#bridge-test:privacytools.io) to whatsapp.wabot (xxxx-xxxx@g.us)
[0013] DEBUG whatsapp:     [Send:bridge/whatsapp/whatsapp.go:300] => Receiving config.Message{Text:"Für Whatsapp", Channel:"xxxx-xxxx@g.us", Username:"[matrix] @tommy: ", UserID:"@tommy:privacytools.io", Avatar:"", Account:"matrix.privacytools", Event:"", Protocol:"matrix", Gateway:"bridge", ParentID:"", Timestamp:time.Time{wall:0xbfeeff2af8505323, ext:12868891372, loc:(*time.Location)(0x334ea00)}, ID:"", Extra:map[string][]interface {}(nil)}
[0013] DEBUG whatsapp:     [Send:bridge/whatsapp/whatsapp.go:350] => Sending config.Message{Text:"Für Whatsapp", Channel:"xxxx-xxxx@g.us", Username:"[matrix] @tommy: ", UserID:"@tommy:privacytools.io", Avatar:"", Account:"matrix.privacytools", Event:"", Protocol:"matrix", Gateway:"bridge", ParentID:"", Timestamp:time.Time{wall:0xbfeeff2af8505323, ext:12868891372, loc:(*time.Location)(0x334ea00)}, ID:"", Extra:map[string][]interface {}(nil)}
[0013] DEBUG gateway:      [SendMessage:gateway/gateway.go:491] mID whatsapp.wabot: C678816355665A741857
[0013] DEBUG gateway:      [func1:gateway/gateway.go:481] => Send from matrix.privacytools (#bridge-test:privacytools.io) to whatsapp.wabot (xxxx-xxxx@g.us) took 485.482934ms
[0093] DEBUG xmpp:         [func1:bridge/xmpp/xmpp.go:210] PING
[0112] DEBUG whatsapp:     [func1:bridge/whatsapp/whatsapp.go:138] Finished getting avatars..
[0183] DEBUG xmpp:         [func1:bridge/xmpp/xmpp.go:210] PING

Environment (please complete the following information):

Additional context

[general]
#check https://github.com/42wim/matterbridge/wiki/Settings#general
#some options for general configs such as
LogFile="/var/log/matterbridge.log"
MediaDownloadPath="/var/www/bridge/upload"
MediaDownloadSize=5000000

[matrix.privacytools]
#Server is your homeserver (eg https://matrix.org)
Server="https://chat.privacytools.io"

#login/pass of your bot.
#Use a dedicated user for this and not your own!
#Messages sent from this user will not be relayed to avoid loops.
Login="bridge-bot"
Password=""

RemoteNickFormat="[{PROTOCOL}] <{NICK}> "

#Whether to send the homeserver suffix. eg ":matrix.org" in @username:matrix.org
#to other bridges, or only send "username".(true only sends username)
#OPTIONAL (default false)
NoHomeServerSuffix=false

[xmpp.blabber]
Server="blabber.im:5222"
#Jid your userid
Jid="bridge-bot@blabber.im"
Password=""
Muc="conference.blabber.im"
Nick="xmppbot"
RemoteNickFormat="[{PROTOCOL}] <{NICK}> "

[telegram.tgbot]
#See https://core.telegram.org/bots#6-botfather 
#and https://www.linkedin.com/pulse/telegram-bots-beginners-marco-frau
Token=""
RemoteNickFormat="({PROTOCOL}) &lt;{NICK}&gt; "
MessageFormat="HTMLNick"

[whatsapp.wabot]
# Number you will use as a relay bot. Tip: Get some disposable sim card, don't rely on 
# your own number.
Number=""

# First time that you login you will need to scan QR code, then credentials will be saved in 
# a session file. 
# If you won't set SessionFile then you will need to scan QR code on every restart.
# optional (by default the session is stored only in memory, till restarting matterbridge)
SessionFile="session-wa.gob"

# If your terminal is white we need to invert QR code in order for it to be scanned properly
# optional (default false)
QrOnWhiteTerminal=false

# Messages will be seen by other WhatsApp contacts as coming from the bridge. 
# Original nick will be part of the message.
RemoteNickFormat="[{PROTOCOL}] @{NICK}: "

[[gateway]]
name="bridge"
enable=true

[[gateway.inout]]
account="xmpp.blabber"
channel="bridge-test"

[[gateway.inout]]
account="matrix.privacytools"
channel="#bridge-test:privacytools.io"

[[gateway.inout]]
account="telegram.tgbot"
channel="-100ID"

[[gateway.inout]]
account="whatsapp.wabot"
channel="xxxx-xxxx@g.us"
urimax commented 3 years ago

I'm newbie. Yesterday I set up for my first time a bridge Whatsapp<>Telegram and I had issues sending messages from WhatsApp to Telegram but not from Telegram to WhatsApp. In my case I discovered that WhatsApp web shows a notice about the new feature of auto-deleting messages 7 days old. This notice I think that is not yet supported by matterbridge. When I disabled this setting on my test group matterbridge begins running fine. Think about it, maybe is also your issue. (I my case, Winx64 and also v1.20 latest release)

allilengyi commented 3 years ago

If I enable auto-delete, then I get in the logs

[0018] ERROR whatsapp:     [HandleError:bridge/whatsapp/handlers.go:39] message type not implemented

when sending a message. When disabled again, nothing is written to the log file.

42wim commented 3 years ago

The whatsapp library has been upgraded in matterbridge v1.21.0 which probably fixed your issue. (https://github.com/Rhymen/go-whatsapp/pull/504)

Can you try and reopen if still an issue.

allilengyi commented 3 years ago

the issue/behavior is still the same

$matterbridge -version
version: 1.21.0 cf13fff7

and

[0002]  INFO router:       [Start:gateway/router.go:75] Starting bridge: whatsapp.wabot 
[0002] DEBUG whatsapp:     [Connect:bridge/whatsapp/whatsapp.go:64] Connecting to WhatsApp..
[0002] DEBUG whatsapp:     [Connect:bridge/whatsapp/whatsapp.go:73] WhatsApp connection successful
[0002] DEBUG whatsapp:     [restoreSession:bridge/whatsapp/helpers.go:83] Restoring WhatsApp session..
[0002] DEBUG whatsapp:     [restoreSession:bridge/whatsapp/helpers.go:91] Session restored successfully!
[0003] ERROR whatsapp:     [HandleError:bridge/whatsapp/handlers.go:40] message type not implemented
[0003] ERROR whatsapp:     [HandleError:bridge/whatsapp/handlers.go:40] message type not implemented
[0003] ERROR whatsapp:     [HandleError:bridge/whatsapp/handlers.go:40] message type not implemented
[0003] ERROR whatsapp:     [HandleError:bridge/whatsapp/handlers.go:40] message type not implemented
[0003] ERROR whatsapp:     [HandleError:bridge/whatsapp/handlers.go:40] message type not implemented
[0005] ERROR whatsapp:     [HandleError:bridge/whatsapp/handlers.go:40] message type not implemented
[0005] ERROR whatsapp:     [HandleError:bridge/whatsapp/handlers.go:40] message type not implemented
adrianovieira commented 3 years ago

Same error here...

$ matterbridge -version

version: 1.21.0 cf13fff7

$ matterbridge

[0006]  INFO router:       Starting bridge: rocketchat.bridge 
[0006]  INFO rocketchat:   Connecting using login/password (sending and receiving)
[0007]  INFO rocketchat:   Connection succeeded
[0007]  INFO rocketchat:   rocketchat.bridge: joining chat-whats-bridge (ID: chat-whats-bridgerocketchat.bridge)
[0007]  INFO main:         Gateway(s) started succesfully. Now relaying messages
[0007] ERROR whatsapp:     message type not implemented
[0007] ERROR whatsapp:     message type not implemented
[0007] ERROR whatsapp:     message type not implemented
[0007] ERROR whatsapp:     message type not implemented
...

$ matterbridge -debug

[0002] DEBUG whatsapp:     [func1:bridge/whatsapp/whatsapp.go:112] Getting user avatars..
[0002]  INFO router:       [Start:gateway/router.go:75] Starting bridge: rocketchat.bridge 
[0002]  INFO rocketchat:   [Connect:bridge/rocketchat/rocketchat.go:73] Connecting using login/password (sending and receiving)
[0002] DEBUG rocketchat:   [apiLogin:bridge/rocketchat/helpers.go:59] handling apiLogin()
[0002]  INFO rocketchat:   [apiLogin:bridge/rocketchat/helpers.go:84] Connection succeeded
[0002]  INFO rocketchat:   [joinChannels:bridge/bridge.go:77] rocketchat.bridge: joining chat-whats-bridge (ID: chat-whats-bridgerocketchat.bridge)
[0002] DEBUG rocketchat:   [handleRocket:bridge/rocketchat/handlers.go:14] Choosing login/password based receiving
[0002]  INFO main:         [main:matterbridge.go:70] Gateway(s) started succesfully. Now relaying messages
[0004] ERROR whatsapp:     [HandleError:bridge/whatsapp/handlers.go:40] message type not implemented
[0004] ERROR whatsapp:     [HandleError:bridge/whatsapp/handlers.go:40] message type not implemented
[0004] ERROR whatsapp:     [HandleError:bridge/whatsapp/handlers.go:40] message type not implemented
[0004] ERROR whatsapp:     [HandleError:bridge/whatsapp/handlers.go:40] message type not implemented
[0004] ERROR whatsapp:     [HandleError:bridge/whatsapp/handlers.go:40] message type not implemented
[0004] ERROR whatsapp:     [HandleError:bridge/whatsapp/handlers.go:40] message type not implemented
...
42wim commented 3 years ago

@adrianovieira @allilengyi Can you try a dev build from here: ~https://github.com/42wim/matterbridge/actions/runs/506061796#artifacts~ https://github.com/42wim/matterbridge/actions/runs/506180640#artifacts ?

Also if you disable auto-delete on your current, does it actually work?

adrianovieira commented 3 years ago

@adrianovieira @allilengyi Can you try a dev build from here: ~https://github.com/42wim/matterbridge/actions/runs/506061796#artifacts~ https://github.com/42wim/matterbridge/actions/runs/506180640#artifacts ?

Also if you disable auto-delete on your current, does it actually work?

I am no sure how to "disable auto-delete"... give me a tip to setup it, please!

42wim commented 3 years ago

@adrianovieira (I have no idea about the auto-delete, I don't use whatsapp myself)

Can you confirm that no messages get through? Other users are telling me they sometimes also got those messages, but it has no impact, the bridge just works.

adrianovieira commented 3 years ago

$ matterbridge -debug

[0000]  INFO main:         [setupLogger:matterbridge.go:106] Enabling debug logging.
[0000]  INFO main:         [main:matterbridge.go:46] Running version 1.21.0 cf13fff7
2021/01/26 11:48:41 too many open files

$ matterbridge-v1.21.0-12-gb3c0c09b-linux-amd64 -debug

[0000]  INFO main:         [setupLogger:matterbridge/matterbridge.go:106] Enabling debug logging.
[0000]  INFO main:         [main:matterbridge/matterbridge.go:46] Running version 1.21.1-dev b3c0c09b
[0000]  INFO main:         [main:matterbridge/matterbridge.go:48] WARNING: THIS IS A DEVELOPMENT VERSION. Things may break.
2021/01/26 11:48:30 too many open files

another infos:

$ cat /proc/sys/fs/file-max                                                                
9223372036854775807

$ ulimit -Hn               
524288

$ ulimit -Sn
1024
42wim commented 3 years ago

@adrianovieira how many bridges / gateways do you have ?

adrianovieira commented 3 years ago

I think they are two

RocketChat (inout to one channel) WhatsApp (inout to one group)

This is what I have so far.

adrianovieira commented 3 years ago

Hi concerning to "open files" comment, I don't know why it happen or how to reproduce it.

So, maybe you can ignore it!

gpopesc commented 3 years ago

The same error here related to whatsapp-telegram like the first person who opened the issue. Attached the log.

level=error msg="message type not implemented" prefix=whatsapp

I get the messages from telegram in whatsapp, but no the other way around.

Running on Synology, docker latest version of matterbridge 1.22.

The same error I got with version 1.21

I tested earlier the integration without whapsapp, among mattermost, matrix and telegram integration and all are working fine.

_matterbridge_matterbridge_1_logs.txt

Later edit: solved: I tested in first phase with my number. Telegram doesn't send the messages to whatsapp bot (my number in this case), which is somehow obviously.

42wim commented 3 years ago

@gpopesc you fixed the issue?

gpopesc commented 3 years ago

yes, it is fixed. everything is working fine. I would call the errors as standard, the relay is working fine. I still have them in log, but I think the last message is important: Gateway(s) started succesfully. Now relaying messages
When I tested I used my phone number (I haven't any spare sims) and I didn't get the messages back on whatsapp, it was misleading.