@will-17173/telegram-cli 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +73 -459
- package/README.zh-CN.md +72 -455
- package/dist/cli/app.js +1 -1
- package/dist/presenters/ink/listen.js +85 -17
- package/dist/presenters/ink/listen.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,547 +1,161 @@
|
|
|
1
1
|
# Telegram CLI
|
|
2
2
|
|
|
3
|
-
[简体中文](README.zh-CN.md)
|
|
3
|
+
[Project website](https://will-17173.github.io/telegram-cli/) · [Telegram CLI documentation](https://will-17173.github.io/telegram-cli/docs/) · [简体中文 README](README.zh-CN.md)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Telegram CLI is a TypeScript command-line interface (CLI) for live Telegram data, local SQLite search, and remote management. Use one `tg` command from a terminal, a script, or a coding agent. Account sessions and synced messages stay on your machine.
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## Read the documentation
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
- Inspect unread chats and read or search messages without storing them locally.
|
|
11
|
-
- Sync chat history to SQLite for offline search, filtering, analysis, and export.
|
|
12
|
-
- Archive selected chats as incremental Markdown files, with optional attachment downloads.
|
|
13
|
-
- Listen for new messages and download incoming attachments.
|
|
14
|
-
- Send, edit, and delete messages from the command line.
|
|
15
|
-
- Inspect contacts, notification settings, chat folders, groups, members, administrators, invites, and forum topics.
|
|
16
|
-
- Disable remote Telegram mutations while keeping read-only and local commands available.
|
|
17
|
-
- Use human-readable, JSON, YAML, or Markdown output in scripts and agent workflows.
|
|
9
|
+
Read the [complete Telegram CLI documentation](https://will-17173.github.io/telegram-cli/docs/) for installation, workflows, every command, automation, safety, and troubleshooting.
|
|
18
10
|
|
|
19
|
-
##
|
|
11
|
+
## Choose a Telegram workflow
|
|
20
12
|
|
|
21
|
-
|
|
13
|
+
Choose a workflow by the data freshness you need, where the result should go, and whether the command changes Telegram.
|
|
22
14
|
|
|
23
|
-
|
|
15
|
+
### Read current Telegram data
|
|
24
16
|
|
|
25
|
-
|
|
26
|
-
- Nonzero exit codes and structured error codes let agents detect and handle failures.
|
|
27
|
-
- `--account <name>` selects an explicit account without changing the current account.
|
|
28
|
-
- Local search and analysis commands let agents inspect synced messages without reconnecting to Telegram.
|
|
29
|
-
|
|
30
|
-
For example, an agent can search one account and parse the result as JSON:
|
|
31
|
-
|
|
32
|
-
```sh
|
|
33
|
-
tg search "release" --account work --json
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
### Agent skill
|
|
37
|
-
|
|
38
|
-
Install the [`using-telegram-cli`](https://skills.sh/will-17173/telegram-cli/using-telegram-cli) skill to teach a supported AI coding agent how to authenticate accounts, synchronize and query messages, automate structured output, and guard Telegram write operations:
|
|
39
|
-
|
|
40
|
-
```sh
|
|
41
|
-
npx skills add https://github.com/will-17173/telegram-cli \
|
|
42
|
-
--skill using-telegram-cli
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
Add `--global` to make the skill available across projects instead of installing it into the current project.
|
|
46
|
-
|
|
47
|
-
## Installation
|
|
48
|
-
|
|
49
|
-
Telegram CLI requires Node.js 22 or later.
|
|
50
|
-
|
|
51
|
-
Install the package globally from npm:
|
|
17
|
+
Use online commands when you need the latest server state. These commands do not add returned messages to SQLite.
|
|
52
18
|
|
|
53
19
|
```sh
|
|
54
|
-
|
|
20
|
+
tg inbox
|
|
21
|
+
tg read @team --since 2h
|
|
22
|
+
tg search-online "incident" --chat @team --json
|
|
55
23
|
```
|
|
56
24
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
Authenticate an account, check its status, and list its chats:
|
|
25
|
+
You can also inspect contacts, notification settings, folders, and group details without importing messages.
|
|
60
26
|
|
|
61
|
-
|
|
62
|
-
tg account add
|
|
63
|
-
tg status
|
|
64
|
-
tg chats
|
|
65
|
-
tg chats --group
|
|
66
|
-
tg chats --channel
|
|
67
|
-
tg chats --user
|
|
68
|
-
```
|
|
27
|
+
### Build a searchable local history
|
|
69
28
|
|
|
70
|
-
|
|
29
|
+
Sync one chat or many chats into the selected account’s SQLite database. Search and analyze the stored copy without reconnecting to Telegram.
|
|
71
30
|
|
|
72
31
|
```sh
|
|
73
|
-
tg sync
|
|
74
|
-
tg search "
|
|
32
|
+
tg sync @team
|
|
33
|
+
tg search "release" --chat @team
|
|
34
|
+
tg recent --chat @team --hours 24
|
|
75
35
|
```
|
|
76
36
|
|
|
77
|
-
|
|
37
|
+
Local commands can also filter, summarize, and export stored messages.
|
|
78
38
|
|
|
79
|
-
|
|
80
|
-
tg sync-all --max-chats 20 --delay 1
|
|
81
|
-
tg listen <chat-or-id> --auto-download
|
|
82
|
-
tg send <chat> "Hello from tg"
|
|
83
|
-
```
|
|
39
|
+
### Follow live messages and download files
|
|
84
40
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
`history`, `sync`, and `sync-all` fetch Telegram messages and store them in the local SQLite database. `read`, `search-online`, and `inbox` query Telegram directly without storing their results. `inbox` lists chats with unread messages without marking them as read.
|
|
41
|
+
The `listen` command streams new messages from one chat or many chats. It can download incoming attachments and run interactive reply or group actions.
|
|
88
42
|
|
|
89
43
|
```sh
|
|
90
|
-
tg
|
|
91
|
-
tg read @team --since 7d --until 2d
|
|
92
|
-
tg search-online release --chat @team --json
|
|
44
|
+
tg listen @team --auto-download
|
|
93
45
|
```
|
|
94
46
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
You can also inspect contacts, notification settings, folders, and group dialogs without changing remote state:
|
|
47
|
+
### Keep a Markdown archive
|
|
98
48
|
|
|
99
|
-
|
|
100
|
-
tg contact list
|
|
101
|
-
tg contact info +8613800000000
|
|
102
|
-
tg notification info @team
|
|
103
|
-
tg folder list
|
|
104
|
-
tg folder info 2
|
|
105
|
-
tg group list --admin
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
The following commands modify Telegram remotely:
|
|
49
|
+
The `archive` command writes incremental Markdown and optional media files. It tracks archive progress separately and does not populate SQLite.
|
|
109
50
|
|
|
110
51
|
```sh
|
|
111
|
-
tg
|
|
112
|
-
tg notification unmute @team
|
|
113
|
-
tg folder chat add Work @team
|
|
114
|
-
tg folder chat remove Work @team
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
Use `tg config write-access off` to block these mutations. Restore them with `tg config write-access on`.
|
|
118
|
-
|
|
119
|
-
Folder commands accept either a title or numeric folder ID. Folder titles are not necessarily unique. Run `tg folder list` first, then use the returned ID with `tg folder info`, `tg folder chat add`, or `tg folder chat remove`.
|
|
120
|
-
|
|
121
|
-
## Configuration
|
|
122
|
-
|
|
123
|
-
Personal Telegram application programming interface (API) credentials are optional. To use your own, create them at [my.telegram.org](https://my.telegram.org), then save them with:
|
|
124
|
-
|
|
125
|
-
```sh
|
|
126
|
-
tg config set --api-id <id> --api-hash <hash>
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
If both `TG_API_ID` and `TG_API_HASH` are unset and the saved configuration file is missing, the CLI uses built-in Telegram API credentials. When a Telegram client is created, it writes this warning to stderr once per process:
|
|
130
|
-
|
|
131
|
-
```text
|
|
132
|
-
warning: using default Telegram API credentials, which have stricter flood limits and may trigger FLOOD_WAIT during frequent or large requests. Run tg config set --api-id <id> --api-hash <hash> to configure your own.
|
|
52
|
+
tg archive @team --download-media
|
|
133
53
|
```
|
|
134
54
|
|
|
135
|
-
|
|
55
|
+
Later runs append new messages and retry referenced media that is still missing.
|
|
136
56
|
|
|
137
|
-
|
|
57
|
+
### Send messages and manage groups
|
|
138
58
|
|
|
139
|
-
|
|
59
|
+
Send text, files, or captioned media groups from the terminal. Inspect and manage group members, administrators, invites, forum topics, and messages.
|
|
140
60
|
|
|
141
61
|
```sh
|
|
142
|
-
tg
|
|
62
|
+
tg send @team "Release is ready" --file ./report.pdf
|
|
63
|
+
tg group members @team --type admins
|
|
64
|
+
tg group member mute @team @alice 2h --yes
|
|
143
65
|
```
|
|
144
66
|
|
|
145
|
-
|
|
67
|
+
Telegram CLI also manages contacts, notification settings, and chat folders. The write-access gate covers commands that change Telegram.
|
|
146
68
|
|
|
147
|
-
|
|
148
|
-
TG_PROXY=http://127.0.0.1:8080 tg status
|
|
149
|
-
```
|
|
69
|
+
### Automate across isolated accounts
|
|
150
70
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
To inspect the effective configuration in human-readable, JSON, or YAML format, run:
|
|
71
|
+
Each registered account has a separate session and SQLite database. Select an account for one command without changing the default.
|
|
154
72
|
|
|
155
73
|
```sh
|
|
156
|
-
tg
|
|
157
|
-
tg config list --json
|
|
158
|
-
tg config list --yaml
|
|
159
|
-
tg config list --show-secrets
|
|
74
|
+
tg stats --account work --json
|
|
160
75
|
```
|
|
161
76
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
Safe proxy endpoint details remain visible, but proxy usernames, passwords, and credential query parameters are always masked, even with `--show-secrets`.
|
|
77
|
+
Finite commands support JSON, YAML, and Markdown output. Failures return nonzero exit statuses and stable error codes.
|
|
165
78
|
|
|
166
|
-
|
|
79
|
+
## Install
|
|
167
80
|
|
|
168
|
-
|
|
81
|
+
Install Node.js 22 or later, then install Telegram CLI from npm:
|
|
169
82
|
|
|
170
83
|
```sh
|
|
171
|
-
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
## Send messages and attachments
|
|
175
|
-
|
|
176
|
-
`send` requires `<chat>`. Send text, one or more files, or files with a caption:
|
|
177
|
-
|
|
178
|
-
```sh
|
|
179
|
-
# Text only
|
|
180
|
-
tg send <chat> "Text only"
|
|
181
|
-
|
|
182
|
-
# Files only; repeat --file to preserve this order
|
|
183
|
-
tg send <chat> --file ./photo.jpg --file ./clip.mp4
|
|
184
|
-
|
|
185
|
-
# Caption and files
|
|
186
|
-
tg send <chat> "Group caption" --file ./photo.jpg --file ./clip.mp4
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
`--file` is repeatable. Multiple files are sent in the specified order as one Telegram media group. The message is optional only when at least one file is present. When files are present, the message becomes the group caption; the CLI does not send it as a separate text message.
|
|
190
|
-
|
|
191
|
-
Telegram determines which file combinations and group sizes it accepts. If Telegram rejects the requested combination or limit, the command returns an error and does not silently split the files into separate messages or groups.
|
|
192
|
-
|
|
193
|
-
## Archive chats as Markdown
|
|
194
|
-
|
|
195
|
-
`archive` requires an explicit scope. Pass one or more chat IDs or usernames, or use `--all`, but don't combine them.
|
|
196
|
-
|
|
197
|
-
The command uses the current account unless you pass `--account <name>`. It writes to that account's `archive` directory by default. Use `--output <path>` to select another directory.
|
|
198
|
-
|
|
199
|
-
```sh
|
|
200
|
-
# Initial archive with attachments: the preceding seven days
|
|
201
|
-
tg archive @team --download-media
|
|
202
|
-
|
|
203
|
-
# Custom range (relative durations or ISO timestamps with zones)
|
|
204
|
-
tg archive @team --since 30d --until 2026-07-13T00:00:00Z
|
|
205
|
-
|
|
206
|
-
# Full available history for every chat, including attachments
|
|
207
|
-
tg archive --all --full --download-media
|
|
84
|
+
npm install -g @will-17173/telegram-cli
|
|
208
85
|
```
|
|
209
86
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
Later runs append new messages to the existing archive. Use `--rebuild` to replace each selected Markdown file. Without a new range, rebuilding reuses the archive's initial range.
|
|
213
|
-
|
|
214
|
-
Use `--download-media` to store attachments in the archive's `media/` directory. Incremental runs retry referenced media that is still missing.
|
|
215
|
-
|
|
216
|
-
Chat or attachment failures produce `archive_partial_failure`, preserve successful chat results, and exit with status 1. Use `--json` or `--yaml` in automation and inspect `completed`, `failed`, and `warnings`.
|
|
87
|
+
## Get started
|
|
217
88
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
## Multiple accounts
|
|
221
|
-
|
|
222
|
-
Each Telegram account has its own persisted authentication session and local message database. Add and authenticate an account interactively with:
|
|
89
|
+
Authenticate one account, list its chats, sync one chat, and search the local copy:
|
|
223
90
|
|
|
224
91
|
```sh
|
|
225
92
|
tg account add
|
|
93
|
+
tg status
|
|
94
|
+
tg chats
|
|
95
|
+
tg sync @team
|
|
96
|
+
tg search "release" --chat @team
|
|
226
97
|
```
|
|
227
98
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
```sh
|
|
231
|
-
# List registered accounts
|
|
232
|
-
tg account list
|
|
233
|
-
|
|
234
|
-
# Show the current account
|
|
235
|
-
tg account current
|
|
236
|
-
|
|
237
|
-
# Choose the default account from an interactive list
|
|
238
|
-
tg account switch
|
|
239
|
-
|
|
240
|
-
# Set the default account by name
|
|
241
|
-
tg account switch <name>
|
|
242
|
-
|
|
243
|
-
# Remove an account and its local session/data
|
|
244
|
-
tg account remove <name> --force
|
|
245
|
-
```
|
|
246
|
-
|
|
247
|
-
Log out explicitly to end the remote session without deleting the account, its settings, or locally stored messages. The `--yes` option confirms logout without a prompt.
|
|
248
|
-
|
|
249
|
-
Logging in again requires an interactive terminal (TTY) and creates or replaces the local Telegram session. Scripts and non-interactive agents receive an `interaction_required` error.
|
|
250
|
-
|
|
251
|
-
```sh
|
|
252
|
-
tg account logout work --yes
|
|
253
|
-
tg account login work
|
|
254
|
-
```
|
|
255
|
-
|
|
256
|
-
In an interactive terminal, `tg account switch` lists registered accounts, marks the current one, and accepts its number. Pass `<name>` when scripting or using `--json`, `--yaml`, or non-interactive input.
|
|
257
|
-
|
|
258
|
-
Commands use the current account by default. Commands that support `--account` can target another registered account for one invocation without changing the current account:
|
|
259
|
-
|
|
260
|
-
```sh
|
|
261
|
-
tg chats --account <name>
|
|
262
|
-
tg sync-all --account <name>
|
|
263
|
-
tg search "keyword" --account <name>
|
|
264
|
-
```
|
|
265
|
-
|
|
266
|
-
Account names are shown by `tg account list`; they are normally derived from the Telegram username. Sessions and message databases remain isolated under each account's directory inside `DATA_DIR`.
|
|
267
|
-
|
|
268
|
-
Telegram API credentials apply to every registered account. You don't need to configure separate API credentials when adding another account.
|
|
269
|
-
|
|
270
|
-
## Group management
|
|
271
|
-
|
|
272
|
-
The `group` command supports read-only inspection and management of members, administrators, chat settings, invite links, forum topics, and messages. Use each command group's help to see its actions:
|
|
273
|
-
|
|
274
|
-
```sh
|
|
275
|
-
# Group details
|
|
276
|
-
tg group info <chat> --account alice --json
|
|
277
|
-
|
|
278
|
-
# Member list: type, name/username query, and bounded result count
|
|
279
|
-
tg group members <chat> --type admins --query alice --limit 50 --yaml
|
|
280
|
-
|
|
281
|
-
# One member's role, administrator rights, and restrictions
|
|
282
|
-
tg group member <chat> <user>
|
|
283
|
-
|
|
284
|
-
# Administrator audit log; --user and --type can be repeated
|
|
285
|
-
tg group audit <chat> --query invite --user <user> --type member_invited --type invite_changed --limit 100 --account alice --json
|
|
286
|
-
|
|
287
|
-
# Management examples (the chat argument comes before action arguments)
|
|
288
|
-
tg group member ban @team @alice --yes
|
|
289
|
-
tg group admin transfer-owner @team @newowner --yes
|
|
290
|
-
tg group chat slowmode @team 30s
|
|
291
|
-
tg group topic --help
|
|
292
|
-
```
|
|
293
|
-
|
|
294
|
-
After confirmation, ownership transfer securely prompts for the Telegram two-factor authentication (2FA) password. The password is never a CLI argument, stdin input, or environment automation source. The secure prompt accepts it only from an interactive terminal, not piped input. Don't automate this prompt.
|
|
295
|
-
|
|
296
|
-
`group members` accepts exactly these seven `--type` filters: `recent`, `all`, `admins`, `banned`, `restricted`, `bots`, and `contacts`. It defaults to `recent` and 100 results; `--limit` accepts 1 through 200. Telegram can return fewer members than its reported total, so a page is not guaranteed to enumerate the whole group.
|
|
297
|
-
|
|
298
|
-
`group audit` requires group administrator rights. Its `--limit` range is 1 through 500, with a default of 100 events. Its repeatable `--user` filter selects action authors. The repeatable `--type` filter accepts these event groups:
|
|
299
|
-
|
|
300
|
-
- **Chat**: `info_changed`, `settings_changed`
|
|
301
|
-
- **Members**: `member_joined`, `member_left`, `member_invited`, `member_banned`, `member_unbanned`, `member_restricted`, `member_unrestricted`
|
|
302
|
-
- **Administrators**: `admin_promoted`, `admin_demoted`
|
|
303
|
-
- **Messages**: `message_deleted`, `message_edited`, `message_pinned`
|
|
304
|
-
- **Invites and topics**: `invite_changed`, `topic_changed`
|
|
305
|
-
- **Other**: `other`
|
|
306
|
-
|
|
307
|
-
Inspection and management actions use human-readable output by default; actions that expose `--json` or `--yaml` provide structured success or error output. Failures set a nonzero exit status. They use the current account unless `--account <name>` selects another registered account for that invocation.
|
|
308
|
-
|
|
309
|
-
Management actions are grouped under `member`, `admin`, `chat`, `invite`, `topic`, and `message`. Member targets must be explicit `@username` values or numeric Telegram user IDs. Durations accept `s`, `m`, `h`, and `d` suffixes, or `off` where disabling is supported. For example, `tg group member mute @team @alice 2h --yes` temporarily mutes a member, while `tg group chat slowmode @team off` disables slow mode.
|
|
310
|
-
|
|
311
|
-
Potentially destructive CLI actions refuse to connect to Telegram unless `--yes` is present. Permanently deleting a chat additionally requires `--confirm-title` with the exact current title. Interactive listen mode presents these confirmations in an Ink modal. Management requires the relevant administrator permission, and some actions require a supergroup, forum, or creator role.
|
|
312
|
-
|
|
313
|
-
Use `tg group member info <chat> <user>` as the canonical member-details route. The legacy `tg group member <chat> <user>` form remains available, but a chat name matching a reserved member action such as `ban`, `mute`, or `info` is ambiguous and requires the canonical route.
|
|
314
|
-
|
|
315
|
-
## Slash commands while listening
|
|
316
|
-
|
|
317
|
-
Interactive `tg listen` presents every supported slash command in one menu. This includes `/reply` and the complete group-management catalog; group commands use the same management grammar without repeating the selected chat:
|
|
318
|
-
|
|
319
|
-
```text
|
|
320
|
-
/reply <message-id> <content>
|
|
321
|
-
/member mute @alice 2h
|
|
322
|
-
```
|
|
323
|
-
|
|
324
|
-
Typing `/` opens the unified command menu, with reply first. Matching ranks exact paths, prefixes, then ordered fuzzy matches, so `/rep` and `/rpy` find `/reply`, while `/ban` finds `/member ban`. Use **Up** and **Down** to move through matches. **Tab** completes the selected command. **Enter** completes an incomplete selection or runs a complete command. **Esc** closes the menu, result, or confirmation.
|
|
325
|
-
|
|
326
|
-
Group-command availability and permission checks are unchanged: unavailable actions remain disabled, risky actions open a confirmation modal, and chat deletion also asks for the exact title. When listening to more than one chat, set an unambiguous outgoing target with `--send-to <chat>` before using group commands, for example `tg listen @team @ops --send-to @team`.
|
|
327
|
-
|
|
328
|
-
## Online and local commands
|
|
329
|
-
|
|
330
|
-
Online commands connect to Telegram and require a valid session:
|
|
331
|
-
|
|
332
|
-
- `read`, `search-online`, and `inbox` return results without storing them locally.
|
|
333
|
-
- `history`, `sync`, `sync-all`, and `refresh` persist fetched messages in SQLite.
|
|
334
|
-
- `contact`, `notification`, `folder`, `info`, and `group` inspect or manage Telegram data.
|
|
335
|
-
- `archive` reads Telegram history and writes Markdown files locally.
|
|
336
|
-
- `send`, `edit`, and `delete` modify Telegram messages.
|
|
337
|
-
- `listen` keeps a connection open for incoming messages and interactive actions.
|
|
99
|
+
Replace `@team` with a chat name, username, or numeric identifier (ID). Run `tg --help` or a command such as `tg sync --help` to inspect available options.
|
|
338
100
|
|
|
339
|
-
|
|
101
|
+
## Know where data goes
|
|
340
102
|
|
|
341
|
-
|
|
103
|
+
Check a command’s execution scope before you run it:
|
|
342
104
|
|
|
343
|
-
|
|
105
|
+
| Scope | Commands | Effect |
|
|
106
|
+
| --- | --- | --- |
|
|
107
|
+
| Online read | `inbox`, `read`, `search-online` | Queries Telegram without storing returned messages. |
|
|
108
|
+
| Local persistence | `history`, `sync`, `sync-all`, `refresh` | Stores fetched messages in the selected account’s SQLite database. |
|
|
109
|
+
| Local read | `search`, `recent`, `stats`, `export` | Reads local SQLite data without connecting to Telegram. |
|
|
110
|
+
| File archive | `archive` | Reads Telegram and writes Markdown or media files without writing to SQLite. |
|
|
111
|
+
| Remote write | `send`, `edit`, `delete`, notification, folder, and group actions | Changes Telegram messages or settings. |
|
|
344
112
|
|
|
345
|
-
|
|
113
|
+
Each account has a separate session and SQLite database. Add `--account work` to select an account for one command without changing the default.
|
|
346
114
|
|
|
347
|
-
|
|
348
|
-
tg recent --chat <chat> --sender <sender> --hours 6 --limit 100
|
|
349
|
-
```
|
|
350
|
-
|
|
351
|
-
Human-readable output groups each Telegram media group into one row and summarizes its attachments. The `ID` column lists every source message ID in that row. Replies include the original message's time, sender, ID, and text when the target exists locally in the same chat. Otherwise, the output identifies the missing local message ID.
|
|
352
|
-
|
|
353
|
-
JSON and YAML output keep the stored-message structure for scripts. `recent` reads local SQLite data and does not connect to Telegram.
|
|
354
|
-
|
|
355
|
-
## Command reference
|
|
115
|
+
## Protect remote data
|
|
356
116
|
|
|
357
|
-
|
|
117
|
+
Disable remote writes before read-only workflows or automation:
|
|
358
118
|
|
|
359
119
|
```sh
|
|
360
|
-
tg
|
|
120
|
+
tg config write-access off
|
|
121
|
+
tg config write-access status
|
|
361
122
|
```
|
|
362
123
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
| Command | Purpose |
|
|
366
|
-
| --- | --- |
|
|
367
|
-
| `tg account add` | Authenticate and register another Telegram account. |
|
|
368
|
-
| `tg account list` | List registered accounts and show which one is current. |
|
|
369
|
-
| `tg account current` | Show the current account. |
|
|
370
|
-
| `tg account switch [name]` | Select the default account interactively or set it by name. |
|
|
371
|
-
| `tg account remove <name> --force` | Remove an account and its local session/data. |
|
|
372
|
-
| `tg account logout <name> --yes` / `tg account login <name>` | Confirm logout non-interactively, or reauthenticate interactively into a new local session; local messages are retained. |
|
|
373
|
-
| `tg status` | Check whether the Telegram account is authenticated. |
|
|
374
|
-
| `tg whoami` | Show basic authenticated account information. |
|
|
375
|
-
| `tg config set --api-id <id> --api-hash <hash>` | Save Telegram API credentials for persistent use. |
|
|
376
|
-
| `tg config set --proxy <url>` | Save an optional proxy for account login and Telegram-backed commands. |
|
|
377
|
-
| `tg config list [--show-secrets]` | Show effective configuration values and sources. Proxy credentials remain masked. |
|
|
378
|
-
| `tg config write-access [status\|on\|off]` | Inspect or gate remote Telegram mutations. |
|
|
379
|
-
| `tg chats [--group\|--channel\|--user]` | List available chats, optionally filtered by type (`--group` includes supergroups). |
|
|
380
|
-
| `tg inbox` | List unread dialogs online without marking messages read. |
|
|
381
|
-
| `tg read <chat> [--since <time>] [--until <time>]` | Read recent Telegram messages without persisting them locally. |
|
|
382
|
-
| `tg search-online <query> [--chat <chat>]` | Search Telegram globally or within one chat without persisting results. |
|
|
383
|
-
| `tg contact list` / `tg contact info <user_or_phone>` | List contacts or resolve one by ID, username, or phone. |
|
|
384
|
-
| `tg dialog inbox` / `tg dialog read <chat>` | Use the dialog-family routes for `inbox` and `read`. |
|
|
385
|
-
| `tg dialog search <query>` / `tg dialog groups` | Search online messages or list group dialogs through the dialog family. |
|
|
386
|
-
| `tg notification info <chat>` | Show notification settings for a chat. |
|
|
387
|
-
| `tg notification mute <chat> [duration]` | Mute notifications temporarily or indefinitely. |
|
|
388
|
-
| `tg notification unmute <chat>` | Restore notifications for a chat. |
|
|
389
|
-
| `tg folder list` / `tg folder info <folder>` | List folders or inspect one folder. |
|
|
390
|
-
| `tg folder chat add <folder> <chat>` | Add an explicit chat to a folder. |
|
|
391
|
-
| `tg folder chat remove <folder> <chat>` | Remove an explicit chat from a folder. |
|
|
392
|
-
| `tg history <chat> -n <limit>` | Fetch and store full chat history (default up to 1000 messages). |
|
|
393
|
-
| `tg sync <chat>` | Incrementally sync new messages for one chat. |
|
|
394
|
-
| `tg sync-all` | Sync messages from all chats, using local last-message IDs for incremental updates. |
|
|
395
|
-
| `tg refresh` | Alias-like command for bulk sync with same runtime options as `sync-all`. |
|
|
396
|
-
| `tg listen [chat ...]` | Stream incoming messages from selected chats or all chats. |
|
|
397
|
-
| `tg listen --no-media` | Hide attachment summary lines while listening. |
|
|
398
|
-
| `tg listen <chat-or-id> --auto-download` | Automatically download incoming attachments while listening. |
|
|
399
|
-
| `tg search "keyword" --chat <chat>` | Search messages already stored locally. |
|
|
400
|
-
| `tg recent`, `tg today`, `tg stats`, `tg top`, `tg timeline` | Explore local message data. |
|
|
401
|
-
| `tg filter <keywords>` | Filter local messages by keyword with optional chat/hour filters. |
|
|
402
|
-
| `tg export <chat>` | Export local messages from a chat. |
|
|
403
|
-
| `tg archive <chat ...>` / `tg archive --all` | Archive selected or all chats as incremental Markdown files. |
|
|
404
|
-
| `tg send <chat> [message] [--file <path> ...]` | Send text, files, or a captioned media group. |
|
|
405
|
-
| `tg edit <chat> <msgId> <text>` | Edit a message. |
|
|
406
|
-
| `tg delete <chat> <msgIds...>` | Delete one or more messages. |
|
|
407
|
-
| `tg purge <chat> --yes` | Remove a chat's locally stored messages. |
|
|
408
|
-
| `tg info <chat>` | Show metadata for a Telegram chat. |
|
|
409
|
-
| `tg group info <chat>` | Show read-only group or supergroup details. |
|
|
410
|
-
| `tg group list [--admin]` | List group, supergroup, and channel dialogs; `--admin` keeps only chats you administer or own. |
|
|
411
|
-
| `tg group members <chat> [--type <type>] [--query <text>] [--limit <count>]` | List and filter members (default `recent`, limit 100; maximum 200). |
|
|
412
|
-
| `tg group member <chat> <user>` | Show one member's role, rights, and restrictions. |
|
|
413
|
-
| `tg group audit <chat> [--query <text>] [--user <user>] [--type <type>] [--limit <count>]` | Query the administrator audit log (default 100; maximum 500). |
|
|
414
|
-
| `tg group member/admin/chat/invite/topic/message --help` | Discover group management actions by family. |
|
|
415
|
-
|
|
416
|
-
All sync-like commands write to local SQLite storage. The `sync-all` and `refresh` commands process multiple chats based on locally stored message IDs.
|
|
417
|
-
|
|
418
|
-
Finite commands support explicit `--json`, `--yaml`, and `--markdown` output. Without an explicit format, non-interactive output remains YAML. Interactive terminals use rich human-readable output.
|
|
419
|
-
|
|
420
|
-
Successful finite output is written to stdout. JSON/YAML structured failures are written to stdout in the requested format. Output-format conflicts also use stdout and a stable YAML envelope. Human-readable and Markdown failures are written to stderr. Every failure sets a nonzero exit status.
|
|
421
|
-
|
|
422
|
-
The `listen` command is an unbounded stream, so these finite-output rules don't apply to it.
|
|
423
|
-
|
|
424
|
-
Common options:
|
|
425
|
-
|
|
426
|
-
| Option | Purpose |
|
|
427
|
-
| --- | --- |
|
|
428
|
-
| `--account <name>` | Use a registered account without changing the current account. |
|
|
429
|
-
| `--json` / `--yaml` / `--markdown` | Select JSON, YAML, or Markdown output for a finite command. |
|
|
430
|
-
| `-v`, `--verbose` | Enable debug logging. |
|
|
431
|
-
| `-V`, `--version` | Print the installed version. |
|
|
432
|
-
|
|
433
|
-
Use `tg <command> --help` to inspect command-specific options. For example, `listen` supports reconnection and plain-text modes, while `search` supports sender, time, regular-expression, and result-limit filters.
|
|
434
|
-
|
|
435
|
-
### Error codes
|
|
436
|
-
|
|
437
|
-
Structured output exposes stable top-level command errors under `error.code`, with operation-specific details where available:
|
|
438
|
-
|
|
439
|
-
- **Accounts:** `account_logged_out`, `account_identity_mismatch`, `interaction_required`
|
|
440
|
-
- **Contacts:** `contact_not_found`
|
|
441
|
-
- **Notifications and folders:** `invalid_notification_duration`, `folder_not_found`, `ambiguous_folder`, `folder_operation_unsupported`
|
|
442
|
-
- **Group ownership:** `password_required`, `password_invalid`, `password_too_fresh`, `session_too_fresh`
|
|
443
|
-
- **Archive:** `archive_account_mismatch`, `archive_failed`, `archive_partial_failure`. When an attachment fails but the archive retains partial results, the top-level code is `archive_partial_failure`, the command exits nonzero, and each media warning uses `archive_media_failed` under `error.details.warnings[].code`.
|
|
444
|
-
- **Write safety and rate limits:** `write_access_disabled`, `flood_wait`
|
|
445
|
-
|
|
446
|
-
### Remote write safety
|
|
447
|
-
|
|
448
|
-
Run `tg config write-access status` to inspect the current setting. Use `tg config write-access off` to block remote mutations made by send, edit, delete, notification, folder, and group commands. Local database operations, configuration changes, and Telegram reads remain available.
|
|
449
|
-
|
|
450
|
-
Run `tg config write-access on` to restore remote mutations after testing or maintenance.
|
|
451
|
-
|
|
452
|
-
### Sync and listen behavior
|
|
453
|
-
|
|
454
|
-
These rules describe how synchronization, listening, replies, and downloads affect local data and terminal output.
|
|
455
|
-
|
|
456
|
-
- `sync-all` and `refresh` are batch operations for local persistence; they are not read-only.
|
|
457
|
-
- `listen` prints a concise separator for each incoming message and can optionally suppress attachment summaries.
|
|
458
|
-
- Telegram media groups appear as one incoming message with a combined attachment summary.
|
|
459
|
-
- Reply output includes the original message's local context when available, or identifies the missing message ID.
|
|
460
|
-
- In interactive `listen`, reply with `/reply <message-id> <content>`. Add attachments with repeatable `--file <path>` options; quote paths that contain spaces.
|
|
461
|
-
- Contact cards show the available name and phone number in attachment summaries. They aren't downloadable attachments and are hidden by `--no-media`.
|
|
462
|
-
- `listen --auto-download` works in both interactive and plain-text modes, saves attachments to `~/Downloads/telegram-cli`, and runs at most three downloads concurrently.
|
|
463
|
-
- Downloads keep Telegram-provided filenames. Unnamed downloads use a MIME-derived extension, then the media-kind extension, then `.bin`.
|
|
464
|
-
- Download failures are reported without stopping the listener. `--no-media` hides attachment summaries only; downloads still run when it is combined with `--auto-download`.
|
|
465
|
-
|
|
466
|
-
## Troubleshooting
|
|
467
|
-
|
|
468
|
-
Use these steps to resolve common account, session, and API credential errors.
|
|
469
|
-
|
|
470
|
-
### No active account
|
|
471
|
-
|
|
472
|
-
If a command reports `account_required`, add an account or select an existing one:
|
|
124
|
+
Run `tg config write-access on` when you intend to modify Telegram again. Enabling the gate does not authorize a specific write.
|
|
473
125
|
|
|
474
|
-
|
|
475
|
-
tg account add
|
|
476
|
-
tg account switch <name>
|
|
477
|
-
```
|
|
126
|
+
Keep Telegram application programming interface (API) credentials, proxy credentials, session files, SQLite databases, exports, and archives private.
|
|
478
127
|
|
|
479
|
-
|
|
128
|
+
## Use with coding agents
|
|
480
129
|
|
|
481
|
-
|
|
130
|
+
Use JSON or YAML when a script or coding agent needs structured output:
|
|
482
131
|
|
|
483
132
|
```sh
|
|
484
|
-
tg account
|
|
485
|
-
tg account add
|
|
133
|
+
tg search "release" --account work --json
|
|
486
134
|
```
|
|
487
135
|
|
|
488
|
-
|
|
136
|
+
Failures return a nonzero exit status and a stable error code. The explicit `--account` option keeps automation on the intended account.
|
|
489
137
|
|
|
490
|
-
|
|
138
|
+
Install the [`using-telegram-cli` agent skill](https://skills.sh/will-17173/telegram-cli/using-telegram-cli) in a supported coding agent:
|
|
491
139
|
|
|
492
140
|
```sh
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
Set both `TG_API_ID` and `TG_API_HASH` when using environment variables. Setting only one causes a configuration error.
|
|
497
|
-
|
|
498
|
-
## Local data and privacy
|
|
499
|
-
|
|
500
|
-
Persisted configuration, authentication sessions, and synced messages remain on your machine unless you copy or export them. The relevant files under `DATA_DIR` are:
|
|
501
|
-
|
|
502
|
-
```text
|
|
503
|
-
config.json
|
|
504
|
-
accounts.json
|
|
505
|
-
accounts/<name>/session
|
|
506
|
-
accounts/<name>/messages.db
|
|
141
|
+
npx skills add https://github.com/will-17173/telegram-cli \
|
|
142
|
+
--skill using-telegram-cli
|
|
507
143
|
```
|
|
508
144
|
|
|
509
|
-
|
|
145
|
+
The skill covers authentication, synchronization, queries, and write safety.
|
|
510
146
|
|
|
511
|
-
##
|
|
147
|
+
## Develop
|
|
512
148
|
|
|
513
|
-
|
|
149
|
+
Use pnpm with Node.js 22 or later:
|
|
514
150
|
|
|
515
151
|
```sh
|
|
516
152
|
pnpm install
|
|
517
153
|
pnpm dev --help
|
|
518
154
|
pnpm test
|
|
519
155
|
pnpm typecheck
|
|
156
|
+
pnpm build
|
|
520
157
|
```
|
|
521
158
|
|
|
522
|
-
During development, expose the current checkout as a global `tg` command that runs the TypeScript source directly. From the project root:
|
|
523
|
-
|
|
524
|
-
```sh
|
|
525
|
-
mkdir -p ~/.local/bin
|
|
526
|
-
cat > ~/.local/bin/tg <<EOF
|
|
527
|
-
#!/bin/sh
|
|
528
|
-
exec "$(pwd)/node_modules/.bin/tsx" "$(pwd)/src/dev.ts" "\$@"
|
|
529
|
-
EOF
|
|
530
|
-
chmod +x ~/.local/bin/tg
|
|
531
|
-
rehash
|
|
532
|
-
```
|
|
533
|
-
|
|
534
|
-
Make sure `~/.local/bin` is in `PATH`. Subsequent `tg` invocations load the latest source changes.
|
|
535
|
-
|
|
536
|
-
For local source development, create a `.env` file in the project root:
|
|
537
|
-
|
|
538
|
-
```dotenv
|
|
539
|
-
TG_API_ID=your_telegram_api_id
|
|
540
|
-
TG_API_HASH=your_telegram_api_hash
|
|
541
|
-
```
|
|
542
|
-
|
|
543
|
-
`pnpm dev` loads this file only for local source development. An installed `tg` does not automatically load `.env`; use `tg config set --api-id <id> --api-hash <hash>` for persistent production configuration.
|
|
544
|
-
|
|
545
159
|
## License
|
|
546
160
|
|
|
547
|
-
Licensed under [GPL-3.0](LICENSE).
|
|
161
|
+
Licensed under [GPL-3.0-only](LICENSE).
|