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

Whatsapp Support? #475

Closed Tjird closed 4 years ago

Tjird commented 5 years ago

https://github.com/Rhymen/go-whatsapp Maybe useful if you want to implement whatsapp support?

42wim commented 5 years ago

Ok, interesting, api based on reverse engineering. Will not be done by me probably, but if someone implements it, I'll merge it.

jamoffat commented 5 years ago

Ok, interesting, api based on reverse engineering. Will not be done by me probably, but if someone implements it, I'll merge it.

I'd be interested in seeing this developed if anyone felt inclined to do so; I can offer limited help in testing too. It would be pretty cool to get WhatsApp bridged! :)

patcon commented 5 years ago

Thanks for the feedback @jamoffat. We're tracking this is the linked mega-issue, so I think we'll prob close this out until someone is working on it :) cc @42wim

42wim commented 5 years ago

Also interesting https://github.com/tulir/mautrix-whatsapp for anyone that wants to make a PR.

KrzysztofMadejski commented 5 years ago

@42wim I'm giving it a try.

I'm slowly moving forward:

Handle messages

EDIT: @patcon added links to spun out issues

42wim commented 5 years ago

@KrzysztofMadejski Great! Feel free to ask any questions here or on the chat, I'll try to respond, could be some delay though.

The gitter bridge is probably the easiest to start from, you'll need to implement the Bridger interface https://github.com/42wim/matterbridge/blob/2cfd880cdb0df29771bf8f31df8d990ab897889d/bridge/bridge.go#L11-L16

And then add your bridge to gateway/bridgemap/bridgemap.go

KrzysztofMadejski commented 5 years ago

I managed to receive the message from WhatsApp and send it out (I copied code from Gitter message handling). I have a connected channel on Slack, but the message didn't arrive there.

Am I missing any fields?

time="2019-02-11T17:48:05+01:00" level=debug msg="<= Sending message from 48remotenumber@s.whatsapp.net on whatsapp.cfall to gateway" prefix=whatsapp
time="2019-02-11T17:48:27+01:00" level=debug msg="<= Message is config.Message{Text:"Bla", Channel:"mygroup@g.us", Username:"48remotenumber@s.whatsapp.net", UserID:"48remotenumber@s.whatsapp.net", Avatar:"", Account:"whatsapp.cfall", Event:"", Protocol:"", Gateway:"", ParentID:"", Timestamp:time.Time{wall:0x0, ext:63685500474, loc:(*time.Location)(0x2319220)}, ID:"7D5824A0570F2CBE19C1B775A5616A84", Extra:map[string][]interface {}(nil)}" prefix=whatsapp

Logs related to Slack connection looks ok:

time="2019-02-11T17:47:46+01:00" level=debug msg="== Receiving event &slack.ConnectingEvent{Attempt:1, ConnectionCount:0}" prefix=slack
time="2019-02-11T17:47:46+01:00" level=debug msg="Unhandled incoming event: *slack.ConnectingEvent" prefix=slack
time="2019-02-11T17:47:46+01:00" level=info msg="Gateway(s) started succesfully. Now relaying messages" prefix=main
time="2019-02-11T17:47:46+01:00" level=debug msg="== Receiving event &slack.ConnectedEvent{ConnectionCount:0, Info:(*slack.Info)(0xc00012e160)}" prefix=slack
time="2019-02-11T17:47:47+01:00" level=debug msg="Start listening for Slack messages" prefix=slack
42wim commented 5 years ago

Anything else after this line?

time="2019-02-11T17:48:27+01:00" level=debug msg="<= Message is config.Message{Text:"Bla", Channel:"mygroup@g.us", Username:"48remotenumber@s.whatsapp.net", UserID:"48remotenumber@s.whatsapp.net", Avatar:"", Account:"whatsapp.cfall", Event:"", Protocol:"", Gateway:"", ParentID:"", Timestamp:time.Time{wall:0x0, ext:63685500474, loc:(*time.Location)(0x2319220)}, ID:"7D5824A0570F2CBE19C1B775A5616A84", Extra:map[string][]interface {}(nil)}" prefix=whatsapp ?

You need to specify the correct channel otherwise it won't get relayed. So the mygroup@g.us should be set as channel in your [gateway.inout] for whatsapp.

