Oscar talks to Telegram as a bot over the Bot API with long polling: no webhook, no public address, no open port.
Set it up
- Create the bot. In Telegram, open @BotFather, send
/newbot, pick a display name and a username ending inbot. BotFather answers with a token like123456789:AA…. - Store the token in
$OSCAR_HOME/credentials.env(mode 0600):TELEGRAM_BOT_TOKEN=123456789:AA... - Say who may talk to Oscar. Your numeric user id is the safe choice
(open @userinfobot and it tells you); a
@usernameworks too, but a username can change hands. Several are separated by commas:This can go inTELEGRAM_ALLOWED_USERS=123456789,@youcredentials.env, the environment, orconfig.tomlastelegram_allowed_users = "123456789". Or let the bot find you:oscar telegram owner --add, then send the bot any message in a private chat — the sender's id is put on the list (oscar setupoffers the same). - Check it:
oscar telegram probeprints the bot's name and id and who is allowed (never the token).oscar doctorhas atelegramline too. - Run it:
oscar telegram serve(Telegram alone) oroscar gateway serve(every configured platform; see Chat gateways, also for running it as a service). - Talk to it: open your bot in Telegram and press Start.
/startshows the commands; they are also in the/menu Oscar publishes.
On start Oscar removes a webhook if the bot had one (polling cannot run beside it).
The / menu lists Oscar's commands, then your skills, most used first, as
many as fit in Telegram's 100 commands (my-skill is offered as
/my_skill). When the skills change (/reload_skills, an accepted skill,
or a change made elsewhere, looked for every five minutes) the menu is
published again, only when its commands changed and at most once a minute
(flood control is waited out).
Topics in private chats
When you turn on topics for your private chat with the bot (Telegram's
threaded mode), each topic is a conversation of its own, like a forum
group's topics. /topic [name] opens one; [rooms."telegram:<chat>:<topic>"]
gives one its own settings (skills = [...] loads skills there), and a
topic is renamed to its conversation's title when it gets one (see
topics).
Groups
Add the bot to a group like any member. In groups Oscar answers only when
addressed: an @mention of the bot, a reply to one of its messages, a
command (/status, /new@yourbot), or a wake word
(telegram_mention_patterns). Messages from people not on the allowed list
are ignored there (in a private chat they are told no). The model sees who
wrote each message ([Yuri K|123456789] …) and the group's title, and may
stay silent when a message is not for it.
Privacy mode. By default Telegram gives bots in groups only commands and
replies to their own messages. To be addressed by @mention, or to use
free-response chats, turn privacy mode off: @BotFather → /setprivacy →
your bot → Disable (then remove the bot from the group and add it again,
so Telegram applies it), or make the bot an admin of the group.
Forum topics are separate conversations, each with its own session, and
replies stay in the topic; a topic is named chat/topic
(-1001234567890/42). In a group each person has a conversation of
their own unless telegram_group_sessions = "shared" (see
rooms shared by several people).
A room's own settings go in [rooms."telegram:-1001234567890"] (one topic:
[rooms."telegram:-1001234567890/42"]); require_mention = false there
makes that chat (or topic) free-response. Admin commands (/pair,
/voice, /platform, /restart, /update, /sethome, /mention) are
in the / menu too; in a group they need the bot's name
(/pair@yourbot ABCD-EFGH) unless the group is free-response.
| Variable (config key) | Meaning |
|---|---|
TELEGRAM_REQUIRE_MENTION (telegram_require_mention) |
false: answer every message in groups (default true); /mention on|off|default changes one chat |
TELEGRAM_FREE_RESPONSE_CHATS (telegram_free_response_chats) |
group ids where every message is for Oscar |
TELEGRAM_ALLOWED_CHATS (telegram_allowed_chats), TELEGRAM_GROUP_ALLOWED_CHATS (telegram_group_allowed_chats) |
when set, the only groups Oscar answers in (both lists count; private chats are not affected) |
TELEGRAM_MENTION_PATTERNS (telegram_mention_patterns) |
wake words: comma-separated regular expressions, any case (\boscar\b, hey bot); a group message matching one is for Oscar |
TELEGRAM_ALLOWED_TOPICS (telegram_allowed_topics) |
when set, the only forum topics answered in |
TELEGRAM_IGNORED_TOPICS (telegram_ignored_topics) |
forum topics never answered in |
TELEGRAM_FREE_RESPONSE_TOPICS (telegram_free_response_topics) |
forum topics where every message is for Oscar |
TELEGRAM_ALLOW_BOTS (telegram_allow_bots) |
messages from other bots: off (default), mentions, all — the bot must be an allowed user too |
Group ids are negative numbers such as -1001234567890; bots that show chat
details (for example @RawDataBot) tell you a group's id.
What it looks like
- Replies are formatted (bold, code blocks, lists, links) and split under Telegram's 4096-character limit.
- Approvals and questions come with buttons; after a press the buttons go and the decision is added to the message. A press from someone not on the list gets a short "not on this bot's list" and changes nothing.
- While working, Oscar shows "typing…" and edits a quiet activity message
with a line for each new tool and a short preview of what it does
(
TELEGRAM_PROGRESS:off,new(the default here),all,verbose;/verbosecycles them for one chat; see tool activity). Reactions are off by default (TELEGRAM_REACTIONS=onadds 👀 while working and 👍 or 👎 after; Telegram allows only a fixed set of reaction emoji);TELEGRAM_TYPING=falseturns the typing indicator off. A message sent during a turn gets a short silent note (⚡ redirected, ⏳ queued, ⏩ steered). Status messages, prompts and notices are sent without a notification. - Voice notes, photos, documents, and spoken or picture replies: see Voice, pictures and files. The public Bot API lets a bot download files up to 20 MB and send up to 50 MB (photos up to 10 MB; a bigger picture goes as a document). Videos go out as videos and GIFs as animations.
- Albums: photos or files sent together (one album) arrive as one turn
with all of them; parts that come within about 1.5 s of each other are
folded together, and the caption of whichever part has one is the
message. When a reply carries two to ten pictures or videos, they go out
as one album (
sendMediaGroup); anything else goes one by one. - Stickers reach the model too: a static sticker as a picture with a
note (
[sticker: 👍]), an animated or video sticker as the note alone. - Locations: a shared location or venue reaches the model as
[location: 52.520008, 13.404954 — Alexanderplatz, Berlin]. A live location is taken once, when sharing starts (its updates are not turns).
Observe mode
With telegram_observe_groups = "on", Oscar keeps the recent messages of
the groups it may answer in (the allowed chats and topics) even when it is
not addressed, and shows them to the model as context when it is mentioned
there, so "@yourbot what do you think of that?" works. Only messages from
allowed users are kept (pairing approvals count), the last
telegram_observe_messages (default 30) per chat, text only (a picture is
noted as [a picture], never fetched).
Privacy: these messages are kept in the gateway's memory only — never in
the session store, the delivery ledger or any file — and are gone on
restart. They reach the model provider only with a turn someone started by
addressing Oscar, marked as other people's words rather than instructions.
A conversation that got them counts as having read untrusted content:
what the background reviews would learn from it waits for your yes (see
review_untrusted in skills and learning).
Tell the group that the bot reads along. Telegram itself only shows a bot
the messages of a group when privacy mode is off (see above).
| Variable (config key) | Meaning |
|---|---|
TELEGRAM_OBSERVE_GROUPS (telegram_observe_groups) |
on: keep recent group messages in memory as context for a mention (default off) |
TELEGRAM_OBSERVE_MESSAGES (telegram_observe_messages) |
how many per chat (default 30, at most 200) |
Webhook mode
Polling (the default) needs no public address. For a host that should sleep when idle, or one behind a load balancer, Telegram can post updates to a public HTTPS URL instead:
telegram_mode = "webhook"
telegram_webhook_url = "https://bot.example.org/telegram" # what your reverse proxy serves
telegram_webhook_listen = "127.0.0.1:8443" # where Oscar listens (the default)Oscar listens on telegram_webhook_listen (a bare port means 127.0.0.1),
answers only POST on the URL's path (/telegram here), and registers the
URL with Telegram at start. TLS is your reverse proxy's job (Caddy,
nginx): Telegram posts only to https:// on ports 443, 80, 88 or 8443, and
the proxy forwards to the local address. Every request must carry the
secret token in X-Telegram-Bot-Api-Secret-Token; anything without it is
refused (401) before its body is read. The token is made once and kept in
telegram-webhook-secret in Oscar's home (mode 0600), or set it yourself
with TELEGRAM_WEBHOOK_SECRET (1-256 letters, digits, _, -). Switching
back to polling removes the webhook at the next start.
| Variable (config key) | Meaning |
|---|---|
TELEGRAM_MODE (telegram_mode) |
polling (default) or webhook |
TELEGRAM_WEBHOOK_URL (telegram_webhook_url) |
the public https:// URL Telegram posts to |
TELEGRAM_WEBHOOK_LISTEN (telegram_webhook_listen) |
the local address:port (default 127.0.0.1:8443) |
TELEGRAM_WEBHOOK_SECRET |
the secret token, instead of the one Oscar keeps (environment or credentials.env) |
Other settings
| Variable | Meaning |
|---|---|
TELEGRAM_ALLOW_ALL_USERS=true |
answer everyone (careful: anyone who finds the bot) |
TELEGRAM_PAIRING=on (telegram_pairing) |
strangers who write privately get a pairing code an admin approves |
TELEGRAM_ADMINS, TELEGRAM_APPROVERS (telegram_admins, telegram_approvers) |
ids or @usernames: who may use the admin commands, who may answer approvals (roles) |
TELEGRAM_POLL_TIMEOUT |
seconds each poll waits (default 25, at most 50) |
TELEGRAM_API_URL |
a local Bot API server instead of api.telegram.org; then files up to 50 MB are fetched |
TELEGRAM_PROXY |
every Bot API call through a proxy: http://, https://, socks5:// or socks5h://, with user:password@ if needed (proxies) |