@tote/bot-telegram
On this page (3 sections)
Self-hosted Telegram bot for one owner. It runs the same agent loop as tote ask.
Design: ADR-001 decision 12.
The bot long-polls Telegram with grammY 1.46.0 (bot.start()). It does not open a port,
does not set a webhook, and does not use @grammyjs/runner. Tote never pays. Checkout
ends when the owner opens the merchant link.
grammY docs, fetched 2026-11-20:
- Long polling: https://grammy.dev/guide/deployment-types
- Inline keyboards: https://grammy.dev/plugins/keyboard
- API call pipeline: https://grammy.dev/advanced/transformers
callback_datais 1 to 64 bytes: https://core.telegram.org/bots/api#inlinekeyboardbutton
Tests do not call Telegram. They pass grammY's client.fetch and answer sendMessage
and answerCallbackQuery locally. The request URL is not stored, because it contains
the bot token.
The published package grammy@1.46.0 was checked the same day at
https://registry.npmjs.org/grammy/latest. Its scripts are prepare (deno2node) and
backport. It has no preinstall, install or postinstall. prepare does not run
when pnpm installs the registry tarball. Its direct dependencies are the same: no
preinstall, install or postinstall. @grammyjs/types 5.0.0 and node-fetch 2.7.0
have a prepare build script of the same kind. debug 4.4.3 and abort-controller
3.0.0 have neither. sensitiveLogs stays false, so a Bot API error does not include the
request URL (the URL contains the bot token).
Run
From the repo root, with the variables in Configuration set:
npx -y pnpm@10.20.0 --silent --filter @tote/bot-telegram tote-bot
or:
node packages/bot-telegram/bin/tote-bot.js
Node 22.19 or newer. There is no build step. bin/tote-bot.js runs the TypeScript source
with Node's type stripping, same as tote. Stop the process with SIGINT or SIGTERM.
The process replies only in TELEGRAM_CHAT_ID. Use your private chat id. Any other chat
gets no reply and no log line.
What a message does
Each text message starts one runAgent call. The prompt is that message. Quantity is
read from those words inside the agent, the same way tote ask reads it. The override
policy is deny. A second message while a run is in progress gets:
Tote is busy with your previous message. Wait for it to finish.
The reply uses the same verdict words as tote ask: satisfies,
satisfies_pending_shipping, incomplete, violates, and out of stock. Check marks
are met, UNMET, unknown, and at checkout.
A checkout or cart handoff does not include the merchant link. The message has an inline
button, Show checkout link. The button data is a random id, not the link. After you tap
it once, the bot sends:
This link opens the merchant checkout. Tote never pays.
https://...
A second tap says the link was already shown and does not send it again. The link is not written to the log and is not sent to the model. Sending it to Telegram means it leaves this machine. That is the trade for chatting there.
Requests longer than 2000 characters are refused before a model call. A photo or other non-text message gets a one-line reminder to send text.
Configuration
The bot loads .env from the current directory, then from the repo root, with
process.loadEnvFile. A variable already set in the shell wins. The variables below are
also documented for the CLI in packages/cli/README.md, except the two Telegram names,
which belong to this package. .env.example at the repo root does not list the Telegram
names yet.
# Required. The https URL of the Tote agent profile (ADR-001 decision 3, human task H-04).
TOTE_AGENT_PROFILE_URL=https://<domain Tote controls>/<path to the agent profile>.json
# Optional, both or neither. Dev Dashboard client credentials select the Token tier.
SHOPIFY_CLIENT_ID=<client id>
SHOPIFY_CLIENT_SECRET=<client secret>
# Required at the Token tier: your own current public IPv4 or IPv6 address.
# This process has one owner, so this is that owner's address (ADR-001 decision 12).
TOTE_BUYER_IP=<your public IP address>
# Required. Form provider:model.
TOTE_MODEL=<provider>:<model>
# Optional. Your delivery country, ISO 3166-1 alpha-2, for example PL.
TOTE_SHIPS_TO=<country code>
# Required. From BotFather. Read with core's parseSecret. Never printed.
TELEGRAM_BOT_TOKEN=<bot token>
# Required. The only chat the bot answers. Your private chat id.
TELEGRAM_CHAT_ID=<chat id>
# The key of the provider in TOTE_MODEL. One of:
# ANTHROPIC_API_KEY, OPENAI_API_KEY, GOOGLE_API_KEY (with GOOGLE_API_TIER=paid),
# OPENROUTER_API_KEY
Model ids match the CLI. See packages/cli/README.md, section Models. anthropic,
openai and google run the Index v0 presets. openrouter takes any OpenRouter slug
and requests zero data retention.
- Without
TOTE_AGENT_PROFILE_URLthe process exits 2 and names the variable. - With neither Shopify credential set, the run uses the Anonymous tier. Checkout is not available at that tier. A cart handoff still works.
- With only one of the two credentials set, the process exits 2.
TOTE_BUYER_IPis required at the Token tier. Core refuses loopback, private, link-local, documentation and other non-public addresses. The error names the variable and does not echo the value. There is no third-party IP lookup.TOTE_SHIPS_TOadds aships to <country>constraint. The country is not read from the message text. Catalog data has no shipping destinations, so the mark isat checkout.TELEGRAM_CHAT_IDis digits, with an optional leading minus. A value that does not match exits 2 and does not echo the value.TELEGRAM_BOT_TOKENis a coreSecretas soon as it is read. Logs do not contain it.sensitiveLogsstays false. Do not setDEBUGto a grammY namespace: the library's own debug lines are outside this package.
Live Telegram calls need a token from the maintainer (H-08). This package's tests do not make them.