https://github.com/mscbuild/woocommerce-telegram
Woocommerce telegram bot (Python) .A Telegram bot for WooCommerce allows you to connect your online store to Telegram, enabling features like order notifications, customer interaction, and even product sales directly through the messaging app.
https://github.com/mscbuild/woocommerce-telegram
bot bussiness development ecommerece messenger telegram telegrambot woocommerce
Last synced: 11 months ago
JSON representation
Woocommerce telegram bot (Python) .A Telegram bot for WooCommerce allows you to connect your online store to Telegram, enabling features like order notifications, customer interaction, and even product sales directly through the messaging app.
- Host: GitHub
- URL: https://github.com/mscbuild/woocommerce-telegram
- Owner: mscbuild
- License: mit
- Created: 2025-07-21T16:48:22.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-07-21T17:18:56.000Z (11 months ago)
- Last Synced: 2025-07-21T19:28:53.570Z (11 months ago)
- Topics: bot, bussiness, development, ecommerece, messenger, telegram, telegrambot, woocommerce
- Language: Python
- Homepage:
- Size: 16.6 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# woocommerce-telegram (Python)








# π§ Use Case Example
- Letβs say you want to notify users via Telegram when:
- A new order is placed
- A product is back in stock
- A customer leaves a review
# ποΈ Project Structure
~~~bash
woocommerce-telegram-bot/
β
βββ bot/
β βββ __init__.py
β βββ config.py
β βββ telegram_bot.py # Bot logic + command handlers
β βββ woo.py # WooCommerce API interface
β
βββ webhook/
β βββ __init__.py
β βββ server.py # Flask server for webhook
β
βββ requirements.txt
βββ run.py # Main entry point
βββ README.md
~~~
# π§± Overview of What You Need
## 1. Telegram Bot
- Create a Telegram bot via @BotFather
- Save the bot token
## 2. WooCommerce Store
- WooCommerce REST API must be enabled
- Get your Consumer Key and Consumer Secret
## 3. Python Environment
Install required libraries:
~~~bash
pip install python-telegram-bot woocommerce flask
~~~
# π§ͺ Example Use Case: Telegram Bot for New Orders
## Step 1: Basic Telegram Bot Setup (Python)
~~~bash
from telegram import Bot
TELEGRAM_BOT_TOKEN = "YOUR_TELEGRAM_BOT_TOKEN"
CHAT_ID = "YOUR_CHAT_ID" # Your Telegram user ID or group ID
bot = Bot(token=TELEGRAM_BOT_TOKEN)
def send_telegram_message(message):
bot.send_message(chat_id=CHAT_ID, text=message)
~~~
## Step 2: WooCommerce API Integration
~~~bash
from woocommerce import API
wcapi = API(
url="https://yourstore.com",
consumer_key="ck_xxx",
consumer_secret="cs_xxx",
version="wc/v3"
)
def get_latest_orders():
return wcapi.get("orders").json()
~~~
## Step 3: Notify on New Order (Polling or Webhook)
Option A: Polling (Not real-time, simpler)
~~~bah
import time
last_order_id = None
while True:
orders = get_latest_orders()
if orders:
latest = orders[0]
if latest['id'] != last_order_id:
msg = f"π New Order!\nCustomer: {latest['billing']['first_name']}\nTotal: {latest['total']}"
send_telegram_message(msg)
last_order_id = latest['id']
time.sleep(60)
~~~
## Option B: Webhook from WooCommerce to Flask (Real-time, better)
1.Create a webhook in WooCommerce:
- Topic: Order Created
- Delivery URL: e.g., `https://yourdomain.com/webhook`
- Secret: Use something unique
- Flask app to receive webhook:
~~~bash
from flask import Flask, request
app = Flask(__name__)
@app.route("/webhook", methods=["POST"])
def wc_webhook():
data = request.json
msg = f"π New Order!\nCustomer: {data['billing']['first_name']}\nTotal: {data['total']}"
send_telegram_message(msg)
return "OK", 200
if __name__ == "__main__":
app.run(port=5000)
~~~
# π§© Optional Features
- Respond to Telegram commands (`/latest_orders`)
- Notify on stock status changes
- Add custom filters for big orders, VIP clients, etc.
# π¦ Packaging It
- Run Flask app on cloud (Heroku, Fly.io, etc.)
- Use ngrok for testing locally with webhooks:
~~~bash
ngrok http 5000
~~~
# π File Contents
- `requirements.txt`
- `bot/config.py`
- `bot/woo.py`
- `bot/telegram_bot.py`
- `webhook/server.py`
- `run.py`
# π How to Run Locally
1.Install dependencies:
~~~bash
pip install -r requirements.txt
~~~
2.Start the bot:
~~~bash
python run.py
~~~
3.Run webhook server (for real-time WooCommerce updates):
~~~bash
python webhook/server.py
~~~
4.(Optional) Use ngrok to expose webhook to WooCommerce:
~~~bash
ngrok http 5000
~~~
- Then set this https://xxxx.ngrok.io/webhook as the webhook URL in your WooCommerce admin panel under:
- WooCommerce β Settings β Advanced β Webhooks
# π¬ Available Telegram Commands
| Command | Description |
| --------------- | -------------------------- |
| `/start` | Greet the user |
| `/latest_order` | Fetch latest order details |
You can add more like /stock_status, /customer_info, etc.
ββ Next you can set up Docker or deployment (Heroku, Fly.io, etc.)