Auto-replies
Configure owner-written reply rules for Telegram, test them without sending, and control replies restricted to named test accounts.
tg serve can answer incoming messages by rules you write. Two things keep it from writing to
people you did not mean:
- It answers only test accounts. A reply goes only to a sender listed in
testersin the rules file. A new file has an emptytesters, so nobody gets a reply until you add your own test account. - Sending is off until you turn it on.
permissions.replies.sendmust beallow.askcounts as no, because a background server has nobody to ask.
The full option lists are in commands.md.
Create and enable a rule
tg replies add away
tg replies edit away --template 'Thanks, {{ sender.firstName | default: "there" }}! I will answer in the morning.'
tg replies edit away --outside 09:00-19:00 --days mon-fri --timezone Europe/Madrid
tg replies edit away --per-chat 1/12h --per-person 1/1dadd creates a rule that is off, with every setting written out. The rules live in
<profile>.replies.json, in the same folder as the configFile that tg config show --json names.
Put the id of your test account in its testers:
{ "testers": [{ "id": "1000001" }], "rules": [ … ] }Rule ids are lower-case letters, digits and -, and each is unique. A rule that replies cannot be
turned on with an empty template.
Then look at what it would have answered, turn it on, and start the server:
tg replies test --since-time 7d
tg replies on away
tg config set permissions.replies.send allow
tg servereplies test reads only messages already in your local store. It sends nothing, changes nothing
and never connects. tg replies off away turns one rule off.
Conditions and audience
replies edit changes only the fields you name. A comma-separated list replaces the whole list; an
empty string clears it.
| What | Options |
|---|---|
| Action | --do reply,task — a reply, a task, or both |
| Chats | --kinds dialog,group, --chats, --not-chats |
| Conditions | --words, --question / --no-question, --mentions-me / --no-mentions-me |
| Senders | --people, --not-people, --contacts-only / --no-contacts-only |
| Reply | --template, --as-reply / --no-as-reply |
| Limits | --per-chat, --per-person, such as 1/12h |
| Working hours | --outside, --days, --timezone, --no-hours |
The first time you set working hours, give the window, the days and the time zone together; after
that you can change one. A wrong edit does not overwrite the file, and the other rules, testers and
the record of what was answered stay as they were.
tg replies audience shows who the whole file may answer. --reply all allows anyone; --reply listed
only the allowed lists. --allow-people, --allow-chats, --deny-people and --deny-chats replace
those lists, and a denial wins over an allowance. testers still applies on top of the audience. A
task action opens a task on this computer and is not limited by the audience.
Templates and a model
A template can use sender.firstName, sender.name, chat.title, chat.kind and now (in the
rule's time zone, or UTC without working hours), with filters such as {{ now | date: "%H:%M" }}. The
incoming message's text is not a template variable. Unknown variables and filters are refused.
A model may write only the ai block; everything outside it is your text:
Thanks, {{ sender.firstName | default: "there" }}!
{% ai %}Briefly confirm you got the message; I will answer tomorrow.{% else %}I will answer tomorrow.{% endai %}The block's body is an instruction to the model. The incoming text goes to the model separately, as
data. When no model is set up, there is no consent, or the call fails, the else text is sent; without
an else, the message gets no reply and the reason is recorded.
Choose the model with models.replies.provider (openai or anthropic), models.replies.model and,
for your own server, models.replies.baseUrl; models.default fills what is not set. Keep the key with
tg models text key set.
Using a model needs its own consent, separate from the right to send:
tg replies consents show
tg replies consents grant
tg replies consents revoke
tg replies consents deny -1002000002
tg replies consents allow -1002000002grant lets incoming message data go to the chosen provider for the whole profile. deny keeps one
chat's messages away from the model; allow removes that, without granting consent. A new provider
or endpoint needs consent again. tg replies test --ai sends stored messages to the model so you can
see its text; it still sends nothing to Telegram.
What a rule never answers
- Your own messages, channels, bots, and messages sent on behalf of a chat.
- An edited message, a message already handled, and anything that arrived before
servestarted. - In a group, a message that neither mentions you nor replies to you, unless the rule names that group
in
chats.
perChat and perPerson limits are required on every rule, so two auto-repliers that answer each
other stop at the first limit.
Stop and look
tg replies pause
tg replies resume
tg replies status
tg sends listpause stops every rule at once, a running serve included, without a restart; resume undoes it.
status says whether sending is allowed, which rules are on and who they may answer. sends list
shows each reply with the rule that sent it.