When telegram.json exists in the data directory, the daemon runs a
Telegram bot next to the socket clients. The file holds the bot token
and the user ID of the owner, and the daemon refuses it unless its mode
is 0600, because the token is a secret. The bot uses getUpdates long
polling only, so it needs no webhook and no open port.
The bot reads only the text messages of the owner in the private chat
and ignores every other update without a log of its content. Each text
goes to the agent as a user message from the source telegram, and /stop
interrupts the turn. A message that is not text gets the answer that
only text is supported. The chat gets the replies as plain text in parts
of at most 4096 UTF-16 units, the errors as short messages, and the
messages typed in the terminal with a mark. It shows the typing action
while a turn runs. Tool calls stay out of the chat, so the phone stays
readable and the bot stays far from the rate limit.
agent/telegram-offset.json holds the next update ID. It moves past an
update only after the message is flushed to the log, so a restart loses
no message. A crash between the flush and the offset write repeats that
message once, which the user accepts. A failed Bot API call waits and
tries again, as long as HTTP 429 asks or from one second up to a minute,
and never stops the agent. A failed write of a message or of the offset
stops the daemon, because the bot could then lose or repeat messages.
Issue:
a143bd8