Developing a Bot for Automatic Product Publishing from Website to Telegram Channel
Bot takes products from website catalog and publishes them to Telegram channel: with photo, description, price, and button linking to product page. Suitable for stores wanting to use Telegram channel as additional sales channel without manual post formatting.
Architecture
Scheduler (Cron/Celery Beat)
↓
ProductPublisher Service
↓ — select products for publishing
Database (products)
↓ — download image
CDN / S3
↓ — send post
Telegram Bot API (sendPhoto / sendMediaGroup)
↓ — mark as published
Database (telegram_posts)
Forming Publication
import httpx
from aiogram import Bot
from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton
bot = Bot(token=BOT_TOKEN)
async def publish_product(product: dict) -> None:
caption = (
f"<b>{product['name']}</b>\n\n"
f"{product['short_description']}\n\n"
f"💰 <b>{product['price']:,.0f} ₽</b>"
)
keyboard = InlineKeyboardMarkup(inline_keyboard=[[
InlineKeyboardButton(
text="🛒 Buy",
url=f"https://example.com/products/{product['slug']}"
)
]])
if product.get('images'):
await bot.send_photo(
chat_id=CHANNEL_ID,
photo=product['images'][0]['url'],
caption=caption,
parse_mode='HTML',
reply_markup=keyboard
)
else:
await bot.send_message(
chat_id=CHANNEL_ID,
text=caption,
parse_mode='HTML',
reply_markup=keyboard
)
# Mark as published
await db.execute(
'INSERT INTO telegram_posts (product_id, channel_id, published_at) VALUES ($1, $2, NOW())',
product['id'], CHANNEL_ID
)
Publication Schedule
Publishing multiple posts in a row is bad taste. Optimal: 1–3 products per day, at specific time:
# Celery Beat Schedule
CELERYBEAT_SCHEDULE = {
'publish-morning': {
'task': 'bot.tasks.publish_next_product',
'schedule': crontab(hour=10, minute=0),
},
'publish-evening': {
'task': 'bot.tasks.publish_next_product',
'schedule': crontab(hour=19, minute=0),
},
}
Publication Queue
Products aren't selected randomly — queue is formed:
- Priority by product creation date or manual sorting in admin
- Products published less than 30 days ago are skipped
- Inactive products excluded automatically
- Operator can mark product as "publish next"
Timeline
Bot with publication schedule and queue: 3–5 business days.