KrzysztofMadejski commented 5 years ago

I'll check that, thanks.

Is it OK that gateway is empty? Will it be filled in during the message relay? I couldn't find a property to take it from.

pon., 11 lut 2019, 20:55: Wim notifications@github.com napisaΕ‚(a):

Anything else after this line?

time="2019-02-11T17:48:27+01:00" level=debug msg="<= Message is config.Message{Text:"Bla", Channel:"mygroup@g.us", Username:" 48remotenumber@s.whatsapp.net", UserID:"48remotenumber@s.whatsapp.net", Avatar:"", Account:"whatsapp.cfall", Event:"", Protocol:"", Gateway:"", ParentID:"", Timestamp:time.Time{wall:0x0, ext:63685500474, loc:(*time.Location)(0x2319220)}, ID:"7D5824A0570F2CBE19C1B775A5616A84", Extra:map[string][]interface {}(nil)}" prefix=whatsapp ?

You need to specify the correct channel otherwise it won't get relayed. So the mygroup@g.us should be set as channel in your [gateway.inout] for whatsapp.

β€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/42wim/matterbridge/issues/475#issuecomment-462470876, or mute the thread https://github.com/notifications/unsubscribe-auth/AAz4N5yqtYkjvu-jGvwgHG--b1MgaWn7ks5vMcq1gaJpZM4Vu22P .

42wim commented 5 years ago

Yup, it will be filled in. Great job btw! πŸ‘

KrzysztofMadejski commented 5 years ago

You need to specify the correct channel otherwise it won't get relayed. So the mygroup@g.us should be set as channel in your [gateway.inout] for whatsapp.

Yes, that solved the problem!

I got first message in and out, so that calls for a celebration and a commit: https://github.com/42wim/matterbridge/compare/master...KrzysztofMadejski:feature_475/whatsapp :)

slack-msg wa-msg

And when I set RemoteNickFormat in settings the username was properly shown in Slack instead of the app name.

KrzysztofMadejski commented 5 years ago

Moved a little bit forward:

chat-wa chat-slack


Now I plan to test it with friends.

I'm wondering @42wim what is your deployment strategy. Release early experimental features, or do you have some minimal set of features that I should implement?

I'm sending a PR request to get some feedback on the code, conventions, etc. It is my first Go program assembled, so all feedback is welcomed.

42wim commented 5 years ago

Minimal set of features is sending and receiving messages working, and you've got that covered already. So after review of your PR it can be merged :)

KrzysztofMadejski commented 5 years ago

Documentation of the whole process extracted here: https://github.com/42wim/matterbridge/wiki/Gateway:-developing-new-one

patcon commented 5 years ago

haha amazing. You are so F*CKING META[L] @KrzysztofMadejski :)

42wim commented 5 years ago

@KrzysztofMadejski thanks for the wiki addition πŸ‘ Regarding to RemoteNickFormat question in your wiki page, you can't set a default. The bridge doesn't handle this, the default RemoteNickFormat for every bridge is empty string. It needs to be specified as a [general] setting in the config or a specific one for each bridge.

KrzysztofMadejski commented 5 years ago

Thanks for merging the PR in @42wim ! Really appreciate the help.

I'm thinking about leaving this issue till most of the checkboxes/features in my first post above are implemented for WhatsApp. Still, if you prefer I can divide this issue into several one-checkbox one-issue.

42wim commented 5 years ago

You're welcome! Keeping it open here is fine by me.

wsdjeg commented 5 years ago

Any guide or tips for bridged whatsapp group? I also want to have a try with this feature. BTW is it possible send message by bot api instead of a real whatsapp account, as I have only one whats app account.

patcon commented 5 years ago

@wsdjeg unfortunately, no such thing as a readily available bot account, just the business api for "medium and large" businesses, which is hard to get access to: https://www.whatsapp.com/business/api

