telegram-tools 3.0.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.
Files changed (41) hide show
  1. telegram_tools-3.0.0/.env.example +6 -0
  2. telegram_tools-3.0.0/.github/ISSUE_TEMPLATE/bug_report.yml +47 -0
  3. telegram_tools-3.0.0/.github/ISSUE_TEMPLATE/config.yml +1 -0
  4. telegram_tools-3.0.0/.github/ISSUE_TEMPLATE/feature_request.yml +30 -0
  5. telegram_tools-3.0.0/.github/pull_request_template.md +16 -0
  6. telegram_tools-3.0.0/.github/workflows/tests.yml +49 -0
  7. telegram_tools-3.0.0/.gitignore +22 -0
  8. telegram_tools-3.0.0/CHANGELOG.md +32 -0
  9. telegram_tools-3.0.0/CODE_OF_CONDUCT.md +21 -0
  10. telegram_tools-3.0.0/CONTRIBUTING.md +60 -0
  11. telegram_tools-3.0.0/LICENSE +21 -0
  12. telegram_tools-3.0.0/PKG-INFO +156 -0
  13. telegram_tools-3.0.0/README.md +107 -0
  14. telegram_tools-3.0.0/SECURITY.md +31 -0
  15. telegram_tools-3.0.0/docs/telethon-api-notes.md +12 -0
  16. telegram_tools-3.0.0/pyproject.toml +50 -0
  17. telegram_tools-3.0.0/src/telegram_tools/__init__.py +5 -0
  18. telegram_tools-3.0.0/src/telegram_tools/cli.py +227 -0
  19. telegram_tools-3.0.0/src/telegram_tools/client.py +12 -0
  20. telegram_tools-3.0.0/src/telegram_tools/config.py +52 -0
  21. telegram_tools-3.0.0/src/telegram_tools/delete.py +95 -0
  22. telegram_tools-3.0.0/src/telegram_tools/discovery.py +138 -0
  23. telegram_tools-3.0.0/src/telegram_tools/doctor.py +69 -0
  24. telegram_tools-3.0.0/src/telegram_tools/exporters.py +30 -0
  25. telegram_tools-3.0.0/src/telegram_tools/models.py +54 -0
  26. telegram_tools-3.0.0/src/telegram_tools/records.py +82 -0
  27. telegram_tools-3.0.0/src/telegram_tools/resolver.py +59 -0
  28. telegram_tools-3.0.0/src/telegram_tools/search.py +81 -0
  29. telegram_tools-3.0.0/src/telegram_tools/topics.py +72 -0
  30. telegram_tools-3.0.0/tests/test_cli.py +105 -0
  31. telegram_tools-3.0.0/tests/test_cli_resolution.py +94 -0
  32. telegram_tools-3.0.0/tests/test_config.py +94 -0
  33. telegram_tools-3.0.0/tests/test_delete.py +131 -0
  34. telegram_tools-3.0.0/tests/test_discovery.py +89 -0
  35. telegram_tools-3.0.0/tests/test_doctor.py +78 -0
  36. telegram_tools-3.0.0/tests/test_exporters.py +25 -0
  37. telegram_tools-3.0.0/tests/test_menu.py +50 -0
  38. telegram_tools-3.0.0/tests/test_records.py +67 -0
  39. telegram_tools-3.0.0/tests/test_resolver.py +86 -0
  40. telegram_tools-3.0.0/tests/test_search.py +99 -0
  41. telegram_tools-3.0.0/tests/test_topics.py +19 -0
@@ -0,0 +1,6 @@
1
+ TELEGRAM_API_ID=123456
2
+ TELEGRAM_API_HASH=replace-with-your-api-hash
3
+
4
+ # Optional: override where the Telethon session file is stored.
5
+ # Default: ~/.telegram-tools/telegram-tools.session
6
+ #TELEGRAM_TOOLS_SESSION=/path/to/session
@@ -0,0 +1,47 @@
1
+ name: Bug report
2
+ description: Report a reproducible problem.
3
+ title: "[Bug]: "
4
+ labels: ["bug"]
5
+ body:
6
+ - type: markdown
7
+ attributes:
8
+ value: |
9
+ Do not include Telegram API hashes, bot tokens, phone numbers, session files, `.env`, private exports, or screenshots with private chat data.
10
+ - type: textarea
11
+ id: summary
12
+ attributes:
13
+ label: Summary
14
+ description: What went wrong?
15
+ validations:
16
+ required: true
17
+ - type: textarea
18
+ id: steps
19
+ attributes:
20
+ label: Reproduction
21
+ description: Commands and sanitized inputs that reproduce the issue.
22
+ placeholder: |
23
+ telegram-tools search --chat @example_group --contains deploy
24
+ validations:
25
+ required: true
26
+ - type: textarea
27
+ id: expected
28
+ attributes:
29
+ label: Expected behavior
30
+ validations:
31
+ required: true
32
+ - type: textarea
33
+ id: actual
34
+ attributes:
35
+ label: Actual behavior
36
+ validations:
37
+ required: true
38
+ - type: input
39
+ id: version
40
+ attributes:
41
+ label: Version or commit
42
+ placeholder: "2.0.1 or commit SHA"
43
+ - type: textarea
44
+ id: validation
45
+ attributes:
46
+ label: Validation output
47
+ description: Paste sanitized `python -m pytest` or `telegram-tools doctor` output if relevant.
@@ -0,0 +1 @@
1
+ blank_issues_enabled: false
@@ -0,0 +1,30 @@
1
+ name: Feature request
2
+ description: Suggest a focused improvement.
3
+ title: "[Feature]: "
4
+ labels: ["enhancement"]
5
+ body:
6
+ - type: markdown
7
+ attributes:
8
+ value: |
9
+ Keep requests focused. Do not include credentials, private chat data, phone numbers, `.env`, or session files.
10
+ - type: textarea
11
+ id: problem
12
+ attributes:
13
+ label: Problem
14
+ description: What workflow is hard or missing?
15
+ validations:
16
+ required: true
17
+ - type: textarea
18
+ id: proposal
19
+ attributes:
20
+ label: Proposed solution
21
+ description: What should change?
22
+ validations:
23
+ required: true
24
+ - type: textarea
25
+ id: safety
26
+ attributes:
27
+ label: Safety impact
28
+ description: Does this touch message deletion, credentials, sessions, or exports?
29
+ validations:
30
+ required: true
@@ -0,0 +1,16 @@
1
+ ## Summary
2
+
3
+ - Summary of changes.
4
+
5
+ ## Safety
6
+
7
+ - [ ] I did not include Telegram API hashes, bot tokens, phone numbers, `.env`, session files, or private exports.
8
+ - [ ] I did not make destructive Telegram operations easier to run accidentally.
9
+ - [ ] If I touched `clear-messages`, dry-run, `--execute`, typed `DELETE`, topic preservation, and topic ID preservation are covered by tests.
10
+
11
+ ## Validation
12
+
13
+ - [ ] `python -m pytest`
14
+ - [ ] `python -m compileall -q src`
15
+ - [ ] `telegram-tools --help`
16
+ - [ ] `telegram-tools doctor` if local Telegram config is available
@@ -0,0 +1,49 @@
1
+ name: Tests
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ pull_request:
8
+
9
+ jobs:
10
+ test:
11
+ name: Python ${{ matrix.python-version }}
12
+ runs-on: macos-latest
13
+ strategy:
14
+ fail-fast: false
15
+ matrix:
16
+ python-version:
17
+ - "3.11"
18
+ - "3.12"
19
+ - "3.13"
20
+ - "3.14"
21
+
22
+ steps:
23
+ - name: Check out repository
24
+ uses: actions/checkout@v4
25
+
26
+ - name: Set up Python
27
+ uses: actions/setup-python@v5
28
+ with:
29
+ python-version: ${{ matrix.python-version }}
30
+ cache: pip
31
+
32
+ - name: Install package
33
+ run: |
34
+ python -m pip install --upgrade pip
35
+ python -m pip install -e ".[dev]"
36
+
37
+ - name: Run tests
38
+ run: python -m pytest
39
+
40
+ - name: Compile sources
41
+ run: python -m compileall -q src
42
+
43
+ - name: Check CLI help
44
+ run: |
45
+ telegram-tools --help
46
+ telegram-tools discover --help
47
+ telegram-tools clear-messages --help
48
+ telegram-tools search --help
49
+ telegram-tools doctor --help
@@ -0,0 +1,22 @@
1
+ .DS_Store
2
+ .venv/
3
+ __pycache__/
4
+ .pytest_cache/
5
+ .ruff_cache/
6
+ .mypy_cache/
7
+ *.egg-info/
8
+ dist/
9
+ build/
10
+
11
+ .env
12
+ .env.*
13
+ !.env.example
14
+
15
+ .telegram-tools/
16
+ *.session
17
+ *.session-journal
18
+ *.session-shm
19
+ *.session-wal
20
+
21
+ exports/
22
+ *.log
@@ -0,0 +1,32 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented here.
4
+
5
+ This project follows a practical changelog style: user-visible changes, safety changes, and release notes belong here; active task tracking belongs outside the repo.
6
+
7
+ ## 3.0.0 - 2026-08-12
8
+
9
+ First PyPI release. Curated to three tools: discovery, search/export, and clear-messages.
10
+
11
+ - **Breaking:** remove `bot-inventory` and `bot-add` (and `bots.json` support).
12
+ - **Breaking:** remove the macOS `.command` launchers — install with `pipx install telegram-tools` instead.
13
+ - **Breaking:** session files and config now default to `~/.telegram-tools/` instead of the current directory. Migrate an existing login with `mv .telegram-tools ~/.telegram-tools` (and move your `.env` values into `~/.telegram-tools/.env` if you want them global). `TELEGRAM_TOOLS_SESSION` still overrides.
14
+ - `.env` is now also read from `~/.telegram-tools/.env` (current directory still wins).
15
+ - Rewrite README for the PyPI audience, including an api_id/api_hash setup walkthrough.
16
+
17
+ ## 2.0.1 - 2026-07-06
18
+
19
+ - Add public-readiness documentation: license, contributing guide, security policy, code of conduct, issue templates, and pull request template.
20
+ - Add GitHub Actions test workflow.
21
+ - Add `telegram-tools doctor` for local setup checks that do not print secrets, token values, or session paths.
22
+ - Replace machine-specific launcher paths with repository-relative path resolution.
23
+ - Expand package metadata for public packaging.
24
+
25
+ ## 0.1.0 - 2026-07-06
26
+
27
+ - Add interactive menu.
28
+ - Add chat/topic discovery.
29
+ - Add message search and JSON/CSV export.
30
+ - Add dry-run-first clear-message workflow that preserves forum topics and topic IDs.
31
+ - Add bot inventory and bot-add commands with masked token output.
32
+ - Add clickable macOS `.command` launchers.
@@ -0,0 +1,21 @@
1
+ # Code of Conduct
2
+
3
+ ## Expected Behavior
4
+
5
+ - Be direct, respectful, and specific.
6
+ - Assume good intent, but accept correction when impact says otherwise.
7
+ - Keep discussion focused on the code, docs, safety, and user outcomes.
8
+ - Do not post private data, credentials, or screenshots that expose other people.
9
+
10
+ ## Unacceptable Behavior
11
+
12
+ - Harassment, threats, or personal attacks.
13
+ - Discriminatory language or conduct.
14
+ - Publishing private information without consent.
15
+ - Repeated bad-faith arguments that block maintainers from doing the work.
16
+
17
+ ## Enforcement
18
+
19
+ Maintainers may edit, hide, or remove comments and may block participants who violate this code of conduct.
20
+
21
+ Report problems privately through the repository owner's GitHub profile or security advisory channel.
@@ -0,0 +1,60 @@
1
+ # Contributing
2
+
3
+ Thanks for helping improve `telegram-tools`.
4
+
5
+ ## Safety First
6
+
7
+ Do not include any real Telegram credentials or private chat data in issues, pull requests, commits, tests, screenshots, fixtures, or logs.
8
+
9
+ Never commit:
10
+
11
+ - `.env`
12
+ - `.telegram-tools/`
13
+ - `*.session*`
14
+ - phone numbers
15
+ - Telegram API hashes
16
+ - bot tokens
17
+ - exported private chat data
18
+
19
+ ## Development Setup
20
+
21
+ ```bash
22
+ python3.11 -m venv .venv
23
+ source .venv/bin/activate
24
+ python -m pip install -e ".[dev]"
25
+ ```
26
+
27
+ ## Validation
28
+
29
+ Run the full local check before opening a pull request:
30
+
31
+ ```bash
32
+ python -m pytest
33
+ python -m compileall -q src
34
+ telegram-tools --help
35
+ telegram-tools discover --help
36
+ telegram-tools clear-messages --help
37
+ telegram-tools search --help
38
+ telegram-tools doctor --help
39
+ ```
40
+
41
+ If you have local Telegram config and session storage, also run:
42
+
43
+ ```bash
44
+ telegram-tools doctor
45
+ ```
46
+
47
+ ## Clear-Message Changes
48
+
49
+ Be especially conservative around `clear-messages`.
50
+
51
+ The required behavior is:
52
+
53
+ - dry-run by default.
54
+ - `--execute` is required before Telegram deletion APIs are called.
55
+ - a typed `DELETE` prompt is required during execution.
56
+ - forum topics are not deleted.
57
+ - topic IDs do not change.
58
+ - only messages collected from the selected chat/topic are deleted.
59
+
60
+ Add or update tests for any change touching that flow.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 telegram-tools contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,156 @@
1
+ Metadata-Version: 2.5
2
+ Name: telegram-tools
3
+ Version: 3.0.0
4
+ Summary: Local Telethon CLI for Telegram chat/topic ID discovery, message search/export, and topic message clearing.
5
+ Project-URL: Homepage, https://github.com/banozz0/telegram-tools
6
+ Project-URL: Repository, https://github.com/banozz0/telegram-tools
7
+ Project-URL: Issues, https://github.com/banozz0/telegram-tools/issues
8
+ Project-URL: Changelog, https://github.com/banozz0/telegram-tools/blob/main/CHANGELOG.md
9
+ License: MIT License
10
+
11
+ Copyright (c) 2026 telegram-tools contributors
12
+
13
+ Permission is hereby granted, free of charge, to any person obtaining a copy
14
+ of this software and associated documentation files (the "Software"), to deal
15
+ in the Software without restriction, including without limitation the rights
16
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
+ copies of the Software, and to permit persons to whom the Software is
18
+ furnished to do so, subject to the following conditions:
19
+
20
+ The above copyright notice and this permission notice shall be included in all
21
+ copies or substantial portions of the Software.
22
+
23
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
+ SOFTWARE.
30
+ License-File: LICENSE
31
+ Keywords: cli,export,forum-topics,telegram,telethon
32
+ Classifier: Development Status :: 4 - Beta
33
+ Classifier: Environment :: Console
34
+ Classifier: Intended Audience :: End Users/Desktop
35
+ Classifier: License :: OSI Approved :: MIT License
36
+ Classifier: Programming Language :: Python :: 3
37
+ Classifier: Programming Language :: Python :: 3.11
38
+ Classifier: Programming Language :: Python :: 3.12
39
+ Classifier: Programming Language :: Python :: 3.13
40
+ Classifier: Programming Language :: Python :: 3.14
41
+ Classifier: Topic :: Communications :: Chat
42
+ Classifier: Topic :: Utilities
43
+ Requires-Python: >=3.11
44
+ Requires-Dist: python-dotenv<2,>=1.0
45
+ Requires-Dist: telethon<2,>=1.44
46
+ Provides-Extra: dev
47
+ Requires-Dist: pytest>=8.0; extra == 'dev'
48
+ Description-Content-Type: text/markdown
49
+
50
+ # telegram-tools
51
+
52
+ A local CLI for operating your own Telegram chats: find the real IDs of your groups, channels, and forum topics, search and export messages, and clear all messages out of forum topics without destroying the topics themselves.
53
+
54
+ Built on [Telethon](https://github.com/LonamiWebs/Telethon). Everything runs on your machine with your own Telegram API credentials — no server, no third party, nothing leaves your computer except the Telegram API calls you asked for.
55
+
56
+ ## What it does
57
+
58
+ - **`discover`** — lists your chats, channels, and forum groups with their exact numeric IDs and every forum topic ID. The fastest way to answer "what is this chat's `-100…` ID and what are its topic IDs?"
59
+ - **`search`** — searches messages by text, sender, date range, or topic, and prints a table or exports JSON/CSV.
60
+ - **`clear-messages`** — deletes all messages inside selected forum topic(s) while preserving the topics and their IDs. Dry-run by default; deleting requires both `--execute` *and* typing `DELETE` at a prompt.
61
+ - **`doctor`** — checks your local setup without printing any secrets.
62
+
63
+ ## What it doesn't do (on purpose)
64
+
65
+ - No deleting or creating forum topics — topic IDs never change.
66
+ - No media downloads.
67
+ - No sending messages, no bots, no automation loops.
68
+ - No cloud anything — credentials and session files stay in `~/.telegram-tools/`.
69
+
70
+ ## Install
71
+
72
+ ```bash
73
+ pipx install telegram-tools
74
+ # or
75
+ uv tool install telegram-tools
76
+ ```
77
+
78
+ Or from source: `pipx install git+https://github.com/banozz0/telegram-tools.git`
79
+
80
+ Requires Python 3.11+.
81
+
82
+ ## Setup: your Telegram API credentials
83
+
84
+ The tool logs in as *you* (a user account, not a bot), so it needs a Telegram API key. One-time, about two minutes:
85
+
86
+ 1. Open <https://my.telegram.org/apps> and log in with your Telegram phone number.
87
+ 2. Fill in the short "Create new application" form (any name/short name works; platform "Desktop").
88
+ 3. Copy the **App api_id** (a number) and **App api_hash** (a hex string).
89
+ 4. Store them where the tool can find them:
90
+
91
+ ```bash
92
+ mkdir -p ~/.telegram-tools
93
+ cat > ~/.telegram-tools/.env <<'EOF'
94
+ TELEGRAM_API_ID=123456
95
+ TELEGRAM_API_HASH=your-api-hash-here
96
+ EOF
97
+ ```
98
+
99
+ Shell environment variables and a `.env` in the current directory also work, and win over `~/.telegram-tools/.env`.
100
+
101
+ Treat the api_hash like a password. The first command you run starts Telethon's interactive login (phone number + code from Telegram); the resulting session file is stored in `~/.telegram-tools/` and reused afterwards. Log out anytime by deleting the session file in that directory (your `.env` can stay) — the session also shows under Telegram's *Settings → Devices*.
102
+
103
+ ## 30 seconds of usage
104
+
105
+ ```bash
106
+ # What are my chats and their IDs?
107
+ telegram-tools discover # admin/managed chats only
108
+ telegram-tools discover --all # everything
109
+
110
+ # Search a group
111
+ telegram-tools search --chat @mygroup --contains deploy
112
+
113
+ # Export a topic to JSON
114
+ telegram-tools search --chat @mygroup --topic 141 --output topic-141.json
115
+
116
+ # Clear a topic (dry-run first — this is the default)
117
+ telegram-tools clear-messages --chat @mygroup --topic 141
118
+ # Actually delete: needs --execute AND typing DELETE at the prompt
119
+ telegram-tools clear-messages --chat @mygroup --topic 141 --execute
120
+ ```
121
+
122
+ Running `telegram-tools` with no arguments opens an interactive menu with the same operations.
123
+
124
+ `discover` output looks like:
125
+
126
+ ```text
127
+ Forum Groups
128
+ ============
129
+ Example Forum
130
+ Chat ID: -1001234567890
131
+ Type: Forum Group
132
+ Admin: yes
133
+
134
+ Topics
135
+ --------------------------------------------
136
+ 141 Deploys
137
+ 217 Support
138
+ 16 General
139
+ ```
140
+
141
+ ## Safety model
142
+
143
+ | Command | Destructive? |
144
+ | --- | --- |
145
+ | `discover`, `search`, `doctor` | No — read-only |
146
+ | `clear-messages` | Yes — but only with `--execute` **and** a typed `DELETE`, only messages, never topics |
147
+
148
+ `clear-messages` also verifies you actually hold the delete-messages permission in the chat before doing anything, skips topic starter messages, and handles Telegram flood-wait limits automatically.
149
+
150
+ ## Status
151
+
152
+ Stable for its three jobs; used regularly by its author. This is a solo project whose code was written by AI agents under review — issues are welcome, fixes are best-effort, and there is no support promise.
153
+
154
+ ## License
155
+
156
+ MIT. See [LICENSE](LICENSE).
@@ -0,0 +1,107 @@
1
+ # telegram-tools
2
+
3
+ A local CLI for operating your own Telegram chats: find the real IDs of your groups, channels, and forum topics, search and export messages, and clear all messages out of forum topics without destroying the topics themselves.
4
+
5
+ Built on [Telethon](https://github.com/LonamiWebs/Telethon). Everything runs on your machine with your own Telegram API credentials — no server, no third party, nothing leaves your computer except the Telegram API calls you asked for.
6
+
7
+ ## What it does
8
+
9
+ - **`discover`** — lists your chats, channels, and forum groups with their exact numeric IDs and every forum topic ID. The fastest way to answer "what is this chat's `-100…` ID and what are its topic IDs?"
10
+ - **`search`** — searches messages by text, sender, date range, or topic, and prints a table or exports JSON/CSV.
11
+ - **`clear-messages`** — deletes all messages inside selected forum topic(s) while preserving the topics and their IDs. Dry-run by default; deleting requires both `--execute` *and* typing `DELETE` at a prompt.
12
+ - **`doctor`** — checks your local setup without printing any secrets.
13
+
14
+ ## What it doesn't do (on purpose)
15
+
16
+ - No deleting or creating forum topics — topic IDs never change.
17
+ - No media downloads.
18
+ - No sending messages, no bots, no automation loops.
19
+ - No cloud anything — credentials and session files stay in `~/.telegram-tools/`.
20
+
21
+ ## Install
22
+
23
+ ```bash
24
+ pipx install telegram-tools
25
+ # or
26
+ uv tool install telegram-tools
27
+ ```
28
+
29
+ Or from source: `pipx install git+https://github.com/banozz0/telegram-tools.git`
30
+
31
+ Requires Python 3.11+.
32
+
33
+ ## Setup: your Telegram API credentials
34
+
35
+ The tool logs in as *you* (a user account, not a bot), so it needs a Telegram API key. One-time, about two minutes:
36
+
37
+ 1. Open <https://my.telegram.org/apps> and log in with your Telegram phone number.
38
+ 2. Fill in the short "Create new application" form (any name/short name works; platform "Desktop").
39
+ 3. Copy the **App api_id** (a number) and **App api_hash** (a hex string).
40
+ 4. Store them where the tool can find them:
41
+
42
+ ```bash
43
+ mkdir -p ~/.telegram-tools
44
+ cat > ~/.telegram-tools/.env <<'EOF'
45
+ TELEGRAM_API_ID=123456
46
+ TELEGRAM_API_HASH=your-api-hash-here
47
+ EOF
48
+ ```
49
+
50
+ Shell environment variables and a `.env` in the current directory also work, and win over `~/.telegram-tools/.env`.
51
+
52
+ Treat the api_hash like a password. The first command you run starts Telethon's interactive login (phone number + code from Telegram); the resulting session file is stored in `~/.telegram-tools/` and reused afterwards. Log out anytime by deleting the session file in that directory (your `.env` can stay) — the session also shows under Telegram's *Settings → Devices*.
53
+
54
+ ## 30 seconds of usage
55
+
56
+ ```bash
57
+ # What are my chats and their IDs?
58
+ telegram-tools discover # admin/managed chats only
59
+ telegram-tools discover --all # everything
60
+
61
+ # Search a group
62
+ telegram-tools search --chat @mygroup --contains deploy
63
+
64
+ # Export a topic to JSON
65
+ telegram-tools search --chat @mygroup --topic 141 --output topic-141.json
66
+
67
+ # Clear a topic (dry-run first — this is the default)
68
+ telegram-tools clear-messages --chat @mygroup --topic 141
69
+ # Actually delete: needs --execute AND typing DELETE at the prompt
70
+ telegram-tools clear-messages --chat @mygroup --topic 141 --execute
71
+ ```
72
+
73
+ Running `telegram-tools` with no arguments opens an interactive menu with the same operations.
74
+
75
+ `discover` output looks like:
76
+
77
+ ```text
78
+ Forum Groups
79
+ ============
80
+ Example Forum
81
+ Chat ID: -1001234567890
82
+ Type: Forum Group
83
+ Admin: yes
84
+
85
+ Topics
86
+ --------------------------------------------
87
+ 141 Deploys
88
+ 217 Support
89
+ 16 General
90
+ ```
91
+
92
+ ## Safety model
93
+
94
+ | Command | Destructive? |
95
+ | --- | --- |
96
+ | `discover`, `search`, `doctor` | No — read-only |
97
+ | `clear-messages` | Yes — but only with `--execute` **and** a typed `DELETE`, only messages, never topics |
98
+
99
+ `clear-messages` also verifies you actually hold the delete-messages permission in the chat before doing anything, skips topic starter messages, and handles Telegram flood-wait limits automatically.
100
+
101
+ ## Status
102
+
103
+ Stable for its three jobs; used regularly by its author. This is a solo project whose code was written by AI agents under review — issues are welcome, fixes are best-effort, and there is no support promise.
104
+
105
+ ## License
106
+
107
+ MIT. See [LICENSE](LICENSE).
@@ -0,0 +1,31 @@
1
+ # Security Policy
2
+
3
+ ## Reporting Security Issues
4
+
5
+ Please do not open public issues for vulnerabilities or accidental secret exposure.
6
+
7
+ Report privately through GitHub security advisories for this repository, or contact the maintainer through a private channel listed on the repository owner profile.
8
+
9
+ ## Sensitive Data
10
+
11
+ Do not include:
12
+
13
+ - Telegram API hashes
14
+ - bot tokens
15
+ - phone numbers
16
+ - `.env`
17
+ - `.telegram-tools/`
18
+ - `*.session*`
19
+ - exported private chat data
20
+ - screenshots that expose private chat names, members, phone numbers, or tokens
21
+
22
+ If you accidentally expose a secret, revoke or rotate it before reporting.
23
+
24
+ ## Supported Versions
25
+
26
+ Security fixes target the latest public release line.
27
+
28
+ | Version | Supported |
29
+ | --- | --- |
30
+ | 3.x | Yes |
31
+ | Earlier private/pre-public snapshots | No |
@@ -0,0 +1,12 @@
1
+ # Telethon API Notes
2
+
3
+ Checked on 2026-07-06 before implementation.
4
+
5
+ - Current stable release checked from PyPI: Telethon 1.44.0, released 2026-06-15.
6
+ - Telethon sessions are local SQLite files by default and contain enough authorization data to reuse the login. This project stores them under `~/.telegram-tools/`, outside any repository.
7
+ - `TelegramClient.iter_dialogs()` is the high-level API for listing open dialogs.
8
+ - `TelegramClient.get_permissions(entity, user)` returns `ParticipantPermissions`; `is_admin` indicates admin/creator status.
9
+ - `TelegramClient.iter_messages()` supports chat search through `search`, sender filtering through `from_user`, and thread/topic traversal through `reply_to`.
10
+ - Telethon documents that `search` and `filter` have no effect with `reply_to`, so topic-scoped keyword search is implemented by iterating the topic and filtering locally.
11
+ - `TelegramClient.delete_messages(entity, message_ids)` chunks IDs internally, but it does not validate that message IDs belong to the passed chat. This project only deletes IDs collected from the selected chat/topic in the same process.
12
+ - Forum topic listing requires raw API support. In the Telethon 1.44.0 wheel, the relevant request class is `telethon.tl.functions.messages.GetForumTopicsRequest`.
@@ -0,0 +1,50 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.25"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "telegram-tools"
7
+ version = "3.0.0"
8
+ description = "Local Telethon CLI for Telegram chat/topic ID discovery, message search/export, and topic message clearing."
9
+ readme = "README.md"
10
+ requires-python = ">=3.11"
11
+ license = { file = "LICENSE" }
12
+ keywords = ["telegram", "telethon", "cli", "forum-topics", "export"]
13
+ classifiers = [
14
+ "Development Status :: 4 - Beta",
15
+ "Environment :: Console",
16
+ "Intended Audience :: End Users/Desktop",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Programming Language :: Python :: 3",
19
+ "Programming Language :: Python :: 3.11",
20
+ "Programming Language :: Python :: 3.12",
21
+ "Programming Language :: Python :: 3.13",
22
+ "Programming Language :: Python :: 3.14",
23
+ "Topic :: Communications :: Chat",
24
+ "Topic :: Utilities",
25
+ ]
26
+ dependencies = [
27
+ "Telethon>=1.44,<2",
28
+ "python-dotenv>=1.0,<2",
29
+ ]
30
+
31
+ [project.optional-dependencies]
32
+ dev = [
33
+ "pytest>=8.0",
34
+ ]
35
+
36
+ [project.scripts]
37
+ telegram-tools = "telegram_tools.cli:main"
38
+
39
+ [project.urls]
40
+ Homepage = "https://github.com/banozz0/telegram-tools"
41
+ Repository = "https://github.com/banozz0/telegram-tools"
42
+ Issues = "https://github.com/banozz0/telegram-tools/issues"
43
+ Changelog = "https://github.com/banozz0/telegram-tools/blob/main/CHANGELOG.md"
44
+
45
+ [tool.hatch.build.targets.wheel]
46
+ packages = ["src/telegram_tools"]
47
+
48
+ [tool.pytest.ini_options]
49
+ testpaths = ["tests"]
50
+ pythonpath = ["src"]