@will-17173/telegram-cli 0.3.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 -335
- package/README.zh-CN.md +72 -333
- package/dist/account/account-authenticator.js +95 -0
- package/dist/account/account-authenticator.js.map +1 -0
- package/dist/account/account-context.js +7 -0
- package/dist/account/account-context.js.map +1 -1
- package/dist/account/account-name.js +17 -0
- package/dist/account/account-name.js.map +1 -0
- package/dist/account/account-presets.js +20 -3
- package/dist/account/account-presets.js.map +1 -1
- package/dist/account/account-store.js +277 -37
- package/dist/account/account-store.js.map +1 -1
- package/dist/cli/app.js +12 -1
- package/dist/cli/app.js.map +1 -1
- package/dist/cli/output.js +21 -6
- package/dist/cli/output.js.map +1 -1
- package/dist/cli/secure-input.js +408 -0
- package/dist/cli/secure-input.js.map +1 -0
- package/dist/commands/account-options.js +37 -7
- package/dist/commands/account-options.js.map +1 -1
- package/dist/commands/account.js +144 -62
- package/dist/commands/account.js.map +1 -1
- package/dist/commands/archive.js +151 -0
- package/dist/commands/archive.js.map +1 -0
- package/dist/commands/config.js +119 -12
- package/dist/commands/config.js.map +1 -1
- package/dist/commands/contact.js +58 -0
- package/dist/commands/contact.js.map +1 -0
- package/dist/commands/data.js +14 -7
- package/dist/commands/data.js.map +1 -1
- package/dist/commands/dialog.js +156 -0
- package/dist/commands/dialog.js.map +1 -0
- package/dist/commands/folder.js +113 -0
- package/dist/commands/folder.js.map +1 -0
- package/dist/commands/group-write.js +45 -5
- package/dist/commands/group-write.js.map +1 -1
- package/dist/commands/group.js +23 -1
- package/dist/commands/group.js.map +1 -1
- package/dist/commands/notification.js +76 -0
- package/dist/commands/notification.js.map +1 -0
- package/dist/commands/query.js +22 -15
- package/dist/commands/query.js.map +1 -1
- package/dist/commands/telegram-runner.js +40 -18
- package/dist/commands/telegram-runner.js.map +1 -1
- package/dist/commands/telegram.js +82 -38
- package/dist/commands/telegram.js.map +1 -1
- package/dist/commands/time-range.js +39 -0
- package/dist/commands/time-range.js.map +1 -0
- package/dist/commands/types.js +3 -2
- package/dist/commands/types.js.map +1 -1
- package/dist/config/credential-store.js +24 -4
- package/dist/config/credential-store.js.map +1 -1
- package/dist/config/env.js +4 -1
- package/dist/config/env.js.map +1 -1
- package/dist/group-commands/catalog.js +10 -0
- package/dist/group-commands/catalog.js.map +1 -1
- package/dist/group-commands/executor.js +13 -4
- package/dist/group-commands/executor.js.map +1 -1
- package/dist/presenters/group.js +16 -0
- package/dist/presenters/group.js.map +1 -1
- package/dist/presenters/human.js +113 -0
- package/dist/presenters/human.js.map +1 -1
- package/dist/presenters/ink/group-command-result.js +2 -0
- package/dist/presenters/ink/group-command-result.js.map +1 -1
- package/dist/presenters/ink/listen-scroll.js +4 -3
- package/dist/presenters/ink/listen-scroll.js.map +1 -1
- package/dist/presenters/ink/listen.js +245 -57
- package/dist/presenters/ink/listen.js.map +1 -1
- package/dist/presenters/ink/mouse-scroll.js +12 -0
- package/dist/presenters/ink/mouse-scroll.js.map +1 -1
- package/dist/presenters/ink/secure-input.js +68 -0
- package/dist/presenters/ink/secure-input.js.map +1 -0
- package/dist/presenters/ink/use-group-command.js +78 -17
- package/dist/presenters/ink/use-group-command.js.map +1 -1
- package/dist/presenters/markdown.js +54 -0
- package/dist/presenters/markdown.js.map +1 -0
- package/dist/presenters/structured.js +8 -3
- package/dist/presenters/structured.js.map +1 -1
- package/dist/services/account-session-service.js +241 -0
- package/dist/services/account-session-service.js.map +1 -0
- package/dist/services/archive-layout.js +61 -0
- package/dist/services/archive-layout.js.map +1 -0
- package/dist/services/archive-manifest.js +187 -0
- package/dist/services/archive-manifest.js.map +1 -0
- package/dist/services/archive-markdown.js +383 -0
- package/dist/services/archive-markdown.js.map +1 -0
- package/dist/services/archive-service.js +718 -0
- package/dist/services/archive-service.js.map +1 -0
- package/dist/services/archive-types.js +2 -0
- package/dist/services/archive-types.js.map +1 -0
- package/dist/services/attachment-download.js +7 -2
- package/dist/services/attachment-download.js.map +1 -1
- package/dist/services/auto-download-coordinator.js +2 -4
- package/dist/services/auto-download-coordinator.js.map +1 -1
- package/dist/services/contact-service.js +78 -0
- package/dist/services/contact-service.js.map +1 -0
- package/dist/services/dialog-service.js +140 -0
- package/dist/services/dialog-service.js.map +1 -0
- package/dist/services/folder-service.js +200 -0
- package/dist/services/folder-service.js.map +1 -0
- package/dist/services/group-write-service.js +78 -18
- package/dist/services/group-write-service.js.map +1 -1
- package/dist/services/message-service.js +17 -1
- package/dist/services/message-service.js.map +1 -1
- package/dist/services/notification-service.js +142 -0
- package/dist/services/notification-service.js.map +1 -0
- package/dist/services/write-access-policy.js +19 -0
- package/dist/services/write-access-policy.js.map +1 -0
- package/dist/telegram/archive-types.js +2 -0
- package/dist/telegram/archive-types.js.map +1 -0
- package/dist/telegram/client-factory.js +51 -11
- package/dist/telegram/client-factory.js.map +1 -1
- package/dist/telegram/contact-types.js +10 -0
- package/dist/telegram/contact-types.js.map +1 -0
- package/dist/telegram/dialog-types.js +2 -0
- package/dist/telegram/dialog-types.js.map +1 -0
- package/dist/telegram/errors.js +14 -0
- package/dist/telegram/errors.js.map +1 -0
- package/dist/telegram/fake-group-management.js +5 -0
- package/dist/telegram/fake-group-management.js.map +1 -1
- package/dist/telegram/folder-types.js +13 -0
- package/dist/telegram/folder-types.js.map +1 -0
- package/dist/telegram/group-write-types.js +28 -1
- package/dist/telegram/group-write-types.js.map +1 -1
- package/dist/telegram/mtcute-archive.js +190 -0
- package/dist/telegram/mtcute-archive.js.map +1 -0
- package/dist/telegram/mtcute-client.js +72 -11
- package/dist/telegram/mtcute-client.js.map +1 -1
- package/dist/telegram/mtcute-contacts.js +90 -0
- package/dist/telegram/mtcute-contacts.js.map +1 -0
- package/dist/telegram/mtcute-dialogs.js +186 -0
- package/dist/telegram/mtcute-dialogs.js.map +1 -0
- package/dist/telegram/mtcute-folders.js +318 -0
- package/dist/telegram/mtcute-folders.js.map +1 -0
- package/dist/telegram/mtcute-group-members.js +43 -3
- package/dist/telegram/mtcute-group-members.js.map +1 -1
- package/dist/telegram/mtcute-message-normalizer.js +63 -0
- package/dist/telegram/mtcute-message-normalizer.js.map +1 -0
- package/dist/telegram/mtcute-notifications.js +101 -0
- package/dist/telegram/mtcute-notifications.js.map +1 -0
- package/dist/telegram/notification-types.js +11 -0
- package/dist/telegram/notification-types.js.map +1 -0
- package/dist/telegram/types.js +6 -1
- package/dist/telegram/types.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,423 +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
|
-
- Manage multiple Telegram accounts with isolated sessions, message databases, and interactive account switching.
|
|
11
|
-
- Fetch chat history into a local SQLite database for fast, offline search.
|
|
12
|
-
- Sync one chat incrementally or sync many chats with a single command.
|
|
13
|
-
- Listen for new messages in real time, with optional attachment summaries.
|
|
14
|
-
- Download attachments from channels that restrict content saving.
|
|
15
|
-
- Search, filter, summarize, and export locally stored messages, with reply context and media-group summaries in recent results.
|
|
16
|
-
- Send, edit, and delete messages from the command line.
|
|
17
|
-
- Inspect and manage groups, members, administrators, invites, forum topics, and messages.
|
|
18
|
-
- Use human-readable output or structured JSON/YAML where supported.
|
|
9
|
+
Read the [complete Telegram CLI documentation](https://will-17173.github.io/telegram-cli/docs/) for installation, workflows, every command, automation, safety, and troubleshooting.
|
|
19
10
|
|
|
20
|
-
##
|
|
11
|
+
## Choose a Telegram workflow
|
|
21
12
|
|
|
22
|
-
|
|
13
|
+
Choose a workflow by the data freshness you need, where the result should go, and whether the command changes Telegram.
|
|
23
14
|
|
|
24
|
-
|
|
15
|
+
### Read current Telegram data
|
|
25
16
|
|
|
26
|
-
|
|
27
|
-
- Nonzero exit codes and structured error codes let agents detect and handle failures.
|
|
28
|
-
- `--account <name>` selects an explicit account without changing the current account.
|
|
29
|
-
- Local search and analysis commands let agents inspect synced messages without reconnecting to Telegram.
|
|
30
|
-
|
|
31
|
-
For example, an agent can search one account and parse the result as JSON:
|
|
17
|
+
Use online commands when you need the latest server state. These commands do not add returned messages to SQLite.
|
|
32
18
|
|
|
33
19
|
```sh
|
|
34
|
-
tg
|
|
20
|
+
tg inbox
|
|
21
|
+
tg read @team --since 2h
|
|
22
|
+
tg search-online "incident" --chat @team --json
|
|
35
23
|
```
|
|
36
24
|
|
|
37
|
-
|
|
25
|
+
You can also inspect contacts, notification settings, folders, and group details without importing messages.
|
|
38
26
|
|
|
39
|
-
|
|
27
|
+
### Build a searchable local history
|
|
28
|
+
|
|
29
|
+
Sync one chat or many chats into the selected account’s SQLite database. Search and analyze the stored copy without reconnecting to Telegram.
|
|
40
30
|
|
|
41
31
|
```sh
|
|
42
|
-
|
|
43
|
-
|
|
32
|
+
tg sync @team
|
|
33
|
+
tg search "release" --chat @team
|
|
34
|
+
tg recent --chat @team --hours 24
|
|
44
35
|
```
|
|
45
36
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
## Installation
|
|
37
|
+
Local commands can also filter, summarize, and export stored messages.
|
|
49
38
|
|
|
50
|
-
|
|
39
|
+
### Follow live messages and download files
|
|
51
40
|
|
|
52
|
-
|
|
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.
|
|
53
42
|
|
|
54
43
|
```sh
|
|
55
|
-
|
|
44
|
+
tg listen @team --auto-download
|
|
56
45
|
```
|
|
57
46
|
|
|
58
|
-
|
|
47
|
+
### Keep a Markdown archive
|
|
59
48
|
|
|
60
|
-
|
|
49
|
+
The `archive` command writes incremental Markdown and optional media files. It tracks archive progress separately and does not populate SQLite.
|
|
61
50
|
|
|
62
51
|
```sh
|
|
63
|
-
tg
|
|
52
|
+
tg archive @team --download-media
|
|
64
53
|
```
|
|
65
54
|
|
|
66
|
-
|
|
55
|
+
Later runs append new messages and retry referenced media that is still missing.
|
|
67
56
|
|
|
68
|
-
|
|
69
|
-
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.
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
Setting only one of `TG_API_ID` or `TG_API_HASH` is an error. A malformed or unreadable saved configuration file is also an error; the CLI does not fall back to the built-in credentials in either case.
|
|
73
|
-
|
|
74
|
-
Personal credentials are stored locally as sensitive configuration. Never share them. API credentials are shared by all registered accounts, while each account keeps its own authentication session.
|
|
75
|
-
|
|
76
|
-
To persist a proxy for Telegram connections, run:
|
|
77
|
-
|
|
78
|
-
```sh
|
|
79
|
-
tg config set --proxy socks5://127.0.0.1:1080
|
|
80
|
-
```
|
|
57
|
+
### Send messages and manage groups
|
|
81
58
|
|
|
82
|
-
|
|
59
|
+
Send text, files, or captioned media groups from the terminal. Inspect and manage group members, administrators, invites, forum topics, and messages.
|
|
83
60
|
|
|
84
61
|
```sh
|
|
85
|
-
|
|
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
|
|
86
65
|
```
|
|
87
66
|
|
|
88
|
-
|
|
67
|
+
Telegram CLI also manages contacts, notification settings, and chat folders. The write-access gate covers commands that change Telegram.
|
|
89
68
|
|
|
90
|
-
|
|
69
|
+
### Automate across isolated accounts
|
|
91
70
|
|
|
92
|
-
|
|
71
|
+
Each registered account has a separate session and SQLite database. Select an account for one command without changing the default.
|
|
93
72
|
|
|
94
73
|
```sh
|
|
95
|
-
tg
|
|
96
|
-
tg config list --json
|
|
97
|
-
tg config list --yaml
|
|
98
|
-
tg config list --show-secrets
|
|
74
|
+
tg stats --account work --json
|
|
99
75
|
```
|
|
100
76
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
The output reports exactly five fields: the effective API ID, API hash, credential source, proxy URL, and proxy source. The API hash is masked by default; use `--show-secrets` to display it in full. The proxy URL is always printed in full and may contain credentials or an MTProxy secret, so avoid writing `config list` output to logs or sharing it. `tg config list` does not create a Telegram client or make a network connection.
|
|
77
|
+
Finite commands support JSON, YAML, and Markdown output. Failures return nonzero exit statuses and stable error codes.
|
|
104
78
|
|
|
105
|
-
|
|
79
|
+
## Install
|
|
106
80
|
|
|
107
|
-
|
|
81
|
+
Install Node.js 22 or later, then install Telegram CLI from npm:
|
|
108
82
|
|
|
109
83
|
```sh
|
|
110
|
-
|
|
84
|
+
npm install -g @will-17173/telegram-cli
|
|
111
85
|
```
|
|
112
86
|
|
|
113
|
-
##
|
|
87
|
+
## Get started
|
|
88
|
+
|
|
89
|
+
Authenticate one account, list its chats, sync one chat, and search the local copy:
|
|
114
90
|
|
|
115
91
|
```sh
|
|
116
|
-
# Add and authenticate the first account
|
|
117
92
|
tg account add
|
|
118
|
-
|
|
119
|
-
# Check authentication status
|
|
120
93
|
tg status
|
|
121
|
-
|
|
122
|
-
# List chats, then use a chat name, username, or ID where `<chat>` appears
|
|
123
94
|
tg chats
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
tg sync <chat>
|
|
127
|
-
|
|
128
|
-
# Search the locally synced messages
|
|
129
|
-
tg search "keyword" --chat <chat>
|
|
130
|
-
|
|
131
|
-
# Sync across all chats
|
|
132
|
-
tg sync-all --max-chats 20 --delay 1
|
|
133
|
-
|
|
134
|
-
# Listen for new messages and automatically download incoming attachments
|
|
135
|
-
tg listen <chat-or-id> --auto-download
|
|
136
|
-
|
|
137
|
-
# Use plain output, download attachments, and hide their message summaries
|
|
138
|
-
tg listen <chat-or-id> --no-interactive --auto-download --no-media
|
|
139
|
-
|
|
140
|
-
# Send a message
|
|
141
|
-
tg send <chat> "Hello from tg"
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
## Send messages and attachments
|
|
145
|
-
|
|
146
|
-
`send` requires `<chat>`. Send text, one or more files, or files with a caption:
|
|
147
|
-
|
|
148
|
-
```sh
|
|
149
|
-
# Text only
|
|
150
|
-
tg send <chat> "Text only"
|
|
151
|
-
|
|
152
|
-
# Files only; repeat --file to preserve this order
|
|
153
|
-
tg send <chat> --file ./photo.jpg --file ./clip.mp4
|
|
154
|
-
|
|
155
|
-
# Caption and files
|
|
156
|
-
tg send <chat> "Group caption" --file ./photo.jpg --file ./clip.mp4
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
`--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.
|
|
160
|
-
|
|
161
|
-
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.
|
|
162
|
-
|
|
163
|
-
## Multiple accounts
|
|
164
|
-
|
|
165
|
-
Each Telegram account has its own persisted authentication session and local message database. Add and authenticate an account interactively with:
|
|
166
|
-
|
|
167
|
-
```sh
|
|
168
|
-
tg account add
|
|
95
|
+
tg sync @team
|
|
96
|
+
tg search "release" --chat @team
|
|
169
97
|
```
|
|
170
98
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
```sh
|
|
174
|
-
# List registered accounts
|
|
175
|
-
tg account list
|
|
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.
|
|
176
100
|
|
|
177
|
-
|
|
178
|
-
tg account current
|
|
101
|
+
## Know where data goes
|
|
179
102
|
|
|
180
|
-
|
|
181
|
-
tg account switch
|
|
103
|
+
Check a command’s execution scope before you run it:
|
|
182
104
|
|
|
183
|
-
|
|
184
|
-
|
|
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. |
|
|
185
112
|
|
|
186
|
-
|
|
187
|
-
tg account remove <name> --force
|
|
188
|
-
```
|
|
113
|
+
Each account has a separate session and SQLite database. Add `--account work` to select an account for one command without changing the default.
|
|
189
114
|
|
|
190
|
-
|
|
115
|
+
## Protect remote data
|
|
191
116
|
|
|
192
|
-
|
|
117
|
+
Disable remote writes before read-only workflows or automation:
|
|
193
118
|
|
|
194
119
|
```sh
|
|
195
|
-
tg
|
|
196
|
-
tg
|
|
197
|
-
tg search "keyword" --account <name>
|
|
120
|
+
tg config write-access off
|
|
121
|
+
tg config write-access status
|
|
198
122
|
```
|
|
199
123
|
|
|
200
|
-
|
|
124
|
+
Run `tg config write-access on` when you intend to modify Telegram again. Enabling the gate does not authorize a specific write.
|
|
201
125
|
|
|
202
|
-
Telegram
|
|
126
|
+
Keep Telegram application programming interface (API) credentials, proxy credentials, session files, SQLite databases, exports, and archives private.
|
|
203
127
|
|
|
204
|
-
##
|
|
128
|
+
## Use with coding agents
|
|
205
129
|
|
|
206
|
-
|
|
130
|
+
Use JSON or YAML when a script or coding agent needs structured output:
|
|
207
131
|
|
|
208
132
|
```sh
|
|
209
|
-
|
|
210
|
-
tg group info <chat> --account alice --json
|
|
211
|
-
|
|
212
|
-
# Member list: type, name/username query, and bounded result count
|
|
213
|
-
tg group members <chat> --type admins --query alice --limit 50 --yaml
|
|
214
|
-
|
|
215
|
-
# One member's role, administrator rights, and restrictions
|
|
216
|
-
tg group member <chat> <user>
|
|
217
|
-
|
|
218
|
-
# Administrator audit log; --user and --type can be repeated
|
|
219
|
-
tg group audit <chat> --query invite --user <user> --type member_invited --type invite_changed --limit 100 --account alice --json
|
|
220
|
-
|
|
221
|
-
# Management examples (the chat argument comes before action arguments)
|
|
222
|
-
tg group member ban @team @alice --yes
|
|
223
|
-
tg group chat slowmode @team 30s
|
|
224
|
-
tg group topic --help
|
|
225
|
-
```
|
|
226
|
-
|
|
227
|
-
`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.
|
|
228
|
-
|
|
229
|
-
`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 exactly these 17 stable grouped event types: `info_changed`, `settings_changed`, `member_joined`, `member_left`, `member_invited`, `member_banned`, `member_unbanned`, `member_restricted`, `member_unrestricted`, `admin_promoted`, `admin_demoted`, `message_deleted`, `message_edited`, `message_pinned`, `invite_changed`, `topic_changed`, and `other`.
|
|
230
|
-
|
|
231
|
-
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.
|
|
232
|
-
|
|
233
|
-
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.
|
|
234
|
-
|
|
235
|
-
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. Ownership transfer currently reports `password_required` when Telegram requires a password; this release does not accept a password for that action.
|
|
236
|
-
|
|
237
|
-
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.
|
|
238
|
-
|
|
239
|
-
## Slash commands while listening
|
|
240
|
-
|
|
241
|
-
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:
|
|
242
|
-
|
|
243
|
-
```text
|
|
244
|
-
/reply <message-id> <content>
|
|
245
|
-
/member mute @alice 2h
|
|
246
|
-
```
|
|
247
|
-
|
|
248
|
-
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/Down to move through matches. Tab completes the selected command; Enter also completes an incomplete selection, or runs a complete command. Esc closes the menu, result, or confirmation.
|
|
249
|
-
|
|
250
|
-
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`.
|
|
251
|
-
|
|
252
|
-
## Online and local commands
|
|
253
|
-
|
|
254
|
-
Online commands connect to Telegram and require a valid session. These include `status`, `whoami`, `chats`, `history`, `sync`, `sync-all`, `refresh`, `info`, all `group` inspection and management families, `send`, `edit`, `delete`, and `listen`.
|
|
255
|
-
|
|
256
|
-
Local commands read or modify the selected account's message database without connecting to Telegram. These include `search`, `recent`, `stats`, `top`, `timeline`, `today`, `filter`, `export`, and `purge`.
|
|
257
|
-
|
|
258
|
-
## Review recent messages
|
|
259
|
-
|
|
260
|
-
`tg recent` shows messages stored during the last 24 hours, with a default limit of 50. Filter the results by chat or sender, or change the time window and limit:
|
|
261
|
-
|
|
262
|
-
```sh
|
|
263
|
-
tg recent --chat <chat> --sender <sender> --hours 6 --limit 100
|
|
264
|
-
```
|
|
265
|
-
|
|
266
|
-
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.
|
|
267
|
-
|
|
268
|
-
JSON and YAML output keep the stored-message structure for scripts. `recent` reads local SQLite data and does not connect to Telegram.
|
|
269
|
-
|
|
270
|
-
## Command reference
|
|
271
|
-
|
|
272
|
-
Run the built-in help for the complete, current command list:
|
|
273
|
-
|
|
274
|
-
```sh
|
|
275
|
-
tg --help
|
|
276
|
-
```
|
|
277
|
-
|
|
278
|
-
Common commands:
|
|
279
|
-
|
|
280
|
-
| Command | Purpose |
|
|
281
|
-
| --- | --- |
|
|
282
|
-
| `tg account add` | Authenticate and register another Telegram account. |
|
|
283
|
-
| `tg account list` | List registered accounts and show which one is current. |
|
|
284
|
-
| `tg account current` | Show the current account. |
|
|
285
|
-
| `tg account switch [name]` | Select the default account interactively or set it by name. |
|
|
286
|
-
| `tg account remove <name> --force` | Remove an account and its local session/data. |
|
|
287
|
-
| `tg status` | Check whether the Telegram account is authenticated. |
|
|
288
|
-
| `tg whoami` | Show basic authenticated account information. |
|
|
289
|
-
| `tg config set --api-id <id> --api-hash <hash>` | Save Telegram API credentials for persistent use. |
|
|
290
|
-
| `tg config set --proxy <url>` | Save an optional proxy for account login and Telegram-backed commands. |
|
|
291
|
-
| `tg config list [--show-secrets]` | Show effective configuration values and sources; the proxy URL is always visible. |
|
|
292
|
-
| `tg chats` | List available chats. |
|
|
293
|
-
| `tg history <chat> -n <limit>` | Fetch and store full chat history (default up to 1000 messages). |
|
|
294
|
-
| `tg sync <chat>` | Incrementally sync new messages for one chat. |
|
|
295
|
-
| `tg sync-all` | Sync messages from all chats, using local last-message IDs for incremental updates. |
|
|
296
|
-
| `tg refresh` | Alias-like command for bulk sync with same runtime options as `sync-all`. |
|
|
297
|
-
| `tg listen [chat ...]` | Stream incoming messages from selected chats or all chats. |
|
|
298
|
-
| `tg listen --no-media` | Hide attachment summary lines while listening. |
|
|
299
|
-
| `tg listen <chat-or-id> --auto-download` | Automatically download incoming attachments while listening. |
|
|
300
|
-
| `tg search "keyword" --chat <chat>` | Search messages already stored locally. |
|
|
301
|
-
| `tg recent`, `tg today`, `tg stats`, `tg top`, `tg timeline` | Explore local message data. |
|
|
302
|
-
| `tg filter <keywords>` | Filter local messages by keyword with optional chat/hour filters. |
|
|
303
|
-
| `tg export <chat>` | Export local messages from a chat. |
|
|
304
|
-
| `tg send <chat> [message] [--file <path> ...]` | Send text, files, or a captioned media group. |
|
|
305
|
-
| `tg edit <chat> <msgId> <text>` | Edit a message. |
|
|
306
|
-
| `tg delete <chat> <msgIds...>` | Delete one or more messages. |
|
|
307
|
-
| `tg purge <chat> --yes` | Remove a chat's locally stored messages. |
|
|
308
|
-
| `tg info <chat>` | Show metadata for a Telegram chat. |
|
|
309
|
-
| `tg group info <chat>` | Show read-only group or supergroup details. |
|
|
310
|
-
| `tg group members <chat> [--type <type>] [--query <text>] [--limit <count>]` | List and filter members (default `recent`, limit 100; maximum 200). |
|
|
311
|
-
| `tg group member <chat> <user>` | Show one member's role, rights, and restrictions. |
|
|
312
|
-
| `tg group audit <chat> [--query <text>] [--user <user>] [--type <type>] [--limit <count>]` | Query the administrator audit log (default 100; maximum 500). |
|
|
313
|
-
| `tg group member/admin/chat/invite/topic/message --help` | Discover group management actions by family. |
|
|
314
|
-
|
|
315
|
-
All sync-like commands write to local SQLite storage. The `sync-all` and `refresh` commands process multiple chats based on locally stored message IDs.
|
|
316
|
-
|
|
317
|
-
Many commands support `--json` or `--yaml` for structured output. Failed commands return a nonzero exit code, so scripts can detect errors without parsing human-readable text.
|
|
318
|
-
|
|
319
|
-
Common options:
|
|
320
|
-
|
|
321
|
-
| Option | Purpose |
|
|
322
|
-
| --- | --- |
|
|
323
|
-
| `--account <name>` | Use a registered account without changing the current account. |
|
|
324
|
-
| `--json` / `--yaml` | Emit structured output when the command supports it. |
|
|
325
|
-
| `-v`, `--verbose` | Enable debug logging. |
|
|
326
|
-
| `-V`, `--version` | Print the installed version. |
|
|
327
|
-
|
|
328
|
-
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.
|
|
329
|
-
|
|
330
|
-
### Sync and listen behavior
|
|
331
|
-
|
|
332
|
-
- `sync-all` and `refresh` are batch operations for local persistence; they are not read-only.
|
|
333
|
-
- `listen` prints a concise separator for each incoming message and can optionally suppress attachment summaries.
|
|
334
|
-
- Telegram media groups appear as one incoming message with a combined attachment summary.
|
|
335
|
-
- Reply output includes the original message's local context when available, or identifies the missing message ID.
|
|
336
|
-
- In interactive `listen`, reply with `/reply <message-id> <content>`. Add attachments with repeatable `--file <path>` options; quote paths that contain spaces.
|
|
337
|
-
- Contact cards show the available name and phone number in attachment summaries. They aren't downloadable attachments and are hidden by `--no-media`.
|
|
338
|
-
- `listen --auto-download` works in both interactive and plain-text modes, saves attachments to `~/Downloads/telegram-cli`, and runs at most three downloads concurrently.
|
|
339
|
-
- Downloads keep Telegram-provided filenames. Unnamed downloads use a MIME-derived extension, then the media-kind extension, then `.bin`.
|
|
340
|
-
- Download failures are reported without stopping the listener. `--no-media` hides attachment summaries only; downloads still run when it is combined with `--auto-download`.
|
|
341
|
-
|
|
342
|
-
## Troubleshooting
|
|
343
|
-
|
|
344
|
-
### No active account
|
|
345
|
-
|
|
346
|
-
If a command reports `account_required`, add an account or select an existing one:
|
|
347
|
-
|
|
348
|
-
```sh
|
|
349
|
-
tg account add
|
|
350
|
-
tg account switch <name>
|
|
351
|
-
```
|
|
352
|
-
|
|
353
|
-
### Session is no longer valid
|
|
354
|
-
|
|
355
|
-
If Telegram returns `AUTH_KEY_UNREGISTERED`, remove the invalid local session and authenticate again:
|
|
356
|
-
|
|
357
|
-
```sh
|
|
358
|
-
tg account remove <name> --force
|
|
359
|
-
tg account add
|
|
133
|
+
tg search "release" --account work --json
|
|
360
134
|
```
|
|
361
135
|
|
|
362
|
-
|
|
136
|
+
Failures return a nonzero exit status and a stable error code. The explicit `--account` option keeps automation on the intended account.
|
|
363
137
|
|
|
364
|
-
|
|
138
|
+
Install the [`using-telegram-cli` agent skill](https://skills.sh/will-17173/telegram-cli/using-telegram-cli) in a supported coding agent:
|
|
365
139
|
|
|
366
140
|
```sh
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
Set both `TG_API_ID` and `TG_API_HASH` when using environment variables. Setting only one causes a configuration error.
|
|
371
|
-
|
|
372
|
-
## Local data and privacy
|
|
373
|
-
|
|
374
|
-
Persisted configuration, authentication sessions, and synced messages remain on your machine unless you copy or export them. The relevant files under `DATA_DIR` are:
|
|
375
|
-
|
|
376
|
-
```text
|
|
377
|
-
config.json
|
|
378
|
-
accounts.json
|
|
379
|
-
accounts/<name>/session
|
|
380
|
-
accounts/<name>/messages.db
|
|
141
|
+
npx skills add https://github.com/will-17173/telegram-cli \
|
|
142
|
+
--skill using-telegram-cli
|
|
381
143
|
```
|
|
382
144
|
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
The `config.json` file may contain an optional `proxy` setting in addition to API credentials. CLI success and error output does not print the stored proxy URL, but you must still protect `config.json`, the environment, and shell history because proxy URLs can contain credentials or MTProxy secrets.
|
|
145
|
+
The skill covers authentication, synchronization, queries, and write safety.
|
|
386
146
|
|
|
387
|
-
##
|
|
147
|
+
## Develop
|
|
388
148
|
|
|
389
|
-
|
|
149
|
+
Use pnpm with Node.js 22 or later:
|
|
390
150
|
|
|
391
151
|
```sh
|
|
392
152
|
pnpm install
|
|
393
153
|
pnpm dev --help
|
|
394
154
|
pnpm test
|
|
395
155
|
pnpm typecheck
|
|
156
|
+
pnpm build
|
|
396
157
|
```
|
|
397
158
|
|
|
398
|
-
During development, expose the current checkout as a global `tg` command that runs the TypeScript source directly. From the project root:
|
|
399
|
-
|
|
400
|
-
```sh
|
|
401
|
-
mkdir -p ~/.local/bin
|
|
402
|
-
cat > ~/.local/bin/tg <<EOF
|
|
403
|
-
#!/bin/sh
|
|
404
|
-
exec "$(pwd)/node_modules/.bin/tsx" "$(pwd)/src/dev.ts" "\$@"
|
|
405
|
-
EOF
|
|
406
|
-
chmod +x ~/.local/bin/tg
|
|
407
|
-
rehash
|
|
408
|
-
```
|
|
409
|
-
|
|
410
|
-
Make sure `~/.local/bin` is in `PATH`. Subsequent `tg` invocations load the latest source changes.
|
|
411
|
-
|
|
412
|
-
For local source development, create a `.env` file in the project root:
|
|
413
|
-
|
|
414
|
-
```dotenv
|
|
415
|
-
TG_API_ID=your_telegram_api_id
|
|
416
|
-
TG_API_HASH=your_telegram_api_hash
|
|
417
|
-
```
|
|
418
|
-
|
|
419
|
-
`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.
|
|
420
|
-
|
|
421
159
|
## License
|
|
422
160
|
|
|
423
|
-
Licensed under [GPL-3.0](LICENSE).
|
|
161
|
+
Licensed under [GPL-3.0-only](LICENSE).
|