SPIW-bot is a Telegram inline bot for resolving and delivering social media content as cached Telegram media. It validates links, fetches metadata, prepares and normalizes assets, caches results, and returns Telegram-ready inline items.
- Supports Telegram inline queries with links from major platforms.
- Handles posts, reels, stories, and multi-item galleries where supported.
- Uses SQLite caching for instant repeated responses.
- Normalizes and deduplicates input links.
- Converts media into Telegram-friendly formats: jpg, png, mp4.
- Applies concurrency and duration limits to reduce overload.
- Designed for secure containerized deployment.
- TikTok
- X / Twitter
- Threads
spiw.__main__initializes settings, database, cache, and starts polling.spiw.telegramhandles inline handlers, result rendering, and callbacks.spiw.orchestratorcoordinates the full lifecycle: resolve -> prepare -> upload -> cache.spiw.providers.*extracts media metadata for each platform.spiw.pipelinedownloads and normalizes content usingyt-dlpandffmpeg.spiw.storagemanages cache persistence and in-memory processing state.
- Python 3.13+
ffmpegandffprobe(if running outside Docker)- Telegram bot token
- Prepare environment
cp .env.example .envSet variables in .env:
SPIW_BOT_TOKEN=YOUR_BOT_TOKEN
SPIW_SERVICE_CHAT_ID=-1001234567890SPIW_SERVICE_CHAT_ID is the chat/channel used to upload media and reuse Telegram file_id values in inline responses.
- Install and run
python -m venv .venv
source .venv/bin/activate
pip install -e .
spiw-botAlternative:
python -m spiwdocker build -t spiw-bot:latest .
docker-compose up -ddocker-compose.yml mounts:
/tmp/spiw-mediaastmpfsfor temporary conversion files../data:/app/dataas persistent SQLite cache storage.
Required variables:
SPIW_BOT_TOKENSPIW_SERVICE_CHAT_ID
Example:
SPIW_BOT_TOKEN=...
SPIW_SERVICE_CHAT_ID=...
docker-compose up -ddeploy.sh contains a manual deploy flow: build image, save archive, transfer, load and restart container.
All config is driven by SPIW_ prefixed environment variables.
| Parameter | Default | Description |
|---|---|---|
SPIW_BOT_TOKEN |
required | Telegram bot token |
SPIW_SERVICE_CHAT_ID |
required | Chat ID used for caching uploads |
SPIW_MAX_VIDEO_DURATION_SECONDS |
600 |
Maximum allowed video duration |
SPIW_PROCESSING_CONCURRENCY |
8 |
Parallel jobs in processing stage |
SPIW_DIRECT_DOWNLOAD_CONCURRENCY |
6 |
Parallel direct download threads |
SPIW_MAX_MEDIA_GROUP_ITEMS |
10 |
Maximum items in Telegram media groups |
SPIW_INLINE_CACHE_SECONDS |
900 |
Inline cache TTL |
SPIW_INLINE_RESOLVE_TIMEOUT |
5.0 |
Metadata warm-up timeout for inline query |
SPIW_PROVIDER_TIMEOUT_SECONDS |
45.0 |
Provider request timeout |
SPIW_HTTP_TIMEOUT_SECONDS |
15.0 |
HTTP request timeout |
SPIW_DB_PATH |
data/spiw.db |
SQLite cache path |
SPIW_MEDIA_TEMP_DIR |
/tmp/spiw-media |
Working directory for temporary files |
SPIW_FFMPEG_BINARY |
ffmpeg |
ffmpeg binary path |
SPIW_FFPROBE_BINARY |
ffprobe |
ffprobe binary path |
SPIW_TIKTOK_FALLBACK_API_URL |
https://www.tikwm.com/api/ |
TikTok fallback endpoint |
- TikTok:
tiktok.com/t/<id>,tiktok.com/video/...,vm.tiktok.com/...,vt.tiktok.com/... - Instagram:
instagram.com/reel/<id>,instagram.com/p/<id> - X / Twitter:
x.com/<handle>/status/<id>ortwitter.com/<handle>/status/<id> - Threads:
threads.com/@<user>/post/<id>
Links can be provided inside a text message; the bot extracts the first valid URL.
spiw.dbstores cached media metadata and query aliases.data/keeps persistent cache state when used with Docker..env.examplecontains the baseline environment template.Dockerfileanddocker-compose.ymldefine container runtime.
- Add the bot as an inline bot.
- In any chat, send
@YourBotName <link>. - For simple media, results are sent immediately.
- For complex content, a loading placeholder appears, then final media is delivered.
- Bot does not respond: check link format and platform support.
- Processing errors: check logs for timeouts or upstream provider changes.
- ffmpeg-related errors: ensure binaries exist and paths in
SPIW_FFMPEG_BINARY/SPIW_FFPROBE_BINARYare valid.
pip install -e .
python -m spiw