How to Send Logs and Alerts to WeChat Using wechat_sender

This guide explains how to install, configure, and use the wechat_sender tool—built on wxpy and Tornado—to forward logs, alerts, and scheduled messages from scripts or web services directly to personal or group WeChat chats.

ITPUB
ITPUB
ITPUB
How to Send Logs and Alerts to WeChat Using wechat_sender

Overview

wechat_sender

is a lightweight service built on wxpy and tornado that enables any Python script to send arbitrary messages (logs, alerts, results) to a personal WeChat account. The service runs under a logged‑in personal WeChat bot and exposes a simple API for immediate, delayed, or scheduled messages.

Installation

pip install wechat_sender

Running the Service

Start the bot (QR code login; use console_qr=True on headless servers) and invoke the listener:

from wxpy import *
from wechat_sender import *
bot = Bot()  # QR code login; use console_qr on a server
listen(bot)  # the service now waits for external messages

Sending a Message from Another Script

from wechat_sender import Sender
Sender().send('Hello From Wechat Sender')
# The message is sent via the File Helper of the logged‑in account

Integration with Python Logging

Attach LoggingSenderHandler to any logger to forward log records automatically to WeChat.

import logging
from wechat_sender import LoggingSenderHandler
logger = logging.getLogger(__name__)

def init_logger():
    handler = LoggingSenderHandler('my_app', level=logging.ERROR)
    logger.addHandler(handler)

if __name__ == '__main__':
    init_logger()
    logger.error('An error occurred')

Delayed and Scheduled Messages

Use delay_send to specify a future delivery time and an optional reminder offset.

import datetime
from wechat_sender import Sender
sender = Sender()
future = datetime.datetime.now() + datetime.timedelta(hours=1)
sender.delay_send(content='Test content', time=future,
                 title='Test title', remind=datetime.timedelta(minutes=59))

When the request succeeds, the message arrives at the scheduled time with the given title and content.

Example Use Case: Appointment Monitoring

A Celery task can query an external service (e.g., a corporate physiotherapy booking system) every minute. When a slot becomes available, the task calls Sender().send(...) to push the booking link to the user’s WeChat.

Project Resources

GitHub repository: https://github.com/bluedazzle/wechat_sender

Documentation: http://wechat-sender.readthedocs.io/zh_CN/latest/

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

AutomationAlertingloggingWeChatwxpy
ITPUB
Written by

ITPUB

Official ITPUB account sharing technical insights, community news, and exciting events.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.