Skip to content

A Telegram bot extension for the WordPress Sales Report Excel project that allows generating WooCommerce sales reports directly from Telegram. Supports Persian/Arabic numerals, group and user access control, and provides secure report links. Ideal for quickly accessing sales data without logging into WordPress.

License

Notifications You must be signed in to change notification settings

BaseMax/telegram-wordpress-sales-bot

Repository files navigation

Telegram WordPress Sales Bot

License: MIT

A Telegram bot extension for the WordPress Sales Report Excel project. This bot allows generating WooCommerce sales reports directly from Telegram, making it more accessible and user-friendly.


Table of Contents


Features

  • Generates WooCommerce sales reports via the WordPress Sales Report Excel project.
  • Supports private users, restricted groups, and open groups with configurable access.
  • Automatically converts Persian/Arabic numbers to English.
  • Sends unauthorized access notifications to the bot owner.
  • Handles unknown commands gracefully in private chats.
  • Works with Docker or directly on the host machine.

Requirements

  • Python 3.13+
  • Docker (optional, recommended for container deployment)
  • Python packages:
python-telegram-bot==20.4
python-dotenv

Installation

  1. Clone the repository:
git clone https://github.com/BaseMax/telegram-wordpress-sales-bot.git
cd telegram-wordpress-sales-bot
  1. Install Python dependencies:
pip install -r requirements.txt
  1. Create a .env file based on this template:
# Prefix for your project
PROJECT_PREFIX=wpsite

# Command to generate the sales report
TELEGRAM_SALES_REPORT_COMMAND=docker exec wordpress php /var/www/html/files/run.php

# Telegram bot token
TELEGRAM_BOT_TOKEN=<your_bot_token>

# Directory where reports are stored
REPORTS_DIR=/var/www/html/files

# URL prefix to access reports
REPORTS_URL_PREFIX=https://wpsite.com/files

# Users allowed in private chats and restricted groups
ALLOWED_USERS=123456789,987654321

# Groups where everyone is allowed to use the bot
ALLOWED_EVERYONE_IN_CHATS=-1001234567890

# Groups where only specific ALLOWED_USERS are allowed
ALLOWED_CHATS=-1001234567890
  • TELEGRAM_SALES_REPORT_COMMAND can point to a different Docker container or a script on the host.
  • ALLOWED_USERS controls private chat and restricted group access.
  • ALLOWED_EVERYONE_IN_CHATS allows all members of specified groups to use the bot.
  • ALLOWED_CHATS restricts group access to specific users only.

Configuration

  • TELEGRAM_BOT_TOKEN: Your bot token from BotFather.
  • REPORTS_DIR: Directory where reports are saved.
  • REPORTS_URL_PREFIX: URL prefix to access generated reports.
  • TELEGRAM_SALES_REPORT_COMMAND: Command to execute the report generation script.
  • ALLOWED_USERS: Comma-separated list of allowed Telegram user IDs.
  • ALLOWED_EVERYONE_IN_CHATS: Comma-separated list of group IDs where everyone can use the bot.
  • ALLOWED_CHATS: Comma-separated list of restricted groups where only specific users can use the bot.

Usage

  1. Start the bot:
python bot.py
  1. Use the /report command in Telegram:
/report 30
  • Generates a report for the last 30 days.
  • Responds with a direct URL to download the report.

Example Response:

✅ Report generated:
https://wpsite.com/files/orders-30days-2025-12-04-1c3f5e92-0a4f-4d8b-9f0b-1e2d3f4a5b6c.xlsx
  1. Unauthorized attempts are notified to the bot owner with user ID and chat info.

Docker Deployment

  1. Build and run the container:
docker-compose up -d
  1. The bot will automatically start and poll for messages.

Notes:

  • The container mounts the project directory and Docker socket, allowing TELEGRAM_SALES_REPORT_COMMAND to access other containers.
  • Make sure the report generation command works either from the host or inside another container.

Contributing

  1. Fork the repository.
  2. Create a branch: git checkout -b feature/my-feature
  3. Commit your changes: git commit -am 'Add new feature'
  4. Push to your branch: git push origin feature/my-feature
  5. Open a Pull Request.

License

This project is licensed under the MIT License. See the LICENSE file for details.


Author

Seyyed Ali Mohammadiyeh (Max Base)

About

A Telegram bot extension for the WordPress Sales Report Excel project that allows generating WooCommerce sales reports directly from Telegram. Supports Persian/Arabic numerals, group and user access control, and provides secure report links. Ideal for quickly accessing sales data without logging into WordPress.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages