Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

46 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

FlamingText Logo
Logo


πŸš€ What is PrimoPopBot?

A single Cloudflare Worker that runs one factory bot (controlled only by you) plus unlimited child bots, each entirely defined by a JSON action DSL you upload through the factory bot. Ever[...]

This is a from-scratch Workers reimplementation of an earlier python-telegram-bot long-polling project, preserving the same powerful DSL philosophy while re-deriving every mechanism for the serv[...]

✨ Key Features

  • πŸ€– Unlimited Child Bots β€” One factory, infinite possibilities
  • πŸ“ JSON DSL β€” Define bot behavior with simple, expressive action declarations
  • ⚑ Webhook-Driven β€” No polling loops, instant response times
  • πŸ” Military-Grade Security β€” AES-GCM encryption at rest, sandboxed evaluators
  • 🌐 TON Wallet Integration β€” Built-in TON Connect v2 and signing helpers
  • 🧠 AI-Powered β€” Workers AI integration for intelligent bot generation
  • πŸ“Š GitHub Actions Gateway β€” Control workflows from Telegram
  • 🚫 Impossible to Pwn β€” No shell, no eval, no RCE vectors

⚑ Quick Start

./setup.sh

The script will automatically:

  1. βœ… Check for / install wrangler and log you in
  2. βœ… Create the BOT_KV KV namespace (prod + preview) and patch wrangler.toml
  3. βœ… Prompt for your Telegram numeric user id and write it into wrangler.toml
  4. βœ… Prompt for and set the two Worker secrets (SECRET_PASSPHRASE, TELEGRAM_WEBHOOK_SECRET)
  5. βœ… Deploy the Worker
  6. βœ… Register your factory bot and store it in KV as bot:factory

After that, open a chat with your factory bot on Telegram and send /start.

