A clean, high-performance asynchronous service engineered to track Twitch stream states in real time and automatically publish interactive notifications to a Telegram channel, featuring seamless automated commenting inside the linked discussion group.
- ๐ฏ Twitch Helix Engine: Asynchronous, stateless polling mechanism with fully automated OAuth2 App Access Token lifecycle management.
- ๐ผ๏ธ Dynamic Asset Handling: Fetches live stream metadata and handles binary image streams on the fly to deliver fresh, high-resolution thumbnails.
- ๐ In-Place State Mutation: Automatically edits original Telegram channel posts when the stream goes offline, swapping active control buttons for a direct VOD link.
- ๐ฌ Smart Discussion Threading: Detects automatic post forwards in the linked discussion chat and instantly drops a customizable call-to-action comment to boost engagement.
- ๐ Hot-Reload Localization: Fully decoupled translation layer (
ru.yml,en.yml) that applies updates immediately on the host without requiring a container rebuild or service restart.
โโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Twitch Helix API โ
โโโโโโโโโโโโโฌโโโโโโโโโโโโโ
โ [JSON Polling Engine]
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโ
โ State Manager โโโบ [Live] โโโบ Fetch Binary Thumbnail
โโโโโโโโโโโโโฌโโโโโโโโโโโโโ โโโบ [Offline] โบ Swap Buttons to VOD Record
โ
โ [Dispatches Payload]
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Telegram Channel Bot โ โโโโ Uses Locales (en.yml / ru.yml)
โโโโโโโโโโโโโฌโโโโโโโโโโโโโ
โ
โ [Telegram Auto-Forward]
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Discussion Group Chat โ โโโโบ Injects Auto-Comment to Thread
โโโโโโโโโโโโโโโโโโโโโโโโโโ
- BOT_TOKEN: Create a new bot instance using @BotFather, run the
/newbotcommand, and securely copy the generated API token. - CHANNEL_ID & DISCUSSION_ID: Add the bot to your target channel and its linked discussion group as an administrator with full post-publishing and message-deletion privileges. Extract the exact unique IDs (prefixed with
-100) by forwarding a message from the channel/chat to @getidsbot. - CHANNEL_CHAT_LINK: Obtain the public or private invitation link to your discussion chat (e.g., https://t.me/your_chat) to populate interactive inline keyboard targets.
- Log into your account via the Twitch Developer Console.
- Register a new application profile (Register Your Application):
- Input a unique, descriptive application identifier name.
- Configure the OAuth Redirect URL boundary to
http://localhost. - Set the category classification to
Application Integration.
- Open your application settings to copy the Client ID, then generate a fresh Client Secret (save it securely, as it will only be displayed once).
Create a .env configuration file in your project root using the production template below:
# Telegram Configuration
BOT_TOKEN=1234567890:ABCdefGhIJKlmNoPQRsTUVwxyZ
CHANNEL_ID=-1001111111111
DISCUSSION_ID=-1002222222222
CHANNEL_CHAT_LINK=https://t.me/example_chat
# Twitch Integration
TWITCH_CLIENT_ID=uio456pasdfghjklzxcvbnm123456
TWITCH_SECRET=mnbvcxzlkjhgfdsaqpwoeiru789012
STREAMER_USERNAME=twitchThe translation engine watches directory patterns natively. Below is the exact structural representation of the decoupled localization blueprint (locales/en.yml):
notifications:
buttons:
link: "Go to Chat"
watch_vod: "Watch VOD"
auto_comment:
text: "๐ Hi! Thanks for the forward. Join our main chat to chat!"
online:
caption: "๐ด <b>%{stream_title}</b>\n\n๐ฎ Game: %{game_name}\n\nJoin the stream!"
offline:
caption: "๐ค Stream has ended. See you next time! The broadcast recording is available below."Before launching the bot, you need to clone the repository, install the uv package manager, and configure the environment.
-
Cloning the Repository: Connect to your server via SSH, navigate to your home directory, and clone the project:
cd ~ git clone https://github.com/d43m0n4rch7/stream-notifier-bot.git cd stream-notifier-bot
-
Installing
uvon the Server:uvis a modern, ultra-fast Python package manager that automatically manages virtual environments. Install it using the official script:curl -LsSf https://astral.sh/uv/install.sh | shAfter the installation is complete, apply the new environment path variables (or simply restart your SSH session):
source $HOME/.local/bin/env
-
Environment Configuration: Create a
.envconfiguration file based on the template and populate it with your tokens:cp .env.example .env nano .env
(To save changes in the nano editor, press
Ctrl + O, thenEnter. To exit, pressCtrl + X)
Utilizes a lean, multi-stage Dockerfile architecture engineered with uv to maintain a minimal production footprint.
Launch the service stack silently in the background:
docker compose up -d --buildNote
The host ./locales directory is mounted as a Read-Only (:ro) target configuration volume. You can modify your translation files directly on the host server, and changes will be parsed dynamically without container teardowns.
Monitor real-time application logs:
docker compose logs -f appFor deployment directly within the operating system's native process tracking infrastructure:
- Provision an isolated virtual environment and synchronize pinned constraints:
uv venv
source .venv/bin/activate
uv sync --frozen --no-dev- Establish a new system service configuration unit:
sudo nano /etc/systemd/system/stream-notifier-bot.service- Populate the service layout file precisely:
(Replace
ubuntuin theWorkingDirectory,ExecStart, andEnvironmentpaths if your server username is different)
[Unit]
Description=Telegram & Twitch Stream Notifier Bot
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=ubuntu
WorkingDirectory=/home/ubuntu/stream-notifier-bot
ExecStart=/home/ubuntu/stream-notifier-bot/.venv/bin/python -m src.main
Restart=always
RestartSec=10
Environment=PYTHONUNBUFFERED=1
Environment=PYTHONPATH=/home/ubuntu/stream-notifier-bot
[Install]
WantedBy=multi-user.target- Reload system control daemon structures and activate the background worker:
sudo systemctl daemon-reload
sudo systemctl enable stream-notifier-bot --now- Verify service initialization status:
sudo systemctl status stream-notifier-bot- Intercept active execution logging pipelines:
sudo journalctl -u stream-notifier-bot -f- Root Cause: The bot is either missing specific admin boundaries inside the group chat or the
DISCUSSION_IDinside your.envdoes not match the true hidden target identity. - Solution: Verify the bot has both
Can Post MessagesandCan Delete Messagesprivileges enabled within the chat admin settings dashboard. Re-verify the-100channel prefix.
- Root Cause: Your
TWITCH_SECRETorTWITCH_CLIENT_IDconfiguration pairs are stale, corrupted, or the App Access Token has expired natively without proper tracking synchronization. - Solution: Wipe local runtime variables, generate a fresh replacement token inside the Twitch Console dashboard, and restart the service runtime completely.
This software is distributed under the terms of the MIT License. Feel free to inspect, refactor, or scale the repository infrastructure globally.
Built with โค๏ธ and clean code paradigms.