Back to Home

Telegram Content Automation Python AI

The article describes a Python bot for automating posts in a Telegram channel using Google Sheets as CMS, OpenAI for text generation, and a custom scheduler. It covers operating modes, technology stack, and API limits bypass. The human retains the role of strategist.

Telegram Bot: Python + OpenAI + Sheets
Advertisement 728x90

Automating Telegram Content with Python and AI

A Python bot using OpenAI and Google Sheets generates unique posts for your Telegram channel based on a spreadsheet schedule. It pulls data, crafts text tailored to product specs or topics, adds hashtags, and publishes on time. Say goodbye to copy-pasting and templates while keeping full control over your strategy.

Bot Architecture

Data flow:

  • Google Sheets holds the posting schedule.
  • gsheet.py pulls the rows.
  • generator.py creates text via OpenAI API (GPT-4o-mini).
  • poster.py sends to Telegram with photos.
  • scheduler.py runs on Moscow time.

Tech stack:

Google AdInline article slot
  • python-telegram-bot for Telegram API.
  • openai for generation.
  • google-api-python-client for Sheets.
  • asyncio and custom scheduler.
  • python-dotenv for tokens.

Google Sheets as Your CMS

Spreadsheet columns:

  • Post date.
  • Post topic.
  • AI prompt.
  • Links to 1–7 photos.
  • Product specs.

You fill in the basics: topic, prompt, photos, specs. The bot handles the rest. It's a game-changer for small businesses ditching manual CMS entry.

Content Generation Modes

Code in generator.py handles different scenarios:

Google AdInline article slot

Catalog mode (with specs):

Input: SKU, dimensions, material.

Output: Punchy sales copy with emotion and CTA.

Google AdInline article slot

Prompts block made-up data.

Atmosphere mode (no specs):

Input: Topic like "How Color Shapes Design".

Output: 2–3 storytelling paragraphs in your brand voice.

Auto-hashtags: build_hashtags() scans topic and specs, adds #newarrival, #review, brand tags.

Posting and Scheduling

  • Photo groups (up to 7) + caption up to 1024 chars.
  • fit_to_caption() trims text at sentence or line breaks.
  • No photos? Pure text post.

Scheduler scheduler_async() calculates time to next run based on POST_TIME (e.g., "13:00" MSK). Skips timezone headaches from libs like apscheduler.

Technical Limits and Fixes

  • Telegram caption: Smart trimming without breaking words.
  • GPT hallucinations: Prompts ban fabrication.
  • Sheets API quota: 500 requests/day—plenty for 1–2 channels.

Scaling? Monitor quotas and rotate keys.

Tasks before/after automation:

| Task | Manual | Bot |

|--------|--------------|-----|

| Text generation | Human | ✅ OpenAI |

| Formatting | Human | ✅ Auto |

| Hashtags | Human | ✅ Topic analysis |

| Posting | Manual | ✅ Scheduled |

| Planning | Human | ❌ Human only |

Human's Role

Bot handles grunt work, you own strategy:

  • Topic selection.
  • Prompt tuning.
  • Quality checks.
  • Schedule tweaks.

Result: Monthly consistent posts, boosted engagement from fresh content.

Key Takeaways

  • Craft precise prompts to dodge hallucinations on specs.
  • Cap captions at 1024 chars with trim function.
  • Custom scheduler fixes timezone issues.
  • Google Sheets as DB: free and simple for small scale.
  • Stay the strategist: pick topics, ensure quality.

— Editorial Team

Advertisement 728x90

Read Next