Setup & Deployment
Deploying Telegram Business Assistant requires a Telegram account with Telegram Business / Premium access, a bot configured in @BotFather, and either GitHub Actions CI (recommended) or the local @tgcloud/cli tool.
1. Prerequisites & @BotFather Setup
Section titled “1. Prerequisites & @BotFather Setup”Open @BotFather in Telegram and complete these steps for your bot:
- Enable Serverless: Go to
@BotFather → Your Bot → Serverlessand activate Telegram Serverless hosting. - Copy the CLI Access Token: Open
Serverless → CLI Access → Access tokenand copy the token formatted asapp<id>:<secret>. - Enable Business Mode: Open
Bot Settings → Business Modeand turn it ON. - Disable Group Access: Open
Bot Settings → Allow Groupsand turn it OFF for privacy. - Enable Threaded Mode (Optional): Open
Bot Settings → Threads Settings → Threaded Modeand turn it ON to organize alerts into per-contact topics. - Find Your Numeric Telegram User ID (
OWNER_ID): Record your numeric user ID (positive integer digits only, such as123456789). - Restrict Bot Usage (
@BotFatherMini App): Open the@BotFatherMini App, select your bot, navigate toBot Settings → Access, and enable Restrict bot usage so unauthorized users cannot interact with the private assistant bot at the Telegram platform level (while Telegram Business updates for the connected owner account continue normally). Then check Allowed users:- Same account (Bot creator =
OWNER_ID): If you created the bot with the same Telegram account whose ID is set inOWNER_ID, your account is listed in Allowed users automatically—simply verify it is present. - Different account (Bot created on Account A, used on Business Account B): If you created the bot on one account and run it on another account (whose numeric ID is stored in
OWNER_IDin GitHub Secrets or local bootstrap), you must open Allowed users and explicitly select and add thatOWNER_IDaccount; otherwise Telegram will block it from sending/startor using owner commands even whenOWNER_IDis configured in the bot.
- Same account (Bot creator =
2. Choose a Deployment Method
Section titled “2. Choose a Deployment Method”Option 1 — GitHub Actions CI (Recommended, Zero Local Setup)
Section titled “Option 1 — GitHub Actions CI (Recommended, Zero Local Setup)”Fork or create a repository from AZiPA/telegram-chat-automation, then add two Repository Secrets under Settings → Secrets and variables → Actions:
| Secret | Validation Pattern | Description |
|---|---|---|
TGCLOUD_TOKEN |
^app[0-9]+:[^[:space:]]+$ |
Telegram Serverless CLI Access Token |
OWNER_ID |
^[1-9][0-9]*$ |
Numeric Telegram user ID of the bot owner |
The deployment workflow runs automatically on every push, or manually via Actions → ✈️ Deploy to Telegram → Run workflow (workflow_dispatch) on Node.js 26.
When triggering manually, you can pick a migration_mode:
| Mode | CLI Flag | Behavior |
|---|---|---|
safe (default) |
--safe |
Additive safe schema changes only; skips warning-level drops (always used on push) |
dry-run |
--dry-run |
Prints pending schema diffs without modifying the SQLite database |
skip |
— | Skips the migration step completely |
yes |
--yes |
Applies safe changes and warning-level drops — use with caution |
Each CI run executes this 6-step sequence:
- Validate
TGCLOUD_TOKENandOWNER_IDsecret formats upfront. - Install CLI dependencies with
npm install --no-audit --no-fund. - Push runtime code via
npx tgcloud push --force. - Apply database migrations via
npx tgcloud migrate --<mode>(unlessskipis selected). - Seed ownership via
npx tgcloud run handlers/message "{owner_id: ${OWNER_ID}}" --ctx '{ci_bootstrap: true}'. - Reconcile webhook status with
npx tgcloud webhook syncandnpx tgcloud webhook.
Option 2 — Local Deployment via @tgcloud/cli
Section titled “Option 2 — Local Deployment via @tgcloud/cli”Local deployment requires Node.js 18+ (CI runs on Node.js 26):
git clone https://github.com/AZiPA/telegram-chat-automation.gitcd telegram-chat-automationnpm installnpx tgcloud loginnpx tgcloud pushnpx tgcloud migrateNext, run the mandatory owner bootstrap (replace 123456789 with your numeric Telegram user ID):
-
Bash / macOS / Linux:
Terminal window npx tgcloud run handlers/message '{owner_id: 123456789}' --ctx '{ci_bootstrap: true}' -
Windows CMD:
Terminal window npx tgcloud run handlers/message "{owner_id: 123456789}" --ctx "{ci_bootstrap: true}"
Verify the command output includes { ok: true }, then inspect the webhook state:
npx tgcloud webhookIf the webhook state has drifted, synchronize it with npx tgcloud webhook sync.
3. Post-Deploy Activation in Telegram
Section titled “3. Post-Deploy Activation in Telegram”- Initialize Private Chat: Open your bot in Telegram and send
/start. Confirm you receive the 🤖 Telegram Business Assistant Status dashboard—this confirmsOWNER_IDwas seeded properly and unlocks private bot messages. - Connect to Telegram Business: Open Settings → Telegram Business → Chatbots, select your bot, and grant the required
BusinessBotRights:
| Right | Purpose |
|---|---|
can_read_messages |
Read messages so incoming texts, media, edits, and deletions can be tracked |
can_reply |
Send and reply to Business chat messages when needed |
can_delete_sent_messages |
Delete messages sent by the bot |
can_delete_all_messages |
Auto-delete exact View-Once trigger replies (may appear as Delete Received Messages in Telegram UI) |
- Confirm Connection: Wait for the bot’s 🔗 Telegram Business Connected confirmation message in your private chat.
Pausing & Resuming Per Chat
Section titled “Pausing & Resuming Per Chat”To pause or resume automation in any specific conversation, use Telegram Business’s native top-bar Stop / Start toggle inside that chat. Disabling the bot globally from Telegram Business settings updates is_enabled = false in the connections table.
Next Steps
Section titled “Next Steps”- Commands & Configuration — Learn all private-chat owner commands and runtime constants.
- Architecture & Schema — Review handlers, SQLite tables, and ongoing maintenance commands.