English | 中文
This project forwards WeChat messages to a Telegram bot, based on wechaty.
By using puppet-wechat4u (which implements the UOS protocol), it
circumvents the login issue with the WeChat Web version.
- Forwards individual WeChat chat messages, group messages, and public account messages to Telegram.
- Allows Telegram to reply to specific WeChat users.
- Supports blacklisting and whitelisting modes for group chats.
- Supports sending videos, files, stickers, images, and voice messages.
- By configuring
API_ID
andAPI_HASH
, it can automatically create a group chat for forwarding.
- This project is for research and educational purposes only. It should not be used for illegal activities.
- Feel free to submit issues for any problems encountered.
- Due to Telegram Bot API limitations, files larger than 20MB cannot be sent, and files larger than 50MB cannot
be received (this can be resolved by configuring
API_ID
andAPI_HASH
). - This project attempts to support only messages compatible with WeChat Web. Unsupported messages are beyond its capabilities.
- Currently, message loss due to network or technical issues cannot be completely avoided, so please be cautious with important messages!
/login
: Get a login QR code.
/user
: Get a user list with reply options (you can search by name or note, e.g., /user Zhang
will find users with "
Zhang" in their name or notes).
/room
: Get a group list with reply options (you can search by name or note, e.g., /room Takeout
will find groups
with "Takeout" in their name or notes).
/recent
: Get a list of recent users or groups who sent messages, with reply options.
/setting
: Program settings.
BOT_TOKEN
Required: The token for your Telegram Bot, created via BotFather.
Configure a Telegram proxy. Leave fields blank to not use a proxy:
# Proxy configuration (optional)
# Protocol: socks5, http, https
PROXY_PROTOCOL=socks5
PROXY_HOST=
PROXY_PORT=
PROXY_USERNAME=
PROXY_PASSWORD=
docker-compose.yml
file:
version: '3'
services:
wechat2tg:
image: finalpi/wechat2tg:latest
container_name: wx2tg
volumes:
- ./config:/app/storage
- ./save-files:/app/save-files # Stickers won’t need to be re-converted once saved here
# use env file or you can just set environment here
# env_file: ".env"
environment:
BOT_TOKEN: ''
# PROXY_HOST: ''
# PROXY_PORT: ''
# Proxy type: socks5, http, https
# PROXY_PROTOCOL: 'socks5'
# Username and password (optional)
# PROXY_USERNAME: ''
# PROXY_PASSWORD: ''
# Telegram API configuration for sending large files (optional)
# API_ID: ''
# API_HASH: ''
# Group message format
ROOM_MESSAGE: '<i>🌐#[topic]</i> ---- <b>👤#[(alias)] #[name]: </b>'
# Official account message format
OFFICIAL_MESSAGE: '<b>📣#[name]: </b>'
# Contact message format
CONTACT_MESSAGE: '<b>👤#[alias_first]: </b>'
# Group message format (in groups)
ROOM_MESSAGE_GROUP: '<b>👤#[(alias)] #[name]: </b>'
# Official account message format (in groups)
OFFICIAL_MESSAGE_GROUP: '<b>📣#[name]: </b>'
# Contact message format (in groups)
CONTACT_MESSAGE_GROUP: '<b>👤#[alias_first]: </b>'
restart: unless-stopped
Run
docker-compose up -d
docker run -itd --env BOT_TOKEN="" --env PROXY_HOST="" --env PROXY_PORT="" --env PROXY_USERNAME="" --env PROXY_PASSWORD="" --env PROXY_PROTOCOL="socks5" finalpi/wechat2tg:latest
-
Install dependencies:
npm install
-
Configure the Telegram Bot's token and proxy information in the
.env
file. -
Run the program:
npm start
-
In Telegram, send
/start
to the bot to begin, or/login
to log in.
Switch between blacklist mode and whitelist mode:
Whitelist Mode - Only accept messages from groups in the whitelist.
Blacklist Mode - Do not accept messages from groups in the blacklist.
Send Success Feedback: Whether to display a message send status feedback (leave off if not necessary, since failures will prompt by default).
Automatic Contact Switching: Automatically switches to the user or group who last replied. Note: If a message is received right before sending, it could result in sending to the wrong recipient!
Receive Public Account Messages: Whether to receive messages from public accounts.
Forward Self-Sent Messages: Whether to forward messages you send using the WeChat mobile client.
Media Compression: If enabled, all received media messages will be processed as images or videos, which may reduce the original quality. If disabled, all messages will be received as files.
Messages can be recalled within 2 minutes by replying to your own message with &rm
. Media messages can only be
recalled after the message has been successfully sent.
Due to Telegram Bot API limitations, files larger than 20MB cannot be sent, and files larger than 50MB cannot be
received. If you need to send or receive larger files, configure API_ID
and API_HASH
.
Note: Testing showed that the web protocol returns an error when sending files over 25MB using chunked uploads. (This has been fixed in the project.)
To get API_ID
and API_HASH
:
-
Log in to your Telegram account.
-
Click "API development tools" and fill in your application details (only the app title and short name are required).
-
Click "Create application" to complete.
Note: Since wechaty-puppet-wechat4u
changes the ID with each login,
there's no way to get a unique key for each contact and group.
Whether a contact or group is the same is determined by the contact's note and nickname.
If these aren't unique, or if their name changes, it may lead to incorrect binding after relogin.
In such cases, re-binding will be required.
- Disable the bot's privacy mode. Open BotFather, type
/mybots
, select your bot, clickBot Settings
-Group Privacy
-Turn off
. If you see "Privacy mode is disabled for xxx", it was successful. - Create a Telegram group, add the bot to it, and follow the prompts to bind contacts or groups. After binding, messages from those contacts or groups will be forwarded to the group.
/bind
: View the current group’s bound contacts or groups.
/unbind
: Unbind contacts or groups from the current group.
/cgdata
: Set the group’s avatar and nickname to match the corresponding WeChat contact or group (requires admin
rights).
- Configure
API_ID
andAPI_HASH
. - Disable the bot's privacy mode.
- Use the
/autocg
command to enable automatic grouping, and follow the prompts to log in to Telegram.
If you want to modify the sender's format, you can change the environment variables in docker or the .env
file.
Custom message template placeholders:
#[alias]
: Contact note.
#[name]
: Contact nickname.
#[topic]
: Group chat nickname.
#[alias_first]
: Note first; if there’s no note, the contact's nickname will be shown.
Thanks to JetBrains for supporting this project.