message-pusher

repository·master·Indexed 26 days ago

https://github.com/songquanpeng/message-pusher

A versatile message notification service supporting multiple channels including Email, WeChat, QQ, DingTalk, Telegram, Discord, and Bark. It features Markdown support, a web management interface, and a REST API for sending notifications. The service can be deployed as a single executable or via Docker, and supports WebSocket clients for real-time message reception.

Tokens
5.2K
Snippets
14
Records
38
Agent score
87%

What's inside message-pusher

  1. Compile the project from source

    master
    If you wish to compile the project manually, you must follow a specific build order to avoid errors. You must compile the frontend before compiling the backend. Failure to do so will result in the error: pattern web/build: no matching files found.
  2. Migrate database from v0.3 to v0.4

    master

    To upgrade your database from version v0.3 to v0.4 (using SQLite as an example), follow these steps:

    1. Backup: Create a backup of your existing database file.
    2. Schema Migration: Download the latest v0.4 version and start the program. The program will automatically migrate the database table structure.
    3. Stop: Terminate the running program.
    4. Data Migration: Execute the migration script: ./bin/migrate_v3_to_v4.py to migrate the actual data.
    5. Restart: Start the program again.

    CRITICAL: Before running the script, ensure that the column order in the users table matches the order expected by the script to prevent data corruption.

    ./bin/migrate_v3_to_v4.py
  3. Use the Message Pusher API

    master

    The Message Pusher service provides an API to send notifications via various channels. The base API URL follows the pattern: https://<domain>/push/<username>. You must replace <domain> and <username> with your actual configured values.

    Request Methods

    • GET: Use query parameters to send messages.
    • POST: Use form data or JSON. If sending JSON, you must set the Content-Type header to application/json.
    https://<domain>/push/<username>
  4. Deploy message-pusher via Docker

    master

    Run the message-pusher service as a Docker container. By default, it listens on port 3000 and uses SQLite for data storage. Ensure the host directory for data exists and has write permissions.

    If you cannot pull from Docker Hub, use the GitHub Container Registry mirror: ghcr.io/songquanpeng/message-pusher.

    docker run -d --restart always --name message-pusher -p 3000:3000 -e TZ=Asia/Shanghai -v /home/ubuntu/data/message-pusher:/data justsong/message-pusher
  5. Deploy message-pusher manually from source

    master

    To deploy manually, you must build the web frontend using npm and the backend using Go.

    1. Build the web assets.
    2. Download Go dependencies and build the binary.
    3. Run the binary with desired flags.

    Initial credentials: Username root, Password 123456.

    # Build
    git clone https://github.com/songquanpeng/message-pusher.git
    cd message-pusher/web
    npm install
    npm run build
    cd ..
    go mod download
    go build -ldflags "-s -w" -o message-pusher
    
    # Run
    chmod u+x message-pusher
    ./message-pusher --port 3000 --log-dir ./logs
  6. Implement a WebSocket client for message reception

    master

    You can build desktop, mobile, or web applications to receive messages by connecting to the server via WebSocket. Note that only one client per user can be connected at a time; connecting a new client will disconnect the previous one.

    Connection Protocol

    • Endpoint: ws://<domain>:<port>/api/register_client/<username>?secret=<secret>
    • Secure Connection: If HTTPS is enabled, use wss:// instead of ws://.
    • Authentication: The secret parameter must be the 服务器连接密钥 (Server Connection Secret) configured in the backend, not the 推送 token (Push Token).

    Message Format

    Messages are encoded in JSON. Your client should handle the following fields:

    {
     "title": "标题",
     "description": "描述",
     "content": "内容",
     "html_content": "转换为 HTML 后的内容",
     "url": "链接"
    }

    Note: You may ignore any additional fields returned in the JSON object.

    ws://<domain>:<port>/api/register_client/<username>?secret=<secret>
  7. Configure Nginx reverse proxy for message-pusher

    master

    To use a custom domain and SSL, configure Nginx as a reverse proxy.

    Important: If you are using the WebSocket client feature, you MUST set proxy_read_timeout and proxy_send_timeout to more than 1 minute (recommended: 300s) to prevent connection drops.

    server{
       server_name push.justsong.cn;  # Replace with your domain
       
       location / {
              client_max_body_size  64m;
              proxy_http_version 1.1;
              proxy_pass http://localhost:3000;  # Replace with your port
              proxy_set_header Host $host;
              proxy_set_header X-Forwarded-For $remote_addr;
              proxy_cache_bypass $http_upgrade;
              proxy_set_header Accept-Encoding gzip;
              
              # Required for WebSocket support
              proxy_read_timeout 300s;
              proxy_send_timeout 300s;   
       }
    }
  8. Manage the React Template application lifecycle

    master

    Use standard npm commands to manage the React Template application. You can install dependencies, start the application in development mode, or build the application for production.

    # Install dependencies
    npm install
    
    # Runs the app in the development mode
    npm start
    
    # Builds the app for production to the `build` folder
    npm run build
  9. Deploy message-pusher using Docker Compose

    master

    You can deploy the message-pusher service using Docker Compose. The service runs on port 3000 by default and requires a persistent volume for data storage.

    Key configuration details:

    • Image: justsong/message-pusher
    • Port Mapping: Maps host port 3000 to container port 3000.
    • Environment Variables: Supports TZ to set the system timezone (e.g., Asia/Shanghai).
    • Volumes:
      • ./data:/data: Persists application data to a local ./data directory.
      • /etc/localtime:/etc/localtime:ro: Synchronizes the container timezone with the host system.
    version: "3"
    
    services:
      message-pusher:
        image: justsong/message-pusher
        restart: unless-stopped
        ports:
          - 3000:3000
        environment:
          - TZ=Asia/Shanghai
        volumes:
          - ./data:/data
          - /etc/localtime:/etc/localtime:ro
  10. Migrate database from v3 to v4

    master

    Use the migrate_v3_to_v4.py script to migrate your SQLite database schema and data from version 3 to version 4. This script transforms user-specific channel configurations (like email, WeChat, Lark, DingTalk, etc.) into the new channels table format.

    Warning: This script performs a DELETE FROM channels operation before migrating. Ensure you have a backup of your database before running this script.