πŸ› οΈ Manual Setup (if you'd rather not use setup.sh)

npm install
npx wrangler login
npx wrangler kv namespace create BOT_KV
npx wrangler kv namespace create BOT_KV --preview
# paste the two ids into wrangler.toml under [[kv_namespaces]]

# edit wrangler.toml: set FACTORY_OWNER_ID to your numeric Telegram user id
# (get it from @userinfobot on Telegram)

npx wrangler secret put SECRET_PASSPHRASE
npx wrangler secret put TELEGRAM_WEBHOOK_SECRET
# (any long random strings; TELEGRAM_WEBHOOK_SECRET must be 1-256 chars,
#  A-Z a-z 0-9 _ - only, per Telegram's setWebhook requirements)

npx wrangler deploy

# Register the factory bot itself (one-time):
curl -s "https://api.telegram.org/bot<FACTORY_TOKEN>/setWebhook" \
  -d "url=https://<your-worker>.workers.dev/hook/factory" \
  -d "secret_token=<same value you put in TELEGRAM_WEBHOOK_SECRET>"

# Put the factory bot's record into KV:
npx wrangler kv key put --binding=BOT_KV "bot:factory" \
  '{"botId":"factory","token":"<FACTORY_TOKEN>","ownerId":"<your-id>","visibility":"private","createdAt":"2026-07-31T00:00:00Z"}'

πŸ’‘ Usage Examples

Creating a New Child Bot

Open your factory bot on Telegram and send /help for the full command list. Typical flow:

/newbot 123456:AA...            β†’ validate token, then tap Public/Private
/setconfig mychildbot           β†’ attach examples/simple-public-bot.json

Or define it inline:

/json mychildbot {"version":1,"commands":[{"command":"start","actions":[{"type":"send_message","text":"hi {user.first_name}"}]}]}

πŸ“¦ Starter Configs

Pre-built examples in examples/:

Config Purpose
simple-public-bot.json Dice, polls, and ask-based name capture
price-tracker-bot.json Real-time data requests and margin calculator
interface-anything-bot.json Generic Telegram API calls for unlimited flexibility
ton-wallet-bot.json TON wallet connections and signing flows

πŸ” Managing Secrets

Store API keys, tokens, and sensitive data per-bot, encrypted at rest with AES-GCM:

/set_secret mychildbot
> (bot asks for the name) API_KEY
> (bot asks for the value) sk-abc123...
βœ… Saved secret API_KEY for mychildbot. I deleted your message containing the value.

Reference in your config with {secrets.API_KEY} β€” resolved server-side only, never exposed unless you explicitly include it.

πŸš€ GitHub Actions Gateway

Enable GitHub workflow control directly from Telegram:

/set_secret factory   β†’ GITHUB_TOKEN
/set_secret factory   β†’ GITHUB_OWNER
/set_secret factory   β†’ GITHUB_REPO

Then use /gh_workflows, /gh_runs, /gh_dispatch <workflow> [ref], etc.

🌐 Generic Telegram Interfaces

For features not yet wrapped as DSL actions, use telegram_api:

{
  "type": "telegram_api",
  "method": "sendVenue",
  "payload": {
    "latitude": 40.758,
    "longitude": -73.9855,
    "title": "Meet here",
    "address": "Times Square, New York"
  }
}

πŸ’° TON Wallet & Signing

Built-in TON-specific helpers for mainnet and testnet:

  • ton_connect β€” Build TON Connect v2 links, send as inline buttons, request ton_proof for authentication
  • ton_sign β€” Build signing URLs for your HTTPS signing page with network, payload type, and state

Both support placeholders like {user.id}, {chat.id}, {vars.some_value} and reject secret placeholders for external transmission.


πŸ—οΈ Architecture

Telegram ──POST /hook/factory──▢  Worker  ──▢ factory.ts (owner-only commands)
Telegram ──POST /hook/:botId───▢  Worker  ──▢ dsl/interpreter.ts (runActions)
                                       β”‚
                     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                     β–Ό                 β–Ό                      β–Ό
                  BOT_KV        ChatSession DO           Workers AI / fetch()
          (bot registry,     (vars, paused "ask"          (compute doesn't
           configs, secrets   flows, rate limits           reach these β€”
           blobs)             β€” per botId:chatId)          sandboxed evaluator)

πŸ“š Component Breakdown

Component Purpose
KV (BOT_KV) Bot registry, configs, encrypted secrets, transient factory-flow state
ChatSession DO Per-chat conversational state, paused ask flows, token-bucket rate limiting
dsl/expression.ts Sandboxed compute evaluator (arithmetic + whitelisted functions only)
dsl/interpreter.ts DSL execution engine (runActions)

πŸ”’ Security Model

βœ… Factory Bot: Hardcoded owner check (FACTORY_OWNER_ID) gates all access
βœ… Private Bots: Only the owner can interact; silent 200 OK for probes
βœ… Public Bots: Configs validated at save time, rejected if unsafe; rate-limited requests
βœ… No Shell/Python: No shell or python actions exist in the type system β€” impossible RCE vector
βœ… Sandboxed Compute: Custom formulas run in a non-Turing-complete whitelist evaluator, never reaching eval or Function


πŸ”„ Differences from Python Original

This reimplementation deliberately changes:

  1. No shell/python actions β€” Completely absent from type system, schema, and interpreter. Replaced with compute/transform using a whitelisted evaluator.

  2. Session state in Durable Objects β€” Not in-process memory. Workers isolates are ephemeral, so vars and paused flows live externally in a DO (trades memory for network round-trip, gains [...]

  3. Web Crypto AES-GCM β€” Same goal as Fernet (symmetric encryption), different primitive (Fernet unavailable in workerd).

  4. Native env.AI binding β€” Direct Workers AI integration instead of authenticated HTTP calls. One fewer secret to manage.

  5. Nested condition + ask resume behavior β€” Resume continues the inner branch only, not sibling actions after the condition (interpreter simplicity tradeoff).

  6. Webhooks instead of long-polling β€” No getUpdates loop, no persistent process. Every update routes to your Worker, verified via X-Telegram-Bot-Api-Secret-Token header.


πŸ“‚ Repository Layout

wrangler.toml              Worker config: KV, DO, AI bindings
package.json / tsconfig.json
src/
  β”œβ”€β”€ index.ts             Hono app: /hook/factory & /hook/:botId routes
  β”œβ”€β”€ telegram.ts          Telegram Bot API client (fetch-based)
  β”œβ”€β”€ env.ts               Shared Env (bindings + vars) interface
  β”œβ”€β”€ secrets.ts           Web Crypto AES-GCM encrypt/decrypt
  β”œβ”€β”€ session.do.ts        ChatSession Durable Object
  β”œβ”€β”€ session-client.ts    DO communication wrapper
  β”œβ”€β”€ factory.ts           Factory-bot command handlers
  β”œβ”€β”€ github.ts            GitHub Actions gateway
  β”œβ”€β”€ ai.ts                Workers AI-backed command generator
  └── dsl/
      β”œβ”€β”€ types.ts         Action & config type definitions
      β”œβ”€β”€ schema.ts        Shape validator & public-bot safety checks
      β”œβ”€β”€ expression.ts    Sandboxed compute evaluator
      β”œβ”€β”€ template.ts      {user.x}/{vars.x}/{secrets.x} interpolation
      └── interpreter.ts   DSL execution engine (runActions)
examples/
  β”œβ”€β”€ simple-public-bot.json
  β”œβ”€β”€ price-tracker-bot.json
  β”œβ”€β”€ interface-anything-bot.json
  └── ton-wallet-bot.json
assets/                    Images & logos
setup.sh                   One-shot wrangler setup + deploy script

⚠️ Known Limitations

  • πŸ“₯ Large Configs: getFile downloads capped at 20MB by Telegram; use /json in chunks or host externally
  • πŸ“¦ GitHub Logs: /gh_logs returns a signed, time-limited download URL (not proxied through Worker)
  • πŸ”€ Nested Conditionals: condition + nested ask resume only the inner branch (see differences #5)

🎯 Next Steps

  • πŸ“– Read /help in your factory bot for detailed command reference
  • πŸ” Explore the examples/ directory for real-world config templates
  • πŸš€ Check wrangler.toml for available bindings and environment variables
  • πŸ’¬ Open an issue for feature requests or bug reports

Built with ⚑ on Cloudflare Workers

Made by quickerup β€’ MIT License

About

🏭 PrimoPopBot β€” Premium Telegram Bot Factory on Cloudflare Workers. Create, program, and manage child bots through an interactive button-driven UI.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages