Rewrite

Rewrite

努力学习的前端小菜鸡(:з」∠)_
github
telegram

Use Telegram to send and receive WeChat messages

Introduction to EH Forwarder Bot#

EH Forwarder Bot (EFB) is an extensible message tunneling chatbot framework that can transfer messages between multiple platforms and remotely control your accounts.

In short, this project is used to forward WeChat messages to Telegram. However, using EFB alone is not enough. To achieve sending and receiving WeChat messages through Telegram, you also need efb-telegram-master(ETM) and efb-wechat-slave(EWS).

Official Documentation Official Wiki

Instructions for Use#

  1. Your WeChat account needs to be able to log in to the WeChat Web. If you are unable to log in, then you may need to give up.
  2. There have been reports of WeChat Web logins being banned by Tencent since mid-2017. The following is a quote from a user:

Since mid-2017, there have been reports of WeChat Web logins being banned by Tencent. The prompt for any attempt to log in to WeChat Web is "The current login environment is abnormal. For the security of your account, Web WeChat cannot be logged in temporarily. You can log in through the mobile client or Windows WeChat." Most users are unblocked within one day to three months after being banned, and the time it takes to unblock varies for different users. According to observations, only less than 10% of users are banned during use. This ban does not affect logins from other clients. The reason for the ban is currently unclear.

At the same time, there is evidence that new WeChat users registered since mid-2017 cannot use WeChat Web. Before using it for the first time, please visit WeChat Web and confirm that you can use this feature normally. If your account cannot use this feature, please try using another account.

If you have requirements for WeChat Web login, please use this channel with caution. For more information, please refer to issue #7.

Deployment Tutorial#

Deploying the service requires a complete Linux system as a server. The following example uses a Debian-based distribution.

Applying for a Telegram bot#

  • Start a conversation with @BotFather in Telegram.
  • Send /newbot to create a bot, during which you need to specify the name and username of the bot (the username should end with "bot").
  • After creation, @BotFather will provide you with an HTTP API in the form of a string of numbers and letters, such as 123123123:WERGadsgaeDFGAwetfGq. Save it for future use.

Please note that to protect your privacy and information security, do not provide your bot username and key to anyone, as this may lead to various risks such as chat information leakage.

Further configuration is required after completion.

  • Send /setprivacy to @BotFather, select the username of the bot you just created, and then select "Disable".
  • Send /setjoingroups to @BotFather, select the username of the bot you just created, and then select "Enable".
  • Send /setcommands to @BotFather, select the username of the bot you just created, and then send the following content:
help-Display the command list.
chat-Generate a chat header.
rm-Delete a message from its remote chat.
link-Link a remote chat to a group.
unlink_all-Unlink all remote chats from the group.
info-Display information about the current Telegram chat.
extra-Access additional features from the channel.
update_info-Update information for the linked Telegram group.

At this point, the Telegram bot is created. If you want to set an avatar for the bot, you can use the /setuserpic command.

Obtaining Telegram ID#

Search for @userinfobot on Telegram and click /start to obtain your Telegram ID, a string of numbers (Chat ID).

Getting Started with Deployment#

First, you need a VPS with a Debian-based distribution, or a device that can install a complete Linux system, has 24-hour uninterrupted power supply, and a stable network connection to serve as the server for deployment.

For example, a Raspberry Pi, or an Android phone with root access that can install a Linux distribution using Linux Deploy. In theory, you can also use Termux to install a complete Linux environment for deployment without root access. (No nesting allowed.)

In addition, your server needs to be able to access the Internet, as Telegram requires external access. If your server cannot access the Internet, ETM can also allow us to specify a proxy for running. This will be mentioned later.

Installing Dependencies#

  • All the following commands need to be executed as the root user or with sudo.
# Update first
apt update -y && apt upgrade -y
# Install the required dependencies and tools
apt install python3 python3-pip python3-setuptools python3-yaml ffmpeg  libcairo2-dev libcairo2 -y

Installing the Main Components#

pip3 install ehforwarderbot efb-telegram-master efb-wechat-slave
pip3 install --upgrade Pillow
# Optional plugin, allows sending Telegram stickers to WeChat, recommended to install
pip3 install "efb-telegram-master[tgs]"

EFB Configuration File#

Create /etc/ehforwarderbot/profiles/wechat/config.yaml and write the following content:

master_channel: blueset.telegram
slave_channels:
- blueset.wechat
# The flags section is for experimental features. For more features, please refer to the documentation: https://github.com/ehForwarderBot/efb-wechat-slave#experimental-features
flags: 
  delete_on_edit: true
  # Replace edited messages with revoked and re-sent messages

ETM Configuration File#

Create /etc/ehforwarderbot/profiles/wechat/blueset.telegram/config.yaml and write the following content:

token: "" # Fill in the API you obtained from botfather between the ""
admins:
- 1234 # Change the number to your personal Telegram ID obtained earlier
#- 1279136259 # If you want multiple Telegram accounts to be able to use it, you can add a second or multiple IDs here, removing the #
# The flags section is for experimental features. For more features, please refer to the documentation: https://github.com/ehForwarderBot/efb-telegram-master#experimental-flags
flags:
  send_image_as_file: true
  # Send all image messages as files to prevent active message image compression. If you need more traffic, you can turn it off and change it to false.
  animated_stickers: true
  # Enable experimental support for animated stickers. This dependency is included in the tutorial dependencies.
  default_media_prompt: text
  # Placeholder text for image/video/file messages without a title.

Note! If your server cannot access the Internet, you can specify a proxy specifically for ETM! Just add the following content to the bottom of the /etc/ehforwarderbot/profiles/wechat/blueset.telegram/config.yaml file:

request_kwargs:
    # ...
    proxy_url: http://PROXY_HOST:PROXY_PORT/
    # Optional, if you need authentication:
    username: PROXY_USER
    password: PROXY_PASS

The above is for HTTP proxies. If you need a SOCKS5 proxy, you need an additional Python package:
pip install python-telegram-bot[socks]
Then use the following content:

request_kwargs:
    # ...
    proxy_url: socks5://URL_OF_THE_PROXY_SERVER:PROXY_PORT
    # Optional, if you need authentication:
    urllib3_proxy_kwargs:
        username: PROXY_USER
        password: PROXY_PASS

At this point, all the required programs and configuration files are ready, and the remaining task is process management.

Creating a systemd Service#

Create /etc/systemd/system/efb@.service and write the following content:

[Unit]
Description=EFB instance for profile %i
Documentation=https://github.com/blueset/ehForwarderBot
Wants=network-online.target
After=network-online.target

[Service]
PrivateTmp=true
ExecStart=/usr/bin/python3 -m ehforwarderbot -p %i
Environment=EFB_DATA_PATH=/etc/ehforwarderbot LANG=zh_CN.UTF-8
TimeoutStopSec=10
Restart=on-failure

[Install]
WantedBy=multi-user.target

Running#

Use systemctl start efb@wechat to start the service.
Use journalctl -u efb@wechat -e to view the output. Open the QR code link at the bottom and scan it with WeChat.
Use systemctl enable efb@wechat to enable auto-start on boot.

Conclusion#

At this point, the entire service has been set up. It's great to send and receive WeChat messages on Telegram, with access to Telegram's extensive sticker collection. Now no one can beat me in WeChat battles (lol).

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.