Wechat (微信) Matrix Application Service Bridge
Image credit: Gnosis
Matrix is an open network for secure, decentralized communication, which can be used similarly to Pidgin on your phone.
Pidgin tries to have all your friends in one place in Linux, regardless of what IM they use. With Matrix you can have your phone client connected to your private server which can all be highly customized. Matrix does not use the XMPP protocol, it uses a REST API so that it could be easier to extend.
The [Matrix] client Element is a universal secure chat app entirely under your control. It supports desktop (Windows, Mac and Linux) and mobile (Android and iOS)
matrix-appservice-wechaty
matrix-appservice-wechaty
is a WeChat (微信) Matrix AppService for bridging your WeChat groups to Matrix rooms.
It has been officially listed at [Matrix] Bridge Page for Wechaty.
According to Types of Bridging, the Matrix Wechaty Bot implements a Simple Puppeted Bridge with Portal Rooms because we want to bring all conversations from WeChat to Matrix, and let the Matrix user control his account on Wechat.
sudo npm install -g matrix-appservice-wechaty
matrix-appservcie-wechaty
is all you need.
config.yaml
Copy config/config.sample.yaml to config.yaml
and update it to match your setup.
domain
needs to change to your domain name, which should point to your homeserver.homeserverUrl
needs to change to your homeserver url, with the port number included.registration
needs to change to your registration yaml file name (see next part for how to generate it)wechaty-registration.yaml
After we setup the config.yaml
, then we can generate the wechaty-registration.yaml
file for registering the appservice to the homeserver:
export APP_SERVICE_ENDPOINT='http://localhost:8788'
matrix-appservice-wechaty \
--config config.yaml \
--url "$APP_SERVICE_ENDPOINT" \
--generate-registration
Note: The URL APP_SERVICE_ENDPIOINT
is used by the home server to communicate with the appservice, in this example is: http://localhost:8788
. If you have other appservices, or other requirements, pick an appropriate hostname and port.
Edit your homeserver.yaml
file and update the app_service_config_files
entry with the path to the wechaty-registration.yaml
file.
app_service_config_files: ["/data/wechaty-registration.yaml"]
You will then need to restart the synapse server.
For docker users:
export SYNAPSE_CONTAINER_ID=$(docker ps | grep synapse | awk '{print $1}')
docker restart $SYNAPSE_CONTAINER_ID
Or if you are not using docker:
synctl restart
Remember to restart it every time the registration file is updated.
Let's start the matrix-appservice-wechaty
bridge, with the port specified in wechaty-registration.yaml
(8788
in the above example)
export WECHATY_PUPPET=wechaty-puppet-padplus
export WECHATY_PUPPET_PADPLUS_TOKEN=xxxxxxxxxxxxxxxxxxxxx
matrix-appservice-wechaty \
--config config.yaml \
--file wechaty-registration.yaml
Note: Wechaty is a very powerful framework that supporting Web, iPad, Win32, Mac, iOS protocols of WeChat. Learn more about WeChaty protocols at our Wechaty Puppet Directory, and you can apply for a token for using wechaty-puppet-padplus at our Support Developers Program
The bridge should start working shortly afterwards.
The current path ($(pwd)
) should have the wechaty-registration.yaml
file and config.yaml
file. Additional bridge-related data will be stored here.
wechaty-registration.yaml
id: wechaty
hs_token: 4f2763d5cc6e931967ec89efdde1123772945184b4cbe99e8fa9538122015e92
as_token: c27815bdd699d2eaefb499c83f99ce1a7983a9688811269fbcc17b632b0b250e
namespaces:
users:
- exclusive: true
regex: '@wechaty_.*'
aliases:
- exclusive: true
regex: '#wechaty_.*'
rooms: []
url: matrix.chatie.io:8788
sender_localpart: wechaty
rate_limited: false
protocols:
- wechaty
config.yaml
domain: chatie.io
homeserverUrl: https://matrix.chatie.io
registration: wechaty-registration.yaml
We have published a docker image wechaty/matrix-appservice for your convenience.
You can use docker to run matrix-appservice-wechaty bridge by adding the following configs to your docker-compose.yml
matrix-appservice-wechaty:
container_name: matrix-appservice-wechaty
image: wechaty/matrix-appservice
volumes:
- ./bridges/matrix-appservice-wechaty:/data
networks:
- default
environment:
- WECHATY_PUPPET_PADPLUS_TOKEN=puppet_padplus_<token>
- WECHATY_PUPPET=wechaty-puppet-padplus
command: ["--config", "/data/config.yaml", "--file", "/data/wechaty-registration.yaml", "--port", "8788"]
@wechaty:your.domain.ltd
)!login
(three times... wip... )wechaty
app service bot will then send you a QR Code for scanning on WeChat.After you have scanned the QR Code and confirmed it on your phone, everything will be setup automatically by the wechaty bot.
!login
Simply run the !logout
management command.
By following the guide from @spantaleev, you can set your matrix server up just in dozens of minutes.
Detail steps to setup the Matrix server from https://github.com/spantaleev/matrix-docker-ansible-deploy/blob/master/docs/README.md
This week I had a great talk with YC partner Eric @ericmigi, who is a serial entrepreneur and also a geek with technology. He uses Matrix a lot and almost integrated all the instance messanger to his Matrix.
But, the matrix does not support Wechat yet. So we'd like to introduce a matrix-wechat bridge to implement the Wechat protocol, and fill the gap between Matrix and Wechat.
@ericmigi provide some links that will help us to kick off a starter, hope we could make a workable POC soon, and any contribution will be welcome.
— Huan, April 2019
@tulir has very rich experiences with building the matrix bridges such as:
— Huan, May 2019
Finished Display user's nickname and avatar in group #66 and Support image and file messages #86.
Finished #13: [TypeScript] Add typing system to matrix-js-sdk
and matrix-appservice-bridge
.
!login
, !logout
command with help messagematrix-appservice-wechaty
by talk to the bot @wechaty:your.domain
@wechaty
, it will send you Wechat Login QR Code. Scan it to login WechatI accept no responsibility if Tencent bans your IP, account or even your details on their system. They have never given official support on custom clients.
— Disclaimer based off: matrix-appservice-discord
Wechaty community has setup the Matrix service(#94) which the server is sponsored by @ericmigi, who is the founder of Beeper, Partner of Y Combinator. He has also founded Pebble Technology (YC W11), which was acquired by Fitbit in 2016.
Learn more about Beeper from Beeper Brings iMessage to Android - No more green bubbles, LG's exit, Android 12, Oneplus and Oppo
[Matrix] Server Admin: