Architecture
┌──────────────┐ long polling ┌────────────┐
│ Telegram bot │◄─────────────────►│ │
│ (buttons) │ media uploads │ gra │
└──────────────┘ │ daemon │
┌──────────────┐ profile / feed / │ (tokio) │
│ Instagram │◄─────────────────►│ │
│ API │ stories / follows└─────┬──────┘
└──────────────┘ │ SQLiteCrates
| Crate | Role |
|---|---|
instagram | Profile, feed and story scraping and media cleaning, over wreq (BoringSSL with Chrome TLS emulation) |
wreq / wreq-util | HTTP stack for the Telegram client, the following-list endpoint and CDN downloads |
rusqlite | SQLite storage (bundled) |
tokio | Async runtime: scheduler, long polling, per-chat workers |
clap, toml, serde | CLI, environment and config parsing |
Modules (src/)
| Module | Responsibility |
|---|---|
bot/ | Long polling; updates handled concurrently across chats and in order within a chat; commands, flows, inline keyboards |
bot/callback.rs | Typed inline-button actions and their compact callback_data format |
bot/views.rs | Screens as pure functions: data → text + keyboard |
poller.rs | Scheduler: due accounts → profile + stats → new posts → new stories → download → deliver |
ig.rs | Instagram session, following list, size-capped downloads, cookie input parsing |
tg.rs | Bot API client: retries on network errors, 5xx and flood control; multipart uploads; token-free errors |
db.rs | Versioned SQLite schema and queries with ownership checks |
config.rs | CLI / env / TOML merging and validation |
state.rs | Expiring per-chat input flows and following-list caches |
render.rs | HTML message builders, numbers, dates, sparklines |
Poll loop
Every tick_secs the scheduler loads active accounts whose last_checked_at + interval_secs has passed and checks them with at most max_concurrent_checks in parallel. Each check:
- Profile: followers/following/posts are stored on the account; with stats enabled, a
statsrow is appended when the counters changed. - Posts: the latest feed items newer than the account's watermark are delivered oldest first (photo, video, or albums for carousels), up to
max_send_per_check. Each delivery is recorded indeliveredand advances the watermark, so restarts never re-send. - Stories (only with cookies): active stories not yet delivered are sent; a story fetch failure doesn't fail the check.
Media that can't be uploaded (videos disabled, over Telegram's 10 MB photo / 50 MB video limits, download or upload error) is replaced by the caption with a link and a note. If even that message fails, the check fails and is retried later. Failed checks are stamped and retried on the account's interval; the user is notified once when the account starts failing.
Credentials resolution
account-linked set → user's ⭐ default set → first global 🌐 set → anonymousAn account set to None is always checked anonymously. Profile previews when adding an account use the user's default set (or the global set); the following list only ever uses the user's own default set.
Storage
SQLite in WAL mode with foreign keys. db_path accepts plain paths and file: URIs. Tables: users, cookie_sets (user_id NULL = global), accounts, stats, delivered. The schema version is kept in PRAGMA user_version; databases from incompatible releases are rejected instead of being migrated.