English | 中文
This project, based on wechaty , enables sending and receiving WeChat messages through Telegram.By utilizing puppet-wechat4u (which uses the UOS protocol), it bypasses the restriction preventing certain accounts from logging into the WeChat Web version.
-
Forward single chat, group chat, and official account messages from WeChat to a Telegram bot.
-
Send messages from Telegram to specific WeChat users, groups, or official accounts.
-
Support for setting group chat blacklists or whitelists.
-
Send videos, files, stickers, images, and voice messages from Telegram.
-
Support message recall.
-
Automatically create forwarding groups by configuring
API_ID
andAPI_HASH
for message grouping. -
Voice-to-text conversion for WeChat voice messages.
-
ChatGPT automatically replies to chat messages in WeChat groups or WeChat users.
- Text messages (emojis within text can be converted to Telegram emojis, but many mappings are not available)
- Non-official stickers
- Image messages
- Audio/Video calls (only message notifications)
- File messages
- Voice messages
- Message recall
- Link messages
- Mini program messages (partially supported)
- Location messages (converted to location text)
- Red packet messages (notification only, cannot retrieve red packet content)
- Group chat messages
- Group chat @ messages (@all and @you will be converted to Telegram @you)
- Official account messages
- Store stickers
- Messages sent by WeChat Work users
-
This project is for technical research and learning purposes only and must not be used for illegal purposes.
-
Feel free to submit issues for any problems you encounter.
-
Due to Telegram Bot API limitations, it cannot send files larger than 20MB or receive files larger than 50MB (this limitation can be resolved by configuring API_ID and API_HASH).
-
This project attempts to support message types allowed by the WeChat Web protocol. Unsupported types, such as native WeChat stickers and red packets, are not available.
-
Message loss might occur due to network or technical issues. For critical messages, proceed cautiously!
Create a docker-compose.yml
file:
version: '3'
services:
wechat2tg:
image: finalpi/wechat2tg:latest
container_name: wx2tg
volumes:
- ./config:/app/storage
- ./save-files:/app/save-files # Saves converted files to avoid re-conversion for stickers
# 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'
# Optional username and password
# PROXY_USERNAME: ''
# PROXY_PASSWORD: ''
# Telegram API configuration for sending large files (optional)
API_ID: ''
API_HASH: ''
# Group message formats
ROOM_MESSAGE: '<i>🌐#[topic]</i> ---- <b>👤#[(alias)] #[name]: </b>'
OFFICIAL_MESSAGE: '<b>📣#[name]: </b>'
CONTACT_MESSAGE: '<b>👤#[alias_first]: </b>'
ROOM_MESSAGE_GROUP: '<b>👤#[(alias)] #[name]: </b>'
OFFICIAL_MESSAGE_GROUP: '<b>📣#[name]: </b>'
CONTACT_MESSAGE_GROUP: '<b>👤#[alias_first]: </b>'
CREATE_ROOM_NAME: '#[topic]'
CREATE_CONTACT_NAME: '#[alias]#[[name]]'
MESSAGE_DISPLAY: '#[identity]#[br]#[body]'
TENCENT_SECRET_ID: ''
TENCENT_SECRET_KEY: ''
# OPENAI
## APIKEY
OPENAI_API_KEY: ''
OPENAI_HOST: 'https://api.openai.com'
OPENAI_MODEL: 'gpt-3.5-turbo'
OPENAI_SYSTEM_PROMPT: ''
OPENAI_MAX_TOKENS: 150
OPENAI_TEMPERATURE: 0.7
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 token and proxy information in the
.env
file. -
Run the program:
npm start
- Send
/start
or/login
to the bot in Telegram to begin.
-
/login
: Retrieve the login QR code. The first person to send this command becomes theBOT
owner. -
/user
: List WeChat users and send messages by clicking their buttons (search by name or alias, e.g.,/user Zhang
for "Zhang"). -
/room
: List WeChat groups and send messages by clicking their buttons (search by name or alias, e.g.,/room Delivery
for "Delivery"). -
/recent
: List recent users or groups with messages for quick replies. -
/settings
: Access settings. -
/bind
: Check group bindings for WeChat users or groups (group-only command). -
/unbind
: Unbind groups from WeChat users or groups (group-only command). -
/order
: Set quick commands for sending preset messages to official accounts. -
/cgdata
: Update group avatar and name (group-only command; admin permissions required). -
/autocg
: Enable auto-grouping mode (requires API_ID and API_HASH; recommended ). -
/check
: Check the current WeChat login status. -
/source
: Retrieve the original file of compressed media by replying with/source
(media-only). -
/aad
: Forward messages from other members within the group. Use the/aad all
command to enable forwarding messages from all members of the group. Alternatively, use/aad @username
to forward messages from a specific user (only supported in groups and requires the auto-create group mode to be enabled). -
/als
: View and manage the forwarding list (only supported in groups and requires the auto-create group mode to be enabled).
Name | Required | Description |
---|---|---|
BOT_TOKEN | Yes | Telegram Bot token from BotFather |
PROXY_PROTOCOL | No | Proxy type (socks5, http, https) |
PROXY_HOST | No | Proxy URL |
PROXY_PORT | No | Proxy port |
PROXY_USERNAME | No | Proxy username |
PROXY_PASSWORD | No | Proxy password |
API_ID | No | Telegram API ID |
API_HASH | No | Telegram API HASH |
ROOM_MESSAGE | No | Group chat message format in the bot |
OFFICIAL_MESSAGE | No | Official account message format in the bot |
CONTACT_MESSAGE | No | User message format in the bot |
ROOM_MESSAGE_GROUP | No | Group chat message format in groups |
CONTACT_MESSAGE_GROUP | No | User message format in groups |
OFFICIAL_MESSAGE_GROUP | No | Official account message format in groups |
CREATE_ROOM_NAME | No | Group name format for auto-created WeChat groups |
CREATE_CONTACT_NAME | No | Group name format for auto-created WeChat contacts |
MESSAGE_DISPLAY | No | Message display format |
TENCENT_SECRET_ID | No | Tencent voice-to-text API Secret ID |
TENCENT_SECRET_KEY | No | Tencent voice-to-text API Secret Key |
-
Switch Between Blacklist or Whitelist Mode
-
Whitelist Mode : Only accepts messages from WeChat groups listed in the whitelist.
-
Blacklist Mode : Does not accept messages from WeChat groups listed in the blacklist.
-
-
Feedback on Message Delivery Indicates whether to provide feedback on the message delivery status. (Recommended to leave it off unless necessary, as failure notifications are shown by default.)
-
Auto-Switch Reply Target Automatically switches the reply target to the WeChat user or group that last sent you a message. Note: Messages sent right after receiving one might be misdirected due to an automatic switch.
-
Receive Official Account Messages Toggles receiving messages from WeChat Official Accounts.
-
Forward Self-Sent Messages Enables forwarding of messages sent via the WeChat mobile client.
-
Media Compression Compresses received media (images, videos) for transmission, potentially losing original quality. If disabled, all media will be sent as files. Replying to a compressed message with
/source
retrieves the original file. -
Auto Voice-to-Text Conversion Converts WeChat voice messages into text.
-
Block Emojis Blocks WeChat emoji messages.
Messages sent within 2 minutes can be recalled by replying &rm
to the message.
Media messages must be successfully sent before recall.
If API_ID
and API_HASH
are configured, deleting a message will also recall it.
Obtaining API_ID
and API_HASH
-
Log in to your Telegram account .
-
Click API development tools and provide basic app details (only title and short name are required).
-
Click Create application to generate the credentials.
Due to Telegram Bot API limitations:
-
Files larger than 20MB cannot be sent.
-
Files larger than 50MB cannot be received. To handle larger files, configure
API_ID
andAPI_HASH
. Note: Web protocol testing shows uploads beyond 25MB may fail. This project includes a fix for this issue.
Important:
Each time wechaty-puppet-wechat4u
re-logs in, IDs change. Group or contact uniqueness is determined by remarks or nicknames.
-
If remarks or nicknames are non-unique, re-binding may be needed after re-login.
-
Changes in contact or group names may also require re-binding. Steps to Manually Bind:
- Disable bot privacy mode:
-
Open BotFather, type
/mybots
, and select your bot. -
Navigate to Bot Settings → Group Privacy → Turn off .
-
Success is indicated by
Privacy mode is disabled for xxx
.
- Create a Telegram group, add the bot, and follow instructions to bind contacts or groups to it.
Commands:
-
/bind
: View current group bindings. -
/unbind
: Unbind the current group. -
/cgdata
: Update group avatar and nickname to match the corresponding WeChat contact or group (requires admin permissions).
-
Configure
API_ID
andAPI_HASH
. -
Disable bot privacy mode.
-
Use the
/autocg
command to enable auto-grouping mode, and follow prompts to log in to Telegram.
-
Configure
TENCENT_SECRET_ID
andTENCENT_SECRET_KEY
(obtainable from Tencent's Speech Recognition Console ). Free usage quota is available. -
Enable auto voice-to-text conversion in
/settings
.
- Configure 'OPENAI_API_KEY'
- Turn on 'Group AI Auto Reply' or 'Contact AI Auto Reply' in '/settings'
You can modify message sender formats via Docker environment variables or the .env
file.
Available placeholders:
-
#[alias]
: Contact's remark. -
#[name]
: Contact's nickname. -
#[topic]
: Group chat name. -
#[alias_first]
: Prioritizes remark; defaults to nickname if no remark. -
#[identity]
: Identity text. -
#[body]
: Message content. -
#[br]
: Line break.
-
Fork the project, switch to the
refactor/ts-single-dev
branch, or create a new branch. Avoid direct commits to themaster
branch. -
Submit a Pull Request to the
refactor/ts-single-dev
branch.
Licensed under the MIT License .
Special thanks to JetBrains for supporting this project!