(Google around and you should find more details on this situation if you're curious.)

KrzysztofMadejski commented 5 years ago

@wsdjeg just get a new sim card and treat it as a bot account. Create groups with this new account (so your personal number won't be shared), add your personal account and give it admin so you can personally invite new people. I got a sim card + spare phone which are lying Wifi + power cord connected at my home (with some cheap data plan in case of Wifi breaking).

WhatsApp business API would be a separate bridge, an option available only when they fully open API.

wsdjeg commented 5 years ago

I just use new sim card. add Join the group. but get a lot error. see https://github.com/42wim/matterbridge/issues/734#issuecomment-466783501

so what I miss? I should add admin promise to the bot?

poVoq commented 5 years ago

https://blog.whatsapp.com/10000649/WhatsApp-for-JioPhone-on-KaiOS?l=en

Could be an interesting new way. This must be basically a lightweight and standalone HTML5 client, as this phone runs a form of KaiOS (FirefoxOS).

I wonder if it can at least be run on a more leightweight browser emulating nodejs if it allows to link to whatapp web...

KrzysztofMadejski commented 5 years ago

@poVoq I don't understand what problem do you want to solve..

poVoq commented 5 years ago

Assuming this can also be used together with WhatsApp web, this could be a much more lightweight system to run in a container on the server so that you can remove WhatsApp completely from any phone you own.

KrzysztofMadejski commented 5 years ago

Could you give an example/documentation of KaiOS run on a VirtualEnv/docker/other virtualization . Also: How the graphical interface could be accessed then?

poVoq commented 5 years ago

KaiOS is a fork of FirefoxOS, thus basically a glorified browser and this app is most likely a HTML5 / Javascript application. Edit: https://ftp.mozilla.org/pub/labs/fxos-simulator/ https://developer.mozilla.org/en-US/docs/Archive/B2G_OS/Simulator (Which is a plugin for Firefox)

Graphical interface for doing the QR code link? I guess similar to how people do it with the Android VMs on their servers right now?

JoKeyser commented 4 years ago

@KrzysztofMadejski thanks a lot for your efforts, I got it working!

As a noob to matterbridge, I was initially confused about two things: 1) What is the QR-code about, and 2) how to set the WA-channel in the configuration file of matterbridge? Below are my answers. Also, here is a good explanation how to use an android-VM: https://github.com/tulir/mautrix-whatsapp/wiki/Android-VM-Setup

  1. The QR-Code is created by matterbridge on the terminal: It's the way Whatsapp authenticates any WA-Web session (which the bridge is using). At startup, matterbridge will prompt a QR-code for about 1 minute that you have to scan from your WA-instance (on your phone or android-VM). To scan it, go to Settings > Whatsapp Web in your WA client (if you run a VM, you may need to connect your webcam, or make a virtual one, see link above):

Screenshot_1567344079

  1. To setup a gateway between two protocols in matterbridge, you need to specify a channel for WA that should be bridged. The chat/group titles you see in WA won't work (e.g. from the screenshot above, "Test" won't work). Fortunately, matterbridge will complain about improper channel names and suggest the correct ones to you. In my case, it was a string of mainly numbers including the phone number of who created the group chat. Maybe there is a way to get this out of WA? (Currently, the WA example config does not explain this at all; it doesn't even mention the gateway part.)
AJ-and-Proxy-Bot commented 4 years ago

Is this still being developed on and is it working? If it is, how do I set it up with discord? And would it be hard to make nicknames for the users?

patcon commented 4 years ago

Thanks for asking @AJ-and-Proxy-Bot, but your message made me (as a general contributor to project, but no one special) realize that this issue might be ready to be closed, as the integration exists.

Since this has been open for a bit, could remaining tasks (like documentation, and new features) move into a new issue to clarity, @42wim or @KrzysztofMadejski? If you :+1:, I'm happy to do the gruntwork :)

patcon commented 4 years ago

@AJ-and-Proxy-Bot as for your specific question, Discord and whatsapp should be bridgeable by following the docs in the wiki. if you hit troubles (or have questions about nicknames, etc.) then the matterbridge chat rooms (see readme) might be the best place πŸ˜„ (i don't know the answer myself, sorry!)

KrzysztofMadejski commented 4 years ago

could remaining tasks (like documentation, and new features) move into a new issue to clarity,

Yes, it will be a lot more clear. It was long due., thanks for a reminder @patcon I'll do that.

KrzysztofMadejski commented 4 years ago

I spun smaller sub-issues out of this one. I also updated https://github.com/42wim/matterbridge/wiki/Section-WhatsApp-(basic) with @poVoq and @JoKeyser suggestions.

@42wim could you close this issue?

hlesueur commented 4 years ago

Hello, Thanks a lot for developing this ! I'm completely new to all this stuff, and I'm stuck at a very basic step: getting the QR code displayed

I'm on windows, and run from a cmd prompt the following command: matterbridge.exe -conf matterbridge.toml

the conf file is set properly I think because I get connection succeded and so on... But the QR code is dsplayed in the console, in a totally unreadable way (pixels are way too big, the QR code is larger than the window size)

I tried to get it work in python (jupyter) by getting the stdout from the same command line, and formatting a QR code with the qrcode library, but I cannot find a proper way to format the QR code (whatsapp refuses it, I obviously get it wrong) seems to me it is 52 colums by 51 lines, which already sounds weird

Is there a tuto? a graphical interface for windows? an option for the console? Thanks for your help

patcon commented 4 years ago

Sorry you're having trouble..! Not knowing anything about using windows consoles, I might suggest using Vagrant+VirtualBox to run inside a linux virtual machine πŸ€·β€β™‚οΈ

Barring any other windows-specific suggestions, would this feel accessible to you?

hlesueur commented 4 years ago

Thanks a lot for answering so fast! Well, I feel ashamed, the answer was in fact quite simple, I put it here for potential windows users: you simply have to increase the size of the console window (in the console properties), and/or decrease the font size such that the whole QRcode appears...

(I spent the last few hours trying to implement the python version... gargl) :-)

patcon commented 4 years ago

No prob. And yeah, good call on sharing back for future travellers :) glad you got it sorted!

mujeebcpy commented 3 years ago

hai it is a wonderful implimentation. i faced two issues while trying this, first the qr code was too large. then i zoomed out the terminal a lot and bypass the issue. second is difficulty of accessing group JID. had to take it from console. if any command in whatsapp group return the JID it will be greate for building something on this

emesika commented 3 years ago

Hi guys

I am trying to use matterbridge to sync 2 whatsapp groups

The XXXXXXXXX is a mask of my phone number used

My config file looks like :

[whatsapp.mywhatsapp] Number="+XXXXXXXXX" SessionFile="session-48111222333.gob" QrOnWhiteTerminal=false RemoteNickFormat="[{PROTOCOL}] @{NICK}: "

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

[[gateway.inout]] account="whatsapp.mywhatsapp" channel="XXXXXXXXX-1604163847@g.us"

[[gateway.inout]] account="whatsapp.mywhatsapp" channel="XXXXXXXXX-1604177317@g.us"

command

./matterbridge -conf matterbridge.toml -debug

output:

[0000] INFO main: [setupLogger:matterbridge.go:106] Enabling debug logging. [0000] INFO main: [main:matterbridge.go:46] Running version 1.19.0 2bb21262 [0000] INFO router: [Start:gateway/router.go:66] Parsing gateway gateway1 [0000] INFO router: [Start:gateway/router.go:75] Starting bridge: whatsapp.mywhatsapp [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.. [0002] DEBUG whatsapp: [Connect:bridge/whatsapp/whatsapp.go:96] Session restored successfully! [0003] INFO whatsapp: [joinChannels:bridge/bridge.go:77] whatsapp.mywhatsapp: joining XXXXXXXXX-1604163847@g.us (ID: 972547788316-1604163847@g.uswhatsapp.mywhatsapp) [0003] DEBUG whatsapp: [func1:bridge/whatsapp/whatsapp.go:126] Getting user avatars.. [0003] INFO whatsapp: [joinChannels:bridge/bridge.go:77] whatsapp.mywhatsapp: joining XXXXXXXXX-1604177317@g.us (ID: 972547788316-1604177317@g.uswhatsapp.mywhatsapp) [0003] INFO main: [main:matterbridge.go:70] Gateway(s) started succesfully. Now relaying messages [0067] DEBUG whatsapp: [func1:bridge/whatsapp/whatsapp.go:138] Finished getting avatars..

But when I am sending message from 1 group I got nothing on the other and vice versa I a connected to the whatsapp web with the QR code from the terminal

What am I missing here ?

thanks