telegram-userbot-cli 0.1.0__tar.gz
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.
- telegram_userbot_cli-0.1.0/.env.example +25 -0
- telegram_userbot_cli-0.1.0/.github/workflows/ci.yml +36 -0
- telegram_userbot_cli-0.1.0/.github/workflows/release.yml +32 -0
- telegram_userbot_cli-0.1.0/.gitignore +8 -0
- telegram_userbot_cli-0.1.0/LICENSE +201 -0
- telegram_userbot_cli-0.1.0/PKG-INFO +126 -0
- telegram_userbot_cli-0.1.0/README-zh.md +105 -0
- telegram_userbot_cli-0.1.0/README.md +113 -0
- telegram_userbot_cli-0.1.0/ROADMAP.md +64 -0
- telegram_userbot_cli-0.1.0/pyproject.toml +33 -0
- telegram_userbot_cli-0.1.0/src/tgcli/__init__.py +3 -0
- telegram_userbot_cli-0.1.0/src/tgcli/__main__.py +6 -0
- telegram_userbot_cli-0.1.0/src/tgcli/auth.py +119 -0
- telegram_userbot_cli-0.1.0/src/tgcli/chats.py +229 -0
- telegram_userbot_cli-0.1.0/src/tgcli/cli.py +101 -0
- telegram_userbot_cli-0.1.0/src/tgcli/client.py +46 -0
- telegram_userbot_cli-0.1.0/src/tgcli/config.py +129 -0
- telegram_userbot_cli-0.1.0/src/tgcli/media.py +91 -0
- telegram_userbot_cli-0.1.0/src/tgcli/messages.py +122 -0
- telegram_userbot_cli-0.1.0/src/tgcli/output.py +46 -0
- telegram_userbot_cli-0.1.0/src/tgcli/resolve.py +113 -0
- telegram_userbot_cli-0.1.0/uv.lock +148 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Copy to .env and fill in real values. Never commit .env.
|
|
2
|
+
|
|
3
|
+
# Required: API credentials from https://my.telegram.org/apps
|
|
4
|
+
TELEGRAM_API_ID=
|
|
5
|
+
TELEGRAM_API_HASH=
|
|
6
|
+
|
|
7
|
+
# Session string. Run `tg login --qr` to generate one (written to .env automatically).
|
|
8
|
+
# Do NOT share this value, and do NOT reuse the session of another client
|
|
9
|
+
# (e.g. an MCP daemon) — two live clients with one session will trigger
|
|
10
|
+
# AuthKeyDuplicatedError.
|
|
11
|
+
TELEGRAM_SESSION_STRING=
|
|
12
|
+
|
|
13
|
+
# Proxy is required when Telegram is unreachable directly (e.g. in CN networks).
|
|
14
|
+
# Common local setup: Clash mixed port, or a LAN socks5 proxy.
|
|
15
|
+
TELEGRAM_PROXY_TYPE=socks5
|
|
16
|
+
TELEGRAM_PROXY_HOST=127.0.0.1
|
|
17
|
+
TELEGRAM_PROXY_PORT=7890
|
|
18
|
+
# TELEGRAM_PROXY_USERNAME=
|
|
19
|
+
# TELEGRAM_PROXY_PASSWORD=
|
|
20
|
+
# TELEGRAM_PROXY_RDNS=true
|
|
21
|
+
|
|
22
|
+
# Optional: stable device identity shown in Telegram Settings → Devices.
|
|
23
|
+
# TELEGRAM_DEVICE_MODEL=
|
|
24
|
+
# TELEGRAM_SYSTEM_VERSION=
|
|
25
|
+
# TELEGRAM_APP_VERSION=
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
lint:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v4
|
|
13
|
+
- uses: astral-sh/setup-uv@v5
|
|
14
|
+
- name: Install dependencies
|
|
15
|
+
run: uv sync --dev
|
|
16
|
+
- name: Ruff lint
|
|
17
|
+
run: uv run ruff check src/
|
|
18
|
+
- name: Ruff format check
|
|
19
|
+
run: uv run ruff format --check src/
|
|
20
|
+
|
|
21
|
+
build:
|
|
22
|
+
runs-on: ubuntu-latest
|
|
23
|
+
steps:
|
|
24
|
+
- uses: actions/checkout@v4
|
|
25
|
+
- uses: astral-sh/setup-uv@v5
|
|
26
|
+
- name: Build package
|
|
27
|
+
run: uv build
|
|
28
|
+
- name: Smoke-test the built wheel installs
|
|
29
|
+
run: |
|
|
30
|
+
uv venv /tmp/smoke
|
|
31
|
+
uv pip install --python /tmp/smoke/bin/python dist/*.whl
|
|
32
|
+
/tmp/smoke/bin/tg --version
|
|
33
|
+
- uses: actions/upload-artifact@v4
|
|
34
|
+
with:
|
|
35
|
+
name: dist
|
|
36
|
+
path: dist/
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags: ["v*"]
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
contents: write
|
|
9
|
+
id-token: write # required for PyPI Trusted Publishing (OIDC token exchange)
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
release:
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
|
+
- uses: astral-sh/setup-uv@v5
|
|
17
|
+
- name: Build package
|
|
18
|
+
run: uv build
|
|
19
|
+
|
|
20
|
+
# Requires PyPI Trusted Publishing to be configured once:
|
|
21
|
+
# PyPI project "telegram-userbot-cli" → Publishing → Add Trusted Publisher →
|
|
22
|
+
# owner=noexcs, repository=telegram-cli, workflow=release.yml.
|
|
23
|
+
- name: Publish to PyPI
|
|
24
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
25
|
+
with:
|
|
26
|
+
packages-dir: dist/
|
|
27
|
+
|
|
28
|
+
- name: GitHub Release
|
|
29
|
+
uses: softprops/action-gh-release@v2
|
|
30
|
+
with:
|
|
31
|
+
files: dist/*
|
|
32
|
+
generate_release_notes: true
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: telegram-userbot-cli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Full-featured Telegram command-line client powered by a Telethon userbot (your own account, not a bot token)
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Requires-Dist: python-dotenv>=1.0
|
|
9
|
+
Requires-Dist: python-socks[asyncio]>=2.4
|
|
10
|
+
Requires-Dist: qrcode>=8.0
|
|
11
|
+
Requires-Dist: telethon<2,>=1.44
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
# telegram-userbot-cli
|
|
15
|
+
|
|
16
|
+
[](https://github.com/noexcs/telegram-cli/actions/workflows/ci.yml)
|
|
17
|
+
[](https://pypi.org/project/telegram-userbot-cli/)
|
|
18
|
+
|
|
19
|
+
Standalone Telegram command-line client. Connects directly to Telegram via
|
|
20
|
+
[Telethon](https://github.com/LonamiWebs/Telethon) (MTProto userbot) — **no MCP,
|
|
21
|
+
no daemon, no external service**. Everything the CLI does lives in the CLI.
|
|
22
|
+
|
|
23
|
+
[中文说明](README-zh.md) · [Roadmap](ROADMAP.md)
|
|
24
|
+
|
|
25
|
+
## Features
|
|
26
|
+
|
|
27
|
+
- QR-code login (`tg login --qr`) with an independent session
|
|
28
|
+
- Messaging: send / reply / edit / delete / forward / polls
|
|
29
|
+
- Chats: list dialogs, history, pinned messages, in-chat & global search
|
|
30
|
+
- Media: download, send files / albums, voice notes
|
|
31
|
+
- Contacts & profile management
|
|
32
|
+
- Chat resolution by name fuzzy match, `@username`, numeric id, or `me`
|
|
33
|
+
(Saved Messages), plus local aliases
|
|
34
|
+
|
|
35
|
+
## Install
|
|
36
|
+
|
|
37
|
+
Requires Python >= 3.10 and [uv](https://docs.astral.sh/uv/).
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
# from PyPI
|
|
41
|
+
uv tool install telegram-userbot-cli # or: pipx install telegram-userbot-cli
|
|
42
|
+
|
|
43
|
+
# from source (development)
|
|
44
|
+
git clone https://github.com/noexcs/telegram-cli.git
|
|
45
|
+
cd telegram-cli
|
|
46
|
+
uv tool install -e .
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
The `tg` command lands in `~/.local/bin/tg` (make sure `~/.local/bin` is on
|
|
50
|
+
your PATH).
|
|
51
|
+
|
|
52
|
+
## Configuration
|
|
53
|
+
|
|
54
|
+
Copy `.env.example` to `.env` and fill in the values:
|
|
55
|
+
|
|
56
|
+
| Variable | Meaning |
|
|
57
|
+
|---|---|
|
|
58
|
+
| `TELEGRAM_API_ID` / `TELEGRAM_API_HASH` | API credentials from https://my.telegram.org/apps (required) |
|
|
59
|
+
| `TELEGRAM_SESSION_STRING` | Session string; generated automatically by `tg login` |
|
|
60
|
+
| `TELEGRAM_PROXY_TYPE/HOST/PORT` | Proxy settings; **required** when Telegram is unreachable directly (e.g. CN networks). Common setup: `socks5` + `127.0.0.1:7890` (Clash) |
|
|
61
|
+
| `TELEGRAM_PROXY_USERNAME/PASSWORD/RDNS` | Optional proxy auth / remote DNS |
|
|
62
|
+
| `TELEGRAM_DEVICE_MODEL/SYSTEM_VERSION/APP_VERSION` | Optional stable device identity |
|
|
63
|
+
|
|
64
|
+
Precedence: real environment variables > `.env` in the current directory >
|
|
65
|
+
`.env` in the project root.
|
|
66
|
+
|
|
67
|
+
## Login
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
tg login --qr # scan the QR with your phone (Settings → Devices → Link Desktop Device)
|
|
71
|
+
tg login --phone # fallback: SMS code flow
|
|
72
|
+
tg me # verify
|
|
73
|
+
tg logout # remove the session
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
> **Note:** the session is independent — do not reuse the session string of
|
|
77
|
+
> another live client (e.g. an MCP daemon). Two live clients sharing one
|
|
78
|
+
> session trigger `AuthKeyDuplicatedError`.
|
|
79
|
+
|
|
80
|
+
## Commands
|
|
81
|
+
|
|
82
|
+
| Command | Description |
|
|
83
|
+
|---|---|
|
|
84
|
+
| `tg me` | Show your account info |
|
|
85
|
+
| `tg chats [keyword]` | List dialogs; `-t user/group/channel`, `-u` unread, `--archived` |
|
|
86
|
+
| `tg hist <chat> [n]` | Recent messages (default 10) |
|
|
87
|
+
| `tg send <chat> <text...>` | Send a message; `-p md/html` |
|
|
88
|
+
| `tg reply <chat> <msg_id> <text...>` | Reply to a message |
|
|
89
|
+
| `tg edit <chat> <msg_id> <new_text>` | Edit your own message |
|
|
90
|
+
| `tg del <chat> <ids...>` | Delete messages (revoke for both sides) |
|
|
91
|
+
| `tg fwd <src> <msg_ids...> <dst>` | Forward messages (last arg is the target) |
|
|
92
|
+
| `tg dl <chat> <msg_id> [-o path]` | Download media (default `~/Downloads/telegram_<chat>_<msgid>`) |
|
|
93
|
+
| `tg sf <chat> <files...> [-c caption]` | Send files; 2–10 files become an album |
|
|
94
|
+
| `tg voice <chat> <file>` | Send a voice note |
|
|
95
|
+
| `tg search <chat> <query>` | Search messages inside a chat |
|
|
96
|
+
| `tg gsearch <query> [-p page]` | Global search across public chats |
|
|
97
|
+
| `tg contacts` | List contacts |
|
|
98
|
+
| `tg pinned <chat>` | Show pinned messages |
|
|
99
|
+
| `tg poll <chat> "<question>" <opts...>` | Create a poll; `--multiple/--quiz/--public` |
|
|
100
|
+
| `tg profile --name/--bio/--photo` | Update your profile |
|
|
101
|
+
| `tg alias set/list/rm` | Local chat aliases (`~/.config/tg/aliases.json`) |
|
|
102
|
+
|
|
103
|
+
Global flags: `--account` (v1: default only), `--json` (raw JSON output).
|
|
104
|
+
Exit codes: `0` ok, `1` command error, `2` config/connection/session error,
|
|
105
|
+
`130` interrupted.
|
|
106
|
+
|
|
107
|
+
## FAQ
|
|
108
|
+
|
|
109
|
+
- **`AuthKeyDuplicatedError`** — two live clients share one session. Run
|
|
110
|
+
`tg logout` then `tg login --qr` to create a fresh one.
|
|
111
|
+
- **`FloodWaitError`** — Telegram rate limit; the CLI waits up to 60s
|
|
112
|
+
automatically, longer waits are reported.
|
|
113
|
+
- **"cannot reach Telegram"** — check the proxy (e.g. Clash on
|
|
114
|
+
`127.0.0.1:7890`) and `TELEGRAM_PROXY_*` in `.env`.
|
|
115
|
+
|
|
116
|
+
## Roadmap
|
|
117
|
+
|
|
118
|
+
See [ROADMAP.md](ROADMAP.md) for the full plan (messaging enhancements, chat &
|
|
119
|
+
group management, contacts, folders, multi-account, voice transcription).
|
|
120
|
+
|
|
121
|
+
## License & acknowledgments
|
|
122
|
+
|
|
123
|
+
[Apache-2.0](LICENSE). Proxy-injection approach, session-generation flow and
|
|
124
|
+
environment variable naming inspired by
|
|
125
|
+
[chigwell/telegram-mcp](https://github.com/chigwell/telegram-mcp)
|
|
126
|
+
(Apache-2.0).
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# telegram-userbot-cli
|
|
2
|
+
|
|
3
|
+
[](https://github.com/noexcs/telegram-cli/actions/workflows/ci.yml)
|
|
4
|
+
[](https://pypi.org/project/telegram-userbot-cli/)
|
|
5
|
+
|
|
6
|
+
独立 Telegram 命令行客户端。通过 [Telethon](https://github.com/LonamiWebs/Telethon)
|
|
7
|
+
(MTProto userbot)直连 Telegram —— **不依赖 MCP、不依赖守护进程、不依赖任何外部服务**,
|
|
8
|
+
所有功能都在 CLI 内完成。
|
|
9
|
+
|
|
10
|
+
[English](README.md) · [Roadmap](ROADMAP.md)
|
|
11
|
+
|
|
12
|
+
## 特性
|
|
13
|
+
|
|
14
|
+
- 扫码登录(`tg login --qr`),使用独立会话
|
|
15
|
+
- 消息:发送 / 引用回复 / 编辑 / 删除 / 转发 / 投票
|
|
16
|
+
- 聊天:会话列表、历史记录、置顶消息、会话内搜索与全局搜索
|
|
17
|
+
- 媒体:下载、发文件 / 相册、语音条
|
|
18
|
+
- 联系人与个人资料管理
|
|
19
|
+
- 会话解析:名称模糊匹配、`@username`、数字 id、`me`(已保存消息),以及本地别名
|
|
20
|
+
|
|
21
|
+
## 安装
|
|
22
|
+
|
|
23
|
+
需要 Python >= 3.10 与 [uv](https://docs.astral.sh/uv/)。
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
# 从 PyPI 安装
|
|
27
|
+
uv tool install telegram-userbot-cli # 或 pipx install telegram-userbot-cli
|
|
28
|
+
|
|
29
|
+
# 从源码安装(开发)
|
|
30
|
+
git clone https://github.com/noexcs/telegram-cli.git
|
|
31
|
+
cd telegram-cli
|
|
32
|
+
uv tool install -e .
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
`tg` 命令安装在 `~/.local/bin/tg`(请确保 `~/.local/bin` 在 PATH 中)。
|
|
36
|
+
|
|
37
|
+
## 配置
|
|
38
|
+
|
|
39
|
+
把 `.env.example` 复制为 `.env` 并填入真实值:
|
|
40
|
+
|
|
41
|
+
| 变量 | 含义 |
|
|
42
|
+
|---|---|
|
|
43
|
+
| `TELEGRAM_API_ID` / `TELEGRAM_API_HASH` | my.telegram.org/apps 获取的 API 凭据(必需) |
|
|
44
|
+
| `TELEGRAM_SESSION_STRING` | 会话字符串;`tg login` 自动写入 |
|
|
45
|
+
| `TELEGRAM_PROXY_TYPE/HOST/PORT` | 代理配置;**本机必须代理**(如 socks5 + 127.0.0.1:7890 Clash) |
|
|
46
|
+
| `TELEGRAM_PROXY_USERNAME/PASSWORD/RDNS` | 可选代理认证 / 远程 DNS |
|
|
47
|
+
| `TELEGRAM_DEVICE_MODEL/SYSTEM_VERSION/APP_VERSION` | 可选设备标识(显示在 TG 设置→设备) |
|
|
48
|
+
|
|
49
|
+
优先级:真实环境变量 > 当前目录 `.env` > 项目根目录 `.env`。
|
|
50
|
+
|
|
51
|
+
## 登录
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
tg login --qr # 手机扫码(设置 → 设备 → 链接桌面设备)
|
|
55
|
+
tg login --phone # 备用:短信验证码流程
|
|
56
|
+
tg me # 验证
|
|
57
|
+
tg logout # 退出登录并删除会话
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
> **注意**:本 CLI 使用独立会话——不要与其他在线的客户端(例如 MCP 守护进程)
|
|
61
|
+
> 共用同一个 session 字符串,否则会触发 `AuthKeyDuplicatedError`。
|
|
62
|
+
|
|
63
|
+
## 命令
|
|
64
|
+
|
|
65
|
+
| 命令 | 说明 |
|
|
66
|
+
|---|---|
|
|
67
|
+
| `tg me` | 查看自己的账号信息 |
|
|
68
|
+
| `tg chats [关键词]` | 会话列表;`-t user/group/channel`、`-u` 只看未读、`--archived` |
|
|
69
|
+
| `tg hist <会话> [条数]` | 最近消息(默认 10 条) |
|
|
70
|
+
| `tg send <会话> <文本...>` | 发消息;`-p md/html` |
|
|
71
|
+
| `tg reply <会话> <消息id> <文本...>` | 引用回复 |
|
|
72
|
+
| `tg edit <会话> <消息id> <新文本>` | 编辑自己发的消息 |
|
|
73
|
+
| `tg del <会话> <id...>` | 删消息(双方撤回) |
|
|
74
|
+
| `tg fwd <来源> <消息id...> <目标>` | 转发(最后一个参数是目标) |
|
|
75
|
+
| `tg dl <会话> <消息id> [-o 路径]` | 下载媒体(默认 `~/Downloads/telegram_<会话>_<消息id>`) |
|
|
76
|
+
| `tg sf <会话> <文件...> [-c 说明]` | 发文件;2–10 个自动合并为相册 |
|
|
77
|
+
| `tg voice <会话> <文件>` | 发语音条 |
|
|
78
|
+
| `tg search <会话> <关键词>` | 会话内搜索 |
|
|
79
|
+
| `tg gsearch <关键词> [-p 页]` | 全局搜索公开频道 |
|
|
80
|
+
| `tg contacts` | 联系人列表 |
|
|
81
|
+
| `tg pinned <会话>` | 查看置顶消息 |
|
|
82
|
+
| `tg poll <会话> "<问题>" <选项...>` | 创建投票;`--multiple/--quiz/--public` |
|
|
83
|
+
| `tg profile --name/--bio/--photo` | 修改个人资料 |
|
|
84
|
+
| `tg alias set/list/rm` | 本地会话别名(`~/.config/tg/aliases.json`) |
|
|
85
|
+
|
|
86
|
+
全局选项:`--account`(v1 仅 default)、`--json`(原始 JSON 输出)。
|
|
87
|
+
退出码:`0` 成功、`1` 命令错误、`2` 配置/连接/会话错误、`130` 中断。
|
|
88
|
+
|
|
89
|
+
## 常见问题
|
|
90
|
+
|
|
91
|
+
- **`AuthKeyDuplicatedError`** —— 两个在线客户端共用了同一个会话。先
|
|
92
|
+
`tg logout` 再 `tg login --qr` 生成新会话即可。
|
|
93
|
+
- **`FloodWaitError`** —— Telegram 限流;60 秒内自动等待,更长的会明确提示。
|
|
94
|
+
- **"cannot reach Telegram"** —— 检查代理是否存活(如 Clash 127.0.0.1:7890)
|
|
95
|
+
以及 `.env` 里的 `TELEGRAM_PROXY_*`。
|
|
96
|
+
|
|
97
|
+
## 路线图
|
|
98
|
+
|
|
99
|
+
完整规划见 [ROADMAP.md](ROADMAP.md)(消息增强、聊天与群管理、联系人、
|
|
100
|
+
文件夹、多账号、语音转文字)。
|
|
101
|
+
|
|
102
|
+
## 协议与致谢
|
|
103
|
+
|
|
104
|
+
[Apache-2.0](LICENSE)。代理注入思路、会话生成流程与环境变量命名借鉴自
|
|
105
|
+
[chigwell/telegram-mcp](https://github.com/chigwell/telegram-mcp)(Apache-2.0)。
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# telegram-userbot-cli
|
|
2
|
+
|
|
3
|
+
[](https://github.com/noexcs/telegram-cli/actions/workflows/ci.yml)
|
|
4
|
+
[](https://pypi.org/project/telegram-userbot-cli/)
|
|
5
|
+
|
|
6
|
+
Standalone Telegram command-line client. Connects directly to Telegram via
|
|
7
|
+
[Telethon](https://github.com/LonamiWebs/Telethon) (MTProto userbot) — **no MCP,
|
|
8
|
+
no daemon, no external service**. Everything the CLI does lives in the CLI.
|
|
9
|
+
|
|
10
|
+
[中文说明](README-zh.md) · [Roadmap](ROADMAP.md)
|
|
11
|
+
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
- QR-code login (`tg login --qr`) with an independent session
|
|
15
|
+
- Messaging: send / reply / edit / delete / forward / polls
|
|
16
|
+
- Chats: list dialogs, history, pinned messages, in-chat & global search
|
|
17
|
+
- Media: download, send files / albums, voice notes
|
|
18
|
+
- Contacts & profile management
|
|
19
|
+
- Chat resolution by name fuzzy match, `@username`, numeric id, or `me`
|
|
20
|
+
(Saved Messages), plus local aliases
|
|
21
|
+
|
|
22
|
+
## Install
|
|
23
|
+
|
|
24
|
+
Requires Python >= 3.10 and [uv](https://docs.astral.sh/uv/).
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# from PyPI
|
|
28
|
+
uv tool install telegram-userbot-cli # or: pipx install telegram-userbot-cli
|
|
29
|
+
|
|
30
|
+
# from source (development)
|
|
31
|
+
git clone https://github.com/noexcs/telegram-cli.git
|
|
32
|
+
cd telegram-cli
|
|
33
|
+
uv tool install -e .
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
The `tg` command lands in `~/.local/bin/tg` (make sure `~/.local/bin` is on
|
|
37
|
+
your PATH).
|
|
38
|
+
|
|
39
|
+
## Configuration
|
|
40
|
+
|
|
41
|
+
Copy `.env.example` to `.env` and fill in the values:
|
|
42
|
+
|
|
43
|
+
| Variable | Meaning |
|
|
44
|
+
|---|---|
|
|
45
|
+
| `TELEGRAM_API_ID` / `TELEGRAM_API_HASH` | API credentials from https://my.telegram.org/apps (required) |
|
|
46
|
+
| `TELEGRAM_SESSION_STRING` | Session string; generated automatically by `tg login` |
|
|
47
|
+
| `TELEGRAM_PROXY_TYPE/HOST/PORT` | Proxy settings; **required** when Telegram is unreachable directly (e.g. CN networks). Common setup: `socks5` + `127.0.0.1:7890` (Clash) |
|
|
48
|
+
| `TELEGRAM_PROXY_USERNAME/PASSWORD/RDNS` | Optional proxy auth / remote DNS |
|
|
49
|
+
| `TELEGRAM_DEVICE_MODEL/SYSTEM_VERSION/APP_VERSION` | Optional stable device identity |
|
|
50
|
+
|
|
51
|
+
Precedence: real environment variables > `.env` in the current directory >
|
|
52
|
+
`.env` in the project root.
|
|
53
|
+
|
|
54
|
+
## Login
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
tg login --qr # scan the QR with your phone (Settings → Devices → Link Desktop Device)
|
|
58
|
+
tg login --phone # fallback: SMS code flow
|
|
59
|
+
tg me # verify
|
|
60
|
+
tg logout # remove the session
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
> **Note:** the session is independent — do not reuse the session string of
|
|
64
|
+
> another live client (e.g. an MCP daemon). Two live clients sharing one
|
|
65
|
+
> session trigger `AuthKeyDuplicatedError`.
|
|
66
|
+
|
|
67
|
+
## Commands
|
|
68
|
+
|
|
69
|
+
| Command | Description |
|
|
70
|
+
|---|---|
|
|
71
|
+
| `tg me` | Show your account info |
|
|
72
|
+
| `tg chats [keyword]` | List dialogs; `-t user/group/channel`, `-u` unread, `--archived` |
|
|
73
|
+
| `tg hist <chat> [n]` | Recent messages (default 10) |
|
|
74
|
+
| `tg send <chat> <text...>` | Send a message; `-p md/html` |
|
|
75
|
+
| `tg reply <chat> <msg_id> <text...>` | Reply to a message |
|
|
76
|
+
| `tg edit <chat> <msg_id> <new_text>` | Edit your own message |
|
|
77
|
+
| `tg del <chat> <ids...>` | Delete messages (revoke for both sides) |
|
|
78
|
+
| `tg fwd <src> <msg_ids...> <dst>` | Forward messages (last arg is the target) |
|
|
79
|
+
| `tg dl <chat> <msg_id> [-o path]` | Download media (default `~/Downloads/telegram_<chat>_<msgid>`) |
|
|
80
|
+
| `tg sf <chat> <files...> [-c caption]` | Send files; 2–10 files become an album |
|
|
81
|
+
| `tg voice <chat> <file>` | Send a voice note |
|
|
82
|
+
| `tg search <chat> <query>` | Search messages inside a chat |
|
|
83
|
+
| `tg gsearch <query> [-p page]` | Global search across public chats |
|
|
84
|
+
| `tg contacts` | List contacts |
|
|
85
|
+
| `tg pinned <chat>` | Show pinned messages |
|
|
86
|
+
| `tg poll <chat> "<question>" <opts...>` | Create a poll; `--multiple/--quiz/--public` |
|
|
87
|
+
| `tg profile --name/--bio/--photo` | Update your profile |
|
|
88
|
+
| `tg alias set/list/rm` | Local chat aliases (`~/.config/tg/aliases.json`) |
|
|
89
|
+
|
|
90
|
+
Global flags: `--account` (v1: default only), `--json` (raw JSON output).
|
|
91
|
+
Exit codes: `0` ok, `1` command error, `2` config/connection/session error,
|
|
92
|
+
`130` interrupted.
|
|
93
|
+
|
|
94
|
+
## FAQ
|
|
95
|
+
|
|
96
|
+
- **`AuthKeyDuplicatedError`** — two live clients share one session. Run
|
|
97
|
+
`tg logout` then `tg login --qr` to create a fresh one.
|
|
98
|
+
- **`FloodWaitError`** — Telegram rate limit; the CLI waits up to 60s
|
|
99
|
+
automatically, longer waits are reported.
|
|
100
|
+
- **"cannot reach Telegram"** — check the proxy (e.g. Clash on
|
|
101
|
+
`127.0.0.1:7890`) and `TELEGRAM_PROXY_*` in `.env`.
|
|
102
|
+
|
|
103
|
+
## Roadmap
|
|
104
|
+
|
|
105
|
+
See [ROADMAP.md](ROADMAP.md) for the full plan (messaging enhancements, chat &
|
|
106
|
+
group management, contacts, folders, multi-account, voice transcription).
|
|
107
|
+
|
|
108
|
+
## License & acknowledgments
|
|
109
|
+
|
|
110
|
+
[Apache-2.0](LICENSE). Proxy-injection approach, session-generation flow and
|
|
111
|
+
environment variable naming inspired by
|
|
112
|
+
[chigwell/telegram-mcp](https://github.com/chigwell/telegram-mcp)
|
|
113
|
+
(Apache-2.0).
|