openartifacts.sh / templates / telegram-bot
Telegram bot
A Telegram bot in webhook mode, in Python with only the standard library. Telegram POSTs each message to the service, the request wakes it, and the reply travels back in the webhook's own response, so a quiet bot sleeps and costs nothing. Out of the box it answers /start, /help and /time and echoes anything else.
Deploy it
One call publishes it as-is and boots it. It needs no secret to boot; set TELEGRAM_BOT_TOKEN before it can do its job. Files you send with the call replace the template's files of the same name, and fields you send override its oa.json. It is billed like any service.
With curl
# once: an account and its token
curl -sX POST "https://openartifacts.sh/v1/signup?ref=templates"
# the template, published and booted
curl -sX POST https://openartifacts.sh/v1/publish \
-H "Authorization: Bearer $OA_TOKEN" \
-F type=service -F template=telegram-bot -F slug=my-bot
From an MCP client
publish_artifact {"type": "service", "template": "telegram-bot",
"slug": "my-bot"}
With the CLI
npx @openartifacts/cli signup --ref templates # once
npx @openartifacts/cli deploy --template telegram-bot --slug my-bot
# or edit first: the files, here, then a normal deploy
npx @openartifacts/cli init telegram-bot
npx @openartifacts/cli deploy ./telegram-bot --slug my-bot
Then: Set TELEGRAM_BOT_TOKEN (oa env set my-bot TELEGRAM_BOT_TOKEN=..., or PUT /v1/artifacts/my-bot/env), then open <url>/setup once to register the webhook.
Set it up
- In Telegram, message @BotFather, send
/newbot, and copy the token it gives you (123456:ABC-...). Give it to the service; it restarts with the token:
oa env set <slug> TELEGRAM_BOT_TOKEN=123456:ABC-... # or: curl -X PUT <api>/v1/artifacts/<slug>/env -H "Authorization: Bearer $OA_TOKEN" \ # -H 'content-type: application/json' -d '{"env":{"TELEGRAM_BOT_TOKEN":"123456:ABC-..."}}'- Open
<url>/setuponce. It registers<url>/telegramas the bot's webhook, using the URL the platform gives the service (OA_URL). - Message the bot.
Until the token is set, GET <url>/ answers with these steps instead of failing, so the service boots and stays healthy without it. With the token set, GET <url>/ shows the bot's username, whether the webhook is registered, and Telegram's last delivery error if there was one.
Environment
| Variable | Required | What it does |
|---|---|---|
TELEGRAM_BOT_TOKEN | yes | The token from @BotFather. The service boots without it and explains what to do. |
TELEGRAM_WEBHOOK_SECRET | no | The secret Telegram sends in X-Telegram-Bot-Api-Secret-Token with every update; anything without it is refused. Defaults to a value derived from the bot token, so it needs no setting. |
Environment variables are set over REST or the CLI (oa env set); the MCP tools do not set them.
Extend it
- Change what it says:
reply_to(text)inbot.pyturns a message's text into the reply. Call an API or a model there. - More update types (buttons, photos, groups): add them to
allowed_updatesinregister_webhook()and handle them indo_POST. - Replies that take longer than a few seconds: answer the webhook with
{}at once and send the reply yourself withtelegram("sendMessage", ...), because Telegram resends an update whose webhook is slow to answer.
What it costs
Prices for small, the size this template needs (current prices on openartifacts.sh):
- Asleep: no runtime charge. The bundle is stored at $0.05 per GB-month.
- Awake: $0.03 per awake hour, billed per minute, plus $0.216 per vCPU-hour of CPU actually used. A message wakes it and it stays awake 600 seconds (
sleep_after_s) after the last one, so an occasional conversation costs about $0.005 plus a little CPU. - Busy all day: awake around the clock is $0.72 a day plus CPU.
Starting it needs an hour of awake time in credit ($0.03), and an account runs one service per $1 of balance.
Files
README.md2.8 kBbot.py8.0 kBoa.json53 B
Every file, as JSON you can edit and publish: GET /v1/templates/telegram-bot.