OpenArtifacts

openartifacts.sh / templates / telegram-bot

Telegram bot

Python 3.11, standard library · size small · 3 files, 10.9 kB

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

  1. In Telegram, message @BotFather, send /newbot, and copy the token it gives you (123456:ABC-...).
  2. 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-..."}}'
  3. Open <url>/setup once. It registers <url>/telegram as the bot's webhook, using the URL the platform gives the service (OA_URL).
  4. 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

VariableRequiredWhat it does
TELEGRAM_BOT_TOKENyesThe token from @BotFather. The service boots without it and explains what to do.
TELEGRAM_WEBHOOK_SECRETnoThe 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

What it costs

Prices for small, the size this template needs (current prices on openartifacts.sh):

Starting it needs an hour of awake time in credit ($0.03), and an account runs one service per $1 of balance.

Files

Every file, as JSON you can edit and publish: GET /v1/templates/telegram-bot.


← all templates · openartifacts.sh · docs.md · skill.md