Repository navigation
Releases
v0.17.0
Added
tg messages search --formsalso matches other forms of each plain word that occur in the
cache:квартираfindsквартируandквартирой,meetingfindsmeetings, andеще
findsещё; a word with a digit (2ms) or a stem of one or two letters (ok) stays as
typed. It works on the index's own words with light Russian and English stemmers, so the
index and older versions are unchanged.
Without the flag search stays exact. A query with FTS5 syntax or--phrasewith--formsis
INVALID_ARGS; whileallowedChatsis set,--formsmatches words only as typed, since the
forms come from the whole cache. Only visible transcripts of current attachments contribute
word forms. The answer addsforms, the forms searched for (null
without--formsor withallowedChats), andfilters.forms. The cache gets the tables
message_search_vocabandtranscript_search_vocab, the words of the message and transcript
indexes, whichtg sqlcan read. See docs/search.md.- The GitHub Release has
NOTICE, the licences of the ported stemmers, next to the binaries,
andbrew install neoromantic/tap/tginstalls it in the formula's prefix.
v0.16.0
Added
-
tg messages listtakes--type,--sinceand--until, so every voice note of a chat, or
the chat since Monday, is one command instead oftg api messages.searchwith a hand-built
peer and filter.--typetakes one or more message types, comma-separated or repeated
(voice,photo,video,document…), plusroundandanimationfor the round video
messages and GIFs thatvideoalso covers;--sinceand--untiltake the forms of
tg messages search. A filtered page reads only the cache, needs no credentials for a chat
the cache knows (a cached@usernameincluded, withallowedChatsset too), explains a name
the cache can't resolve, and pages with--beforeand--afteras before. It addscomplete,trueonly when one cached range covers the page up to the chat's
newest known message and, with--type, every message in it has its type (a date window never
guesses the date of a message the cache lacks);missing
(history,types) says why it isfalse,missingBeforewhere the newest gap ends, and
suggestionone sentence.nextof an incomplete page has what fills it
(tg messages list --fresh,tg db migrate), then the same page again, with--account
kept;nextcarries--sinceand--untilresolved to UTC seconds. Without the new flags the
output is unchanged.tg messages searchtakes--typetoo, echoes it infilters.typeand
addstypesPending; itsnextthen finishes a pending migration. Both commands suggest a
one-time manual fetch for media whose type is unknown. When only the type is missing,
listomits the automatic next page even if it has enough known matches to fill the limit. -
tg media downloadtakes several--idvalues and downloads the files of those messages of
the chat in one run: up to 100 IDs per fetch, one private-chat protection check, up to 5 files at
a time (2 of 20 MiB or more) and a flood wait that pauses the whole batch instead of failing
files. A file fails on waits only after six in a row with no part downloaded between them,
so a large download throttled by Telegram's speed limit completes. It prints one JSON line per file as each finishes, success or error, and exits 1 when
any failed. Cached files need no network and partial files resume, as before. One--id
prints what it printed before; a repeated--idstill runs as a batch, downloading the ID once. -
--outtakes a name template such as./media/{chat}/{date}_{id}_{name}(placeholders
{chat},{id},{date},{name},{kind}); each filled part is made a safe file name,
and one that exists as a symlink fails that file instead of being followed.
With several--id, a directory--outnames files{id}_{name}, so two photos no longer
collide onphoto.jpg. Repeating a batch accepts existing files with identical bytes. A
collision between different files in one batch returnsFILE_EXISTSeven with--overwrite.
Without--overwrite, a new file is published with a hard link; on a filesystem without
hard links (exFAT, FAT, some network shares) it is copied instead, never over an existing
file. If the copy is interrupted, use--overwriteto replace a partial export. -
Transcribe voice and video notes with a local Whisper program using
tg media transcribe. Search their transcripts withtg messages search, including snippets and counts.
Fixed
tg messages search --sinceand--untilwith milliseconds round up to the next second,
since message dates are whole seconds:--until 00:01:40.500Zno longer leaves out a message
sent at00:01:40, and--sincewith milliseconds no longer takes one sent just before it.
Itsnextcarries the bounds resolved to UTC, so a relative bound (60s) keeps its window
across pages.- With
allowedChatsset,tg messages searchresolves its chat and the list from the cache
alone, so a cached@usernamewithout an access hash needs no credentials again. tg messages search --freshisINVALID_ARGSthat says search reads only the cache, instead
of a generic unknown option.- A string flag's value that looks like a repeatable flag is no longer read as that flag:
tg send --caption '--file=x'sends that caption. - A cached page of history vouches for the IDs above its newest message only up to the chat's
newest message known before the request: a fetch that Telegram answers with nothing new now
settles the gap (tg messages list --before 21 --freshbelow a known message 30, a chat
Telegram shows empty, or a chat whose newest messages were deleted), and a message cached while
the request ran no longer vouches for a page that could miss a message sent meanwhile. The
daemon's history pages follow the same rule.
v0.15.2
Fixed
tg media downloadworks on Windows. It failed withEPERM: operation not permitted, ftruncatebefore the first request, because it truncated the partial download through a file
opened for appending. A resumed download keeps its whole parts as before (#233).
v0.15.1
Fixed
- A boolean flag with a value other than
trueorfalse(--silent=noand--silent=0,
which ran as--silent) isINVALID_ARGSinstead of being read as set (#217). tg send,tg messages readandtg apiwrite methods resolve an@usernamethrough
Telegram, not the cache, so a username that moved never sends to its previous owner. The
allowedChatscheck of a write resolves the list's@usernameentries the same way: an entry
allows the chat that holds the username now, not its previous owner by ID. Reads take the
latest fetched owner of a username (#217).- The daemon no longer deletes an account when two accounts sign in as the same Telegram user.
It picked the one to keep by the kind of phone, so it could delete the account with the cache,
label and active choice, or the one with the only working session. Now it leaves both and
doesn't sync the second; its error says to log in again or remove it.
v0.15.0
Added
- An agent skill,
skills/telegram-sync-cli/SKILL.md: when to usetg, finding chats and
messages, counting and reading whole chats with onetg sqlquery and checking that the
cache covers the chat, confirming beforetg send, the error schema and the exit codes.
Install it withbunx skills add neoromantic/telegram-sync-clior
tg skill install --dir <skills dir>, which writes the same file fromtgitself. A test
runs every command in its examples against made-up data and checks the answers of its SQL. tg skill validatereports the account record the next command uses without--account
(account,accounts_total):activeAccountinconfig.json, else the active account,
else the only one. It also reports whether a live process holdsdaemon.pid
(daemon: { status, pid }). Neither checks that the session is authorized or online. No
account, several and none active, or an invalidconfig.jsonis an issue. Each value is
read on its own: one that can't be read isnull(accounts_total) orunknown
(daemon.status), with the reason, and the others stay accurate.tg send --markdownand--htmlsend rich messages such as headings and tables on
supported accounts. The result includesformat. File captions stay plain text.
Changed
-
tgstarts about five times faster for every command that answers from the cache, and for
--helpand--version: it loads the Telegram client library only when a command calls
Telegram (0.1 s of CPU instead of 0.5 s on a source install). -
A group (basic group or supergroup) adds new messages to the cache only while you take part
in it: you sent an ordinary message there in the last 90 days. Reading a group doesn't count.
The rule holds in everytg chats syncmode and intg messages list/get,--fresh
included (which still return Telegram's page). Messages already cached stay; private chats
and channels are unchanged. After each dialog pass the daemon asks Telegram once per group
for your newest message of the last 90 days, at the lowest priority. Your next message in a
group, from any device or withtg send, turns it back on; the messages of the pause aren't
fetched later.tg chats listandtg chats syncshow such a group withsyncEnabled: false,
the reasongroup_participation_requiredorgroup_participation_unknownand
lastOwnMessageAt, andtg statusleaves it out of the chats with sync on and of the history
progress. See docs/sync-strategy.md. -
Breaking:
tg skillinstalls only the Markdown skill. tg 0.14.0 and older wrote
<dataDir>/skill.jsonthere and ignored--dir. Now:tg skill manifestis removed;tg skill installneeds--dir, the agent's skills directory, and rejects an empty one;- it writes
<dir>/telegram-sync-cli/SKILL.mdinstead of<dataDir>/skill.json,
replacing a file already there, local edits included, and refusing a symbolic link for
telegram-sync-cliorSKILL.md(the skills directory itself may be one); - its JSON drops
data.manifestand keepspath,bytesandoverwritten.
Replace
tg skill installwith:tg skill install --dir ~/.claude/skills -
Breaking:
tg skill validatereports a missing account as an issue, so before
tg auth loginit printsvalid: false, still with exit 0. tg 0.14.0 and older checked only
the credentials and the data directory. -
Breaking:
src/db/index.tsno longer exportsdb, the opendata.dbconnection. Code
that imports it from the package source callsgetDataDb(), which opensdata.dbon first
use.
Fixed
tg skill installandtg skill validatework with a corruptdata.db, which stopped every
command with a SQLite stack trace before it started:data.dbnow opens when a command first
reads an account. Install writes the skill, and validate names the file as an issue.- A command acts on the chat and account it checked against
allowedChats: the check pins the account and hands its resolved chat to the command, so a
switch of the active account or a second lookup in between can't move it (#217). - A flag a command doesn't declare (
--acount 2) and a value after a boolean flag
(--silent false, which ran as--silent) areINVALID_ARGSinstead of being ignored (#217). - A Telegram call that succeeded is no longer reported as failed when tg can't write it to its
localapi_activitylog, so a retry doesn't repeat a send (#217). - The npm package declares
long, which tg imports directly. Until now it only arrived
through@mtcute/core, so an install that doesn't hoist transitive dependencies could fail
to start. tg auth login --phoneworks for a user who already has an account under another phone,
such as theuser:<id>account of a QR login or a number they have since changed (#213).
The phone moves to that account, which keeps its cache. Until now the login failed with
UNIQUE constraint failed: accounts.phoneand left a second account behind.- A login of a user who already has an account under another phone or a QR login gives that
account the new session. Until now the account kept its old session, so after the old
session was ended in Telegram the login succeeded but the account stayed signed out.
v0.14.0
Added
- Every error says whether running the same command again can work:
error.retryableis
trueforRATE_LIMITED,NETWORK_ERROR, a media download that waited too long for
another tg process and atg apicall Telegram failed on its side (500 or -503),false
otherwise (#160). Nothing else in the error schema changes. RATE_LIMITEDcarries the suggestionWait <n>s, then run the same command again(for a
media download, "… to resume the download"), with the wait indetails.wait_secondsas
before, from every command:tg api,tg send,tg chats,tg contacts,tg user,
tg messagesandtg media download.ACCOUNT_NOT_FOUNDsuggeststg accounts listand the flag to pass the account to
(--account, or--idfortg accounts switch,removeandinfo).tg send --towith a
user ID Telegram refuses (PEER_ID_INVALID) suggests sending to the user's@usernameor
+phoneonce, so tg caches the user.nextin success answers: a list of{ command, why }besidedata, wherecommandis a
completetgcommand line that runs as written in a POSIX shell andwhysays what it does
(#160). A paged read that has more suggests its next page with the account and every filter
it was given:tg messages list(older pages, or newer ones after--after),
tg messages search,tg chats list,tg contacts list, andtg messages wait --chat,
which suggests waiting on from the last message it returned.tg chats searchwith no
result suggeststg chats list --fresh, then the same search, where before the command was
only inmessage. An answer with nothing to suggest has nonext, and every existing field
(message,nextBefore,nextAfter,hasMore,offset) is unchanged.--format pretty
prints the suggestions on stderr, so stdout stays the data's JSON;--quietprints nothing.
Changed
- The
datafields oftg chats listare declared once, in
src/commands/chats/list-output.ts: the command's types come from it, the field table in
docs/cli-commands.md is generated from it (bun run docs:outputs), and
an e2e test fails when the command prints a field the declaration doesn't have (#160, a trial
on one command). The output doesn't change. zod is a devDependency and doesn't ship.
Fixed
tg messages list,get,search,unread,waitandwatchshow the content of a rich
message: one whose content is page blocks (headings, tables, lists, quotations, code,
formulas, footnotes, media) instead of a text. It printed astext: null, so an agent saw an
empty message where a table or a whole report was sent, and search could not find it. Its
textis now the blocks in Telegram's rich Markdown (#headings, pipe tables,- [x]task
lists,$$…$$formulas,[^1]footnotes, HTML tags such as<details>where Markdown has
none), with a placeholder for media, maps and buttons ([photo: caption]).messageType
staystext. The text is cached, so search matches any word of it, a table cell's too.
Messages cached by older versions print it fromraw_jsonat once, and a background
migration (messages_rich_text) makes them searchable.
v0.13.1
Fixed
tg messages search --chat mesearches Saved Messages and--sender mefinds your own
messages:me(any case) is the account's own user ID, read from the account without a
Telegram call. Before, both returned nothing and still succeeded. When the account doesn't
know its user ID yet,meisINVALID_ARGS(exit 3) with a hint to runtg meonce. A
--chator--sendervalue that is neither an ID, a username norme(a typo such as
12abc) isINVALID_ARGSnaming the flag, instead of an empty success.tg apitypes its arguments by the method's TL schema, so the documented examples work:
tg api messages.getHistory --peer me --limit 1and
tg api messages.sendMessage --json '{"peer":"@user","message":"Hi"}'failed with
Unknown object undefined. A chat given as a string or number where the method takes an
InputPeer, InputUser or InputChannel (peer,idofusers.getFullUser,channel…)
resolves liketg send --to(me,@username,+phone, a marked ID; cache first); a long
given as a number or decimal string becomes a Long (before,--hash 123went out as 0); a
required int or long left out is 0 (offsetId,maxId,hash…), a requiredrandomIdis
random and a requiredoffsetPeerisinputPeerEmpty. A chat of the wrong kind (a group as
a user) isINVALID_ARGS. Full TL objects go as before.
v0.13.0
Commands for agents: wait for a reply, read and mark unread messages, and keep an agent
read-only or to a few chats.
Added
tg db vacuumchecks the free disk before a full VACUUM (daemon stopped): it needs 2.2 times
the cache file plus 64 MB, as the storage benchmark measured. When the disk is short it fails
at once withGENERAL_ERROR,details.reason: "disk_full", the bytes needed and free, and
changes nothing, instead of failing after minutes of work.tg statusshows the same check
next to its vacuum hint (#119).tg messages waitblocks until the daemon stores a new message, then returns the new messages
oldest first, in the same shape astg messages list;tg messages watchprints each one as a
JSON line as it is stored, until Ctrl-C or SIGTERM. Both read only the cache (no second
Telegram session) and return within about a second of the daemon storing a message.
--chatkeeps one chat,--after <id>returns that chat's cached messages newer than it at
once,--settle Nkeeps collecting until N quiet seconds, and after--timeout(default
60 s) the result is{ "messages": [], "timedOut": true }with exit 0. Without a running
daemon they fail at once withDAEMON_NOT_RUNNING(#24).- Unread messages (#25).
tg chats list --unreadlists only chats with unread messages, and
every chat item hasunreadCount.tg messages unread [--chat <peer>] [--limit N]prints each
chat's oldest unread messages from the cache with its unread count andmissing, how many of
them the cache lacks;--freshreads the counts and those messages from Telegram.
tg messages read --chat <peer> [--max-id <id>]marks a chat read on Telegram
(messages.readHistory, orchannels.readHistoryfor supergroups and channels) and caches
its new count.chats_cachegetsunread_countandread_inbox_max_id, which dialog lists
set; the daemon raises the count for each new incoming message and takes reads on any device
from Telegram's read updates, so the counts stay current between dialog passes. A cache from
an older version has no counts until the daemon's next start ortg chats list --fresh. - Read-only mode and a chat allowlist for agents (#26).
readOnlyinconfig.jsonor
TELEGRAM_SYNC_CLI_READ_ONLY=1refuses, before connecting, every command that changes
something on Telegram with the new codeREAD_ONLY(exit 1):tg send,tg messages read,
tg apimethods not namedget…,search…,resolve…orcheck…, andtg auth login,
login-qrandlogout.allowedChats(orTELEGRAM_SYNC_CLI_ALLOWED_CHATS, which replaces
it for one process) limits commands to those chats: one that names another chat fails with
CHAT_NOT_ALLOWED(exit 1),tg chats list,tg chats search,tg messages search,wait,
watchandunreadshow only allowed chats, andtg sqlandtg apiare off.tg status
shows both underaccess. They guard against mistakes and are not a security boundary.
Changed
tg auth login-qrdraws its QR code with uqr instead of
qrcode-terminal, which has had no release since 2018. The code is black on white with the
standard four-module quiet zone, so it scans in dark and light terminal themes, and it goes to
stderr with its status lines, so they no longer mix with the JSON result on stdout (#10).- The daemon raises a chat's
last_message_idandlast_message_atwith each live message, so
tg chats listkeeps the order of recent activity between dialog passes.
Fixed
tg db migratewith the daemon stopped no longer locks othertgcommands out of the cache: it
ran its batches back to back, and on a big cache a command that wrote meanwhile (tg messages listcaching a page,tg sendcaching the sent message) could give up withdatabase is lockedafter 5 s. It now pauses 150 ms after each second of work, so such a write gets in
within about a second; the run takes up to 15% longer (#122).
v0.12.2
Fixed
tg sql "SELECT 1 AS one" -f jsonruns the query: the value of-f/--formatafter a positional
query was added to the SQL (SELECT 1 AS one json, a syntax error), and after--queryit was
refused as an extra argument.tg sql -f json print-schemaprints the schema.tg messages list,getandsearchsay what a service message did. A call, a pin or a
group change used to print onlymessageType: "service"with no text, so an agent reading a
chat could not tell a call had happened. Every item now hasaction, read fromraw_json(so it
works for messages cached by older versions too),nullfor other messages: a call gives
video,durationand why it ended (missed,busy,hangup,disconnect), a pin the
pinned message, a group change the new title or the users added or removed. Any other action
gives its type name.tg statusno longer counts a sender whose every cached message is deleted as missing:
nothing is left to ask Telegram for, and search doesn't show those messages by default. On a
1.16M-message cache, 1,125 of the 1,376 senders still missing after the first fetch were such
senders (#143).- Several commands can open a new cache together without failing to initialize its search index.
v0.12.1
Fixed
- The daemon fetches the senders that cached messages name but the cache lacks, so
sender:namefinds their messages andtg messagesshows their names. Caches synced before
0.9.0 have many (about 3% of the messages of a 1.16M-message cache), and a live message still
leaves one now and then. Once a day the daemon asks Telegram for one message of each such
sender by ID, up to 100 per request, only when it has no other sync work: on a made-up cache of
that shape, 349 requests for 2,960 senders. A sender Telegram doesn't return is asked again
30 days later.tg statusshows how many senders are still missing (#143).