Deploy
LinkBrain runs entirely on Cloudflare: a single Worker, a D1 database, and Workers AI. Personal use stays inside the free tiers, and there is no long-running process — the Worker wakes on each Telegram webhook request.
Prerequisites
Section titled “Prerequisites”- A Cloudflare account (free) and Node.js 18+.
npm installpulls inwranglerlocally. - A Telegram bot token — message @BotFather, send
/newbot, and copy the token (looks like7123456789:AAF…). - (Optional) a GitHub token (classic, no scopes) — raises the GitHub API rate limit from 60 to 5,000 requests/hour. Only worth it if you save many repos.
-
Install dependencies from the project root.
Terminal window npm install -
Authenticate wrangler with your Cloudflare account (opens a browser).
Terminal window npx wrangler login -
Create the D1 database, then paste the printed
database_idintowrangler.jsonc(replaceREPLACE_WITH_ID_FROM_wrangler_d1_create).Terminal window npx wrangler d1 create linkbrain -
Create the tables and load seeded links.
Terminal window npx wrangler d1 migrations apply linkbrain --remote -
Set your secrets (paste each value when prompted). Generate a webhook secret with
openssl rand -hex 16.Terminal window npx wrangler secret put TELEGRAM_TOKEN # the BotFather tokennpx wrangler secret put WEBHOOK_SECRET # a random stringnpx wrangler secret put ALLOWED_CHAT_ID # your chat id — see belownpx wrangler secret put GITHUB_TOKEN # optional; enter to skip -
Deploy — this prints your Worker URL.
Terminal window npm run deploy -
Point Telegram at the Worker. The webhook lives at the
/webhookpath (everything else serves the docs). Thesecret_tokenMUST equal theWEBHOOK_SECRETfrom step 5.Terminal window curl "https://api.telegram.org/bot<TELEGRAM_TOKEN>/setWebhook?url=https://linkbrain.<you>.workers.dev/webhook&secret_token=<WEBHOOK_SECRET>"
Finding your chat id
Section titled “Finding your chat id”ALLOWED_CHAT_ID locks the bot to just you. Message
@userinfobot on Telegram — it replies with your
numeric id. With it set, the Worker silently ignores messages from any other
chat. See the security model for what each gate stops.
Verify
Section titled “Verify”Confirm the webhook is registered:
curl "https://api.telegram.org/bot<TELEGRAM_TOKEN>/getWebhookInfo"You want "url" set to your Worker and "pending_update_count": 0 with no
last_error_message. Then send a link to your bot — you should get a reply with
a summary and tags within a couple of seconds.
Local development
Section titled “Local development”npm run dev # wrangler dev on http://localhost:8787npm run db:migrate:local # apply migrations to the LOCAL D1D1 runs locally, but Workers AI has no local engine — wrangler dev proxies
AI calls to your Cloudflare account, so summaries need wrangler login. Without
it, summarization degrades gracefully and the link still saves from scraped
metadata. Local secrets live in .dev.vars (gitignored).