Add multi-route donor->recipient support, fix VK hashtag truncation

Posts can now be sourced from multiple VK groups, each routed to its own
Telegram/MAX destination(s) with independent on/off switches, configured
via data/routes.json (supports // line comments). Falls back to a single
route auto-generated from the legacy VK_SOURCE/TG_CHAT_ID/MAX_CHAT_ID env
vars if routes.json doesn't exist yet, so existing deployments keep working.

Routes are processed strictly sequentially within a cycle (no concurrency)
to keep flood control on VK/TG/MAX correct, since bot tokens are shared
across routes. DB schema gains route_id in the posts uniqueness key so the
same VK donor can safely feed multiple routes without status collisions.

Also removes the trailing-hashtag-stripping logic in text_formatter, which
was silently deleting VK posts' own hashtags whenever COMMON_TAGS wasn't
configured (it always wasn't) - posts are now forwarded unchanged.
This commit is contained in:
2026-08-18 14:48:22 +05:00
parent ec65aaf57d
commit 20135263c4
11 changed files with 596 additions and 233 deletions
+20 -6
View File
@@ -1,9 +1,22 @@
# ==========================================
# Donor(VK) -> Recipient(TG/MAX) routes
# ==========================================
# Multiple VK donor groups, each with its own Telegram/MAX destination(s) and its own
# TG/MAX on-off switches, are configured in a separate JSON file (default data/routes.json),
# NOT here. See data/routes.json.example for the format.
#
# VK_SOURCE / TG_CHAT_ID / MAX_CHAT_ID below are ONLY used once, as a fallback: if
# data/routes.json doesn't exist yet, it gets auto-generated from these three values
# as a single route (id "default") on first run. After that, edit routes.json directly -
# these three env vars are then ignored.
ROUTES_CONFIG_PATH=data/routes.json
# ==========================================
# VKontakte Settings
# ==========================================
# VK User/Service access token
# VK User/Service access token (shared by all routes)
VK_ACCESS_TOKEN=vk1.a.your_vk_token_here
# Target VK source: screen name, URL or owner_id (e.g., "redairsoft", "club123456", "-123456", "https://vk.com/redairsoft")
# Legacy single-route fallback - see routes.json note above
VK_SOURCE=redairsoft
# VK API Version
VK_API_VERSION=5.199
@@ -13,9 +26,10 @@ VK_CHECK_COUNT=10
# ==========================================
# Telegram Settings
# ==========================================
# Telegram Bot Token (from @BotFather)
# Telegram Bot Token (from @BotFather) - shared by all routes, posts into whichever
# chat_id each route configures
TG_BOT_TOKEN=123456789:ABCdefGHIjklMNOpqrSTUvwxYZ
# Destination Chat/Channel ID (e.g., "-1001234567890" or with topic thread "-1001234567890:42")
# Legacy single-route fallback - see routes.json note above
TG_CHAT_ID=-1001234567890
# Optional TG Media Storage Channel (e.g. for generating permanent file_ids)
TG_MEDIA_CHANNEL_ID=
@@ -36,9 +50,9 @@ TELEGRAM_API_HASH=
# ==========================================
# MAX Messenger Settings
# ==========================================
# MAX Bot Token
# MAX Bot Token - shared by all routes, posts into whichever chat_id each route configures
MAX_BOT_TOKEN=your_max_bot_token_here
# MAX Destination Chat ID
# Legacy single-route fallback - see routes.json note above
MAX_CHAT_ID=123456
# MAX API Base URL
MAX_API_BASE_URL=https://platform-api2.max.ru