python-telegram 0.18.0__tar.gz → 2.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.
- python_telegram-2.0.0/.gitignore +13 -0
- python_telegram-2.0.0/CONTRIBUTING.md +80 -0
- python_telegram-2.0.0/PKG-INFO +156 -0
- python_telegram-2.0.0/README.md +129 -0
- {python-telegram-0.18.0 → python_telegram-2.0.0}/docs/requirements.txt +1 -0
- python_telegram-2.0.0/docs/source/changelog.rst +176 -0
- {python-telegram-0.18.0 → python_telegram-2.0.0}/docs/source/conf.py +38 -66
- python_telegram-2.0.0/docs/source/index.rst +118 -0
- python_telegram-2.0.0/docs/source/non_blocking_login.rst +64 -0
- {python-telegram-0.18.0 → python_telegram-2.0.0}/docs/source/proxy.rst +5 -6
- {python-telegram-0.18.0 → python_telegram-2.0.0}/docs/source/tdlib.rst +1 -2
- python_telegram-2.0.0/docs/source/tutorial.rst +130 -0
- python_telegram-2.0.0/hatch_build.py +104 -0
- python_telegram-2.0.0/pyproject.toml +64 -0
- {python-telegram-0.18.0 → python_telegram-2.0.0}/telegram/__init__.py +1 -1
- python_telegram-2.0.0/telegram/client.py +1101 -0
- python_telegram-2.0.0/telegram/py.typed +0 -0
- python_telegram-2.0.0/telegram/tdjson.py +185 -0
- {python-telegram-0.18.0 → python_telegram-2.0.0}/telegram/text.py +19 -19
- {python-telegram-0.18.0 → python_telegram-2.0.0}/telegram/utils.py +19 -17
- {python-telegram-0.18.0 → python_telegram-2.0.0}/telegram/worker.py +7 -5
- python-telegram-0.18.0/CONTRIBUTING.md +0 -44
- python-telegram-0.18.0/MANIFEST.in +0 -11
- python-telegram-0.18.0/PKG-INFO +0 -87
- python-telegram-0.18.0/README.md +0 -77
- python-telegram-0.18.0/docs/source/_templates/about.html +0 -57
- python-telegram-0.18.0/docs/source/_templates/navigation.html +0 -13
- python-telegram-0.18.0/docs/source/changelog.rst +0 -130
- python-telegram-0.18.0/docs/source/index.rst +0 -76
- python-telegram-0.18.0/docs/source/modules.rst +0 -7
- python-telegram-0.18.0/docs/source/non_blocking_login.rst +0 -54
- python-telegram-0.18.0/docs/source/tutorial.rst +0 -122
- python-telegram-0.18.0/pyproject.toml +0 -8
- python-telegram-0.18.0/python_telegram.egg-info/PKG-INFO +0 -87
- python-telegram-0.18.0/python_telegram.egg-info/SOURCES.txt +0 -33
- python-telegram-0.18.0/python_telegram.egg-info/dependency_links.txt +0 -1
- python-telegram-0.18.0/python_telegram.egg-info/requires.txt +0 -1
- python-telegram-0.18.0/python_telegram.egg-info/top_level.txt +0 -1
- python-telegram-0.18.0/setup.cfg +0 -10
- python-telegram-0.18.0/setup.py +0 -40
- python-telegram-0.18.0/telegram/client.py +0 -895
- python-telegram-0.18.0/telegram/lib/darwin/libtdjson.dylib +0 -0
- python-telegram-0.18.0/telegram/lib/linux/libtdjson.so +0 -0
- python-telegram-0.18.0/telegram/tdjson.py +0 -120
- {python-telegram-0.18.0 → python_telegram-2.0.0}/LICENSE +0 -0
- {python-telegram-0.18.0 → python_telegram-2.0.0}/docs/Makefile +0 -0
- {python-telegram-0.18.0 → python_telegram-2.0.0}/docs/source/telegram.rst +0 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
Pull requests are welcome!
|
|
4
|
+
|
|
5
|
+
Feel free to open an issue if you find a bug, have new ideas, suggestions,
|
|
6
|
+
or spot a mistake in the [documentation](https://python-telegram.readthedocs.io/latest/).
|
|
7
|
+
|
|
8
|
+
## Reporting bugs
|
|
9
|
+
|
|
10
|
+
We use [GitHub
|
|
11
|
+
Issues](https://github.com/alexander-akhmetov/python-telegram/issues) to track
|
|
12
|
+
bugs. If you find a bug, please open a new issue.
|
|
13
|
+
|
|
14
|
+
Try to include steps to reproduce the bug, a detailed description, and some sample code if possible.
|
|
15
|
+
|
|
16
|
+
## Pull request process
|
|
17
|
+
|
|
18
|
+
1. Fork the repository and create a new branch from `main`.
|
|
19
|
+
2. Make your changes and don't forget to add new tests :)
|
|
20
|
+
3. Ensure the tests pass with your changes.
|
|
21
|
+
4. Create a new PR!
|
|
22
|
+
|
|
23
|
+
## Coding style
|
|
24
|
+
|
|
25
|
+
The project uses [ruff](https://docs.astral.sh/ruff/) as an autoformatter and linter.
|
|
26
|
+
|
|
27
|
+
## Tests
|
|
28
|
+
|
|
29
|
+
To run tests you need to install [tox](https://tox.wiki/).
|
|
30
|
+
|
|
31
|
+
Run tests:
|
|
32
|
+
|
|
33
|
+
```shell
|
|
34
|
+
tox
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Run a specific test using python 3.12:
|
|
38
|
+
|
|
39
|
+
```shell
|
|
40
|
+
tox -e py312 -- -k test_add_message_handler
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
`tests/test_tdlib_binary.py` loads a real `tdlib` and skips when it cannot find one, so a
|
|
44
|
+
checkout with no system `tdlib` still runs a green suite.
|
|
45
|
+
|
|
46
|
+
## tdlib binaries
|
|
47
|
+
|
|
48
|
+
The binaries are not in this repository. They are built in
|
|
49
|
+
[tdlib-compiled](https://github.com/alexander-akhmetov/tdlib-compiled), which publishes one
|
|
50
|
+
per platform as a release with a `SHA256SUMS` and a `BUILD-INFO.json`.
|
|
51
|
+
|
|
52
|
+
`tdlib.lock` pins that release tag, the asset names, the wheel platform tags and the sha256
|
|
53
|
+
of each asset. Bumping tdlib is a PR that changes only that file: copy the tag, the digests
|
|
54
|
+
and the `wheel_platform` values out of the new release's `BUILD-INFO.json`, so the lock
|
|
55
|
+
always describes bytes that exist.
|
|
56
|
+
|
|
57
|
+
To build one platform wheel yourself, download the asset for your target and run:
|
|
58
|
+
|
|
59
|
+
```shell
|
|
60
|
+
PYTHON_TELEGRAM_TDLIB_TARGET=macos-arm64 PYTHON_TELEGRAM_TDLIB_DIR=tdlib python -m build --wheel
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
With no `PYTHON_TELEGRAM_TDLIB_TARGET` the build produces a binary-free pure wheel, which is
|
|
64
|
+
what `pip install -e .` needs.
|
|
65
|
+
|
|
66
|
+
`make docker/build` installs the released PyPI version, not your working tree.
|
|
67
|
+
|
|
68
|
+
## Release checklist
|
|
69
|
+
|
|
70
|
+
1. Bump `__version__` in `telegram/__init__.py` and write the changelog entry.
|
|
71
|
+
2. Tag a release candidate first, for example `1.1.0rc1`. The tag pattern matches it and
|
|
72
|
+
PyPI does not serve a prerelease by default, so it exercises all four wheels, the four
|
|
73
|
+
verification runners, the attestation and trusted publishing with a version nobody
|
|
74
|
+
installs by accident.
|
|
75
|
+
3. Install the release candidate wheel and run `examples/echo_bot.py` against a bot token,
|
|
76
|
+
on macOS arm64 and on Linux. Watch the full
|
|
77
|
+
`NONE -> WAIT_TDLIB_PARAMETERS -> WAIT_PHONE_NUMBER -> READY` sequence. This is the only
|
|
78
|
+
check that covers the login request payloads; the smoke test cannot, because they need a
|
|
79
|
+
live session.
|
|
80
|
+
4. Tag the final version.
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: python-telegram
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: Python library to help you build your own Telegram clients
|
|
5
|
+
Project-URL: Source, https://github.com/alexander-akhmetov/python-telegram
|
|
6
|
+
Project-URL: Documentation, https://python-telegram.readthedocs.io/latest/
|
|
7
|
+
Project-URL: Tutorial, https://python-telegram.readthedocs.io/latest/tutorial.html
|
|
8
|
+
Project-URL: Changelog, https://python-telegram.readthedocs.io/latest/changelog.html
|
|
9
|
+
Author-email: Alexander Akhmetov <me@alx.cx>
|
|
10
|
+
License: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: api,client,td,tdjson,tdlib,telegram
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: MacOS :: MacOS X
|
|
16
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
17
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
|
+
Requires-Python: >=3.10
|
|
25
|
+
Requires-Dist: telegram-text==0.2.0
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# python-telegram
|
|
29
|
+
|
|
30
|
+
[](https://github.com/alexander-akhmetov/python-telegram/actions)
|
|
31
|
+
[](https://pypi.python.org/pypi/python-telegram)
|
|
32
|
+
[](https://python-telegram.readthedocs.io/latest/)
|
|
33
|
+
|
|
34
|
+
Python API for the [tdlib](https://github.com/tdlib/td) library.
|
|
35
|
+
It helps you build your own Telegram clients.
|
|
36
|
+
|
|
37
|
+
`tdlib` connects to Telegram over MTProto, the same protocol the official apps use.
|
|
38
|
+
This library signs in as a full Telegram account with a phone number, and it can do what a regular client can do.
|
|
39
|
+
|
|
40
|
+
It is not a wrapper around the HTTP Bot API.
|
|
41
|
+
If you only need a bot, [python-telegram-bot](https://github.com/python-telegram-bot/python-telegram-bot) is a better fit.
|
|
42
|
+
You can still sign in as a bot here by passing `bot_token` instead of `phone`.
|
|
43
|
+
|
|
44
|
+
- [Changelog](https://python-telegram.readthedocs.io/latest/changelog.html)
|
|
45
|
+
- [Documentation](https://python-telegram.readthedocs.io/latest/)
|
|
46
|
+
- [Tutorial](https://python-telegram.readthedocs.io/latest/tutorial.html)
|
|
47
|
+
|
|
48
|
+
## Installation
|
|
49
|
+
|
|
50
|
+
This library requires Python 3.10+. Windows is not supported.
|
|
51
|
+
|
|
52
|
+
```shell
|
|
53
|
+
pip install python-telegram
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
See [documentation](https://python-telegram.readthedocs.io/latest/#installation) for more details.
|
|
57
|
+
|
|
58
|
+
### tdlib
|
|
59
|
+
|
|
60
|
+
Four wheels bundle a `tdlib` binary. Each one works on Python 3.10 through 3.14:
|
|
61
|
+
|
|
62
|
+
| Platform | Wheel | Needs at least |
|
|
63
|
+
| --- | --- | --- |
|
|
64
|
+
| Linux x86_64 | `manylinux_2_28_x86_64` | glibc 2.28 |
|
|
65
|
+
| Linux aarch64 | `manylinux_2_28_aarch64` | glibc 2.28 |
|
|
66
|
+
| macOS arm64 | `macosx_11_0_arm64` | macOS 11 |
|
|
67
|
+
| macOS x86_64 | `macosx_10_15_x86_64` | macOS 10.15 |
|
|
68
|
+
|
|
69
|
+
Those binaries link OpenSSL and zlib statically, so they need nothing from the system.
|
|
70
|
+
|
|
71
|
+
Anywhere else, pip installs the source distribution, which carries no binary. On musl, on
|
|
72
|
+
32-bit ARM, or with an older glibc, [compile](https://tdlib.github.io/td/build.html) `tdlib`
|
|
73
|
+
yourself.
|
|
74
|
+
|
|
75
|
+
`python-telegram` looks for the library in this order, and logs which one it used:
|
|
76
|
+
|
|
77
|
+
1. the `library_path` argument
|
|
78
|
+
2. the `PYTHON_TELEGRAM_TDLIB_PATH` environment variable
|
|
79
|
+
3. a system-wide `tdjson`
|
|
80
|
+
4. the bundled binary
|
|
81
|
+
|
|
82
|
+
A system-wide `tdlib` therefore wins over the bundled one. To point at a specific build,
|
|
83
|
+
pass its path. The file is called `libtdjson.so` on Linux and `libtdjson.dylib` on macOS:
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
tg = Telegram(
|
|
87
|
+
# ...
|
|
88
|
+
library_path="/usr/local/lib/libtdjson.so",
|
|
89
|
+
)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
If nothing can be found, `TDJson()` raises `TDLibNotFoundError`, an `OSError` subclass whose
|
|
93
|
+
message names the platform, the paths tried and the overrides.
|
|
94
|
+
|
|
95
|
+
### Docker
|
|
96
|
+
|
|
97
|
+
This library has a [docker image](https://hub.docker.com/r/akhmetov/python-telegram/):
|
|
98
|
+
|
|
99
|
+
```sh
|
|
100
|
+
docker run -i -t --rm \
|
|
101
|
+
-v /tmp/docker-python-telegram/:/tmp/ \
|
|
102
|
+
akhmetov/python-telegram \
|
|
103
|
+
python3 /app/examples/send_message.py $API_ID $API_HASH $PHONE $CHAT_ID $TEXT
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## How to use the library
|
|
107
|
+
|
|
108
|
+
First, [register a new Telegram application](https://my.telegram.org/apps/) to get your `api_id` and `api_hash`.
|
|
109
|
+
Check out the [tutorial](https://python-telegram.readthedocs.io/latest/tutorial.html) for more details.
|
|
110
|
+
|
|
111
|
+
Basic example:
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
from telegram.client import Telegram
|
|
115
|
+
from telegram.text import Spoiler
|
|
116
|
+
|
|
117
|
+
tg = Telegram(
|
|
118
|
+
api_id=123456,
|
|
119
|
+
api_hash="api_hash",
|
|
120
|
+
phone="+31611111111", # you can pass 'bot_token' instead
|
|
121
|
+
database_encryption_key="changekey123",
|
|
122
|
+
files_directory="/tmp/.tdlib_files/",
|
|
123
|
+
)
|
|
124
|
+
tg.login()
|
|
125
|
+
|
|
126
|
+
# The chat must be in the tdlib database before you can send a message to it.
|
|
127
|
+
# `get_chats` loads up to `limit` chats from the main chat list.
|
|
128
|
+
result = tg.get_chats(limit=100)
|
|
129
|
+
result.wait()
|
|
130
|
+
|
|
131
|
+
chat_id = 123456789
|
|
132
|
+
result = tg.send_message(chat_id, Spoiler("Hello world!"))
|
|
133
|
+
|
|
134
|
+
# `tdlib` is asynchronous, so `python-telegram` always returns an `AsyncResult` object.
|
|
135
|
+
# You can receive a result with the `wait` method of this object.
|
|
136
|
+
result.wait()
|
|
137
|
+
print(result.update)
|
|
138
|
+
|
|
139
|
+
tg.stop() # You must call `stop` at the end of the script.
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
You can also use `call_method` to call any [tdlib method](https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1_function.html):
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
tg.call_method("getUser", params={"user_id": user_id})
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
More examples can be found in the [/examples/ directory](/examples/).
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
More information is available in the [documentation](https://python-telegram.readthedocs.io/latest/).
|
|
153
|
+
|
|
154
|
+
## Development
|
|
155
|
+
|
|
156
|
+
See [CONTRIBUTING.md](/CONTRIBUTING.md).
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# python-telegram
|
|
2
|
+
|
|
3
|
+
[](https://github.com/alexander-akhmetov/python-telegram/actions)
|
|
4
|
+
[](https://pypi.python.org/pypi/python-telegram)
|
|
5
|
+
[](https://python-telegram.readthedocs.io/latest/)
|
|
6
|
+
|
|
7
|
+
Python API for the [tdlib](https://github.com/tdlib/td) library.
|
|
8
|
+
It helps you build your own Telegram clients.
|
|
9
|
+
|
|
10
|
+
`tdlib` connects to Telegram over MTProto, the same protocol the official apps use.
|
|
11
|
+
This library signs in as a full Telegram account with a phone number, and it can do what a regular client can do.
|
|
12
|
+
|
|
13
|
+
It is not a wrapper around the HTTP Bot API.
|
|
14
|
+
If you only need a bot, [python-telegram-bot](https://github.com/python-telegram-bot/python-telegram-bot) is a better fit.
|
|
15
|
+
You can still sign in as a bot here by passing `bot_token` instead of `phone`.
|
|
16
|
+
|
|
17
|
+
- [Changelog](https://python-telegram.readthedocs.io/latest/changelog.html)
|
|
18
|
+
- [Documentation](https://python-telegram.readthedocs.io/latest/)
|
|
19
|
+
- [Tutorial](https://python-telegram.readthedocs.io/latest/tutorial.html)
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
This library requires Python 3.10+. Windows is not supported.
|
|
24
|
+
|
|
25
|
+
```shell
|
|
26
|
+
pip install python-telegram
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
See [documentation](https://python-telegram.readthedocs.io/latest/#installation) for more details.
|
|
30
|
+
|
|
31
|
+
### tdlib
|
|
32
|
+
|
|
33
|
+
Four wheels bundle a `tdlib` binary. Each one works on Python 3.10 through 3.14:
|
|
34
|
+
|
|
35
|
+
| Platform | Wheel | Needs at least |
|
|
36
|
+
| --- | --- | --- |
|
|
37
|
+
| Linux x86_64 | `manylinux_2_28_x86_64` | glibc 2.28 |
|
|
38
|
+
| Linux aarch64 | `manylinux_2_28_aarch64` | glibc 2.28 |
|
|
39
|
+
| macOS arm64 | `macosx_11_0_arm64` | macOS 11 |
|
|
40
|
+
| macOS x86_64 | `macosx_10_15_x86_64` | macOS 10.15 |
|
|
41
|
+
|
|
42
|
+
Those binaries link OpenSSL and zlib statically, so they need nothing from the system.
|
|
43
|
+
|
|
44
|
+
Anywhere else, pip installs the source distribution, which carries no binary. On musl, on
|
|
45
|
+
32-bit ARM, or with an older glibc, [compile](https://tdlib.github.io/td/build.html) `tdlib`
|
|
46
|
+
yourself.
|
|
47
|
+
|
|
48
|
+
`python-telegram` looks for the library in this order, and logs which one it used:
|
|
49
|
+
|
|
50
|
+
1. the `library_path` argument
|
|
51
|
+
2. the `PYTHON_TELEGRAM_TDLIB_PATH` environment variable
|
|
52
|
+
3. a system-wide `tdjson`
|
|
53
|
+
4. the bundled binary
|
|
54
|
+
|
|
55
|
+
A system-wide `tdlib` therefore wins over the bundled one. To point at a specific build,
|
|
56
|
+
pass its path. The file is called `libtdjson.so` on Linux and `libtdjson.dylib` on macOS:
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
tg = Telegram(
|
|
60
|
+
# ...
|
|
61
|
+
library_path="/usr/local/lib/libtdjson.so",
|
|
62
|
+
)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
If nothing can be found, `TDJson()` raises `TDLibNotFoundError`, an `OSError` subclass whose
|
|
66
|
+
message names the platform, the paths tried and the overrides.
|
|
67
|
+
|
|
68
|
+
### Docker
|
|
69
|
+
|
|
70
|
+
This library has a [docker image](https://hub.docker.com/r/akhmetov/python-telegram/):
|
|
71
|
+
|
|
72
|
+
```sh
|
|
73
|
+
docker run -i -t --rm \
|
|
74
|
+
-v /tmp/docker-python-telegram/:/tmp/ \
|
|
75
|
+
akhmetov/python-telegram \
|
|
76
|
+
python3 /app/examples/send_message.py $API_ID $API_HASH $PHONE $CHAT_ID $TEXT
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## How to use the library
|
|
80
|
+
|
|
81
|
+
First, [register a new Telegram application](https://my.telegram.org/apps/) to get your `api_id` and `api_hash`.
|
|
82
|
+
Check out the [tutorial](https://python-telegram.readthedocs.io/latest/tutorial.html) for more details.
|
|
83
|
+
|
|
84
|
+
Basic example:
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
from telegram.client import Telegram
|
|
88
|
+
from telegram.text import Spoiler
|
|
89
|
+
|
|
90
|
+
tg = Telegram(
|
|
91
|
+
api_id=123456,
|
|
92
|
+
api_hash="api_hash",
|
|
93
|
+
phone="+31611111111", # you can pass 'bot_token' instead
|
|
94
|
+
database_encryption_key="changekey123",
|
|
95
|
+
files_directory="/tmp/.tdlib_files/",
|
|
96
|
+
)
|
|
97
|
+
tg.login()
|
|
98
|
+
|
|
99
|
+
# The chat must be in the tdlib database before you can send a message to it.
|
|
100
|
+
# `get_chats` loads up to `limit` chats from the main chat list.
|
|
101
|
+
result = tg.get_chats(limit=100)
|
|
102
|
+
result.wait()
|
|
103
|
+
|
|
104
|
+
chat_id = 123456789
|
|
105
|
+
result = tg.send_message(chat_id, Spoiler("Hello world!"))
|
|
106
|
+
|
|
107
|
+
# `tdlib` is asynchronous, so `python-telegram` always returns an `AsyncResult` object.
|
|
108
|
+
# You can receive a result with the `wait` method of this object.
|
|
109
|
+
result.wait()
|
|
110
|
+
print(result.update)
|
|
111
|
+
|
|
112
|
+
tg.stop() # You must call `stop` at the end of the script.
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
You can also use `call_method` to call any [tdlib method](https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1_function.html):
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
tg.call_method("getUser", params={"user_id": user_id})
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
More examples can be found in the [/examples/ directory](/examples/).
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
More information is available in the [documentation](https://python-telegram.readthedocs.io/latest/).
|
|
126
|
+
|
|
127
|
+
## Development
|
|
128
|
+
|
|
129
|
+
See [CONTRIBUTING.md](/CONTRIBUTING.md).
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
=========
|
|
2
|
+
Changelog
|
|
3
|
+
=========
|
|
4
|
+
|
|
5
|
+
[2.0.0] - 2026-08-23
|
|
6
|
+
--------------------
|
|
7
|
+
|
|
8
|
+
- tdlib 1.8.31 is replaced by tdlib 1.8.66.
|
|
9
|
+
- ``python-telegram`` is now published as four platform wheels instead of one ``py3-none-any`` wheel: ``manylinux_2_28_x86_64``, ``manylinux_2_28_aarch64``, ``macosx_11_0_arm64`` and ``macosx_10_15_x86_64``. Each bundles a ``tdlib`` that links OpenSSL and zlib statically, so it needs nothing from the system.
|
|
10
|
+
- The bundled binary now works on Apple Silicon. The old one was x86_64 only and ``ctypes`` refused to load it (`#377 <https://github.com/alexander-akhmetov/python-telegram/issues/377>`_).
|
|
11
|
+
- The bundled Linux binary no longer needs OpenSSL 1.1, which reached end of life in 2023 and is absent from Debian 12+, Ubuntu 22.04+ and RHEL 9. Importing the library in those images failed with ``libssl.so.1.1: cannot open shared object file``.
|
|
12
|
+
- Installing from the source distribution no longer gives you a ``tdlib`` binary. The sdist is the fallback for the platforms the four wheels do not cover, so install ``tdlib`` system-wide or pass ``library_path``.
|
|
13
|
+
- The library can now be pointed at a specific ``tdlib`` with the ``PYTHON_TELEGRAM_TDLIB_PATH`` environment variable. The search order is ``library_path``, then that variable, then a system-wide ``tdjson``, then the bundled binary. Which one was used is logged.
|
|
14
|
+
- When no library can be found or loaded, ``TDJson`` raises ``TDLibNotFoundError`` instead of a raw ``dlopen`` message. It subclasses ``OSError``, which is what ``ctypes.CDLL`` used to raise, so existing handlers keep working.
|
|
15
|
+
- Login no longer fails with a ``ValueError`` on ``authorizationStateWaitPremiumPurchase``, and an authorization state this library has never heard of now resolves to ``AuthorizationState.UNKNOWN`` instead of raising.
|
|
16
|
+
|
|
17
|
+
Breaking changes, from the tdlib 1.8.66 signatures:
|
|
18
|
+
|
|
19
|
+
- ``get_web_page_instant_view`` takes ``only_local`` instead of ``force_full``. tdlib removed ``force_full``; ``only_local`` means something different, "use locally available information only, without any network request".
|
|
20
|
+
- ``import_contacts`` now sends each contact as an ``importedContact`` rather than a ``contact``. That is what ``importContacts`` takes in 1.8.66.
|
|
21
|
+
- ``addProxy`` now nests the server, port and type inside a ``proxy`` object. Code that calls ``call_method('addProxy', ...)`` directly has to be updated.
|
|
22
|
+
|
|
23
|
+
[1.0.0] - 2026-07-25
|
|
24
|
+
--------------------
|
|
25
|
+
|
|
26
|
+
- Python 3.9 is no longer supported.
|
|
27
|
+
- Added support for Python 3.13 and 3.14.
|
|
28
|
+
- Login no longer fails with a ``ValueError`` when tdlib reports an authorization state that ``AuthorizationState`` did not know about: ``authorizationStateWaitEmailAddress``, ``authorizationStateWaitEmailCode``, ``authorizationStateWaitOtherDeviceConfirmation`` and ``authorizationStateLoggingOut``.
|
|
29
|
+
- Added email authorization support: ``send_email_address`` and ``send_email_code``.
|
|
30
|
+
- ``stop`` no longer blocks forever when tdlib does not answer, and no longer leaves the client running when tdlib answers with an error. It now waits up to 5 seconds for the session to close, which can be changed with ``stop(close_timeout=...)``.
|
|
31
|
+
- Calling a method after ``stop`` raises ``ClientDestroyedError`` instead of crashing the process. The destroyed tdlib handle was passed to the C library as a ``NULL`` pointer.
|
|
32
|
+
- An exception raised by an update handler no longer stops the worker thread. The error is logged and the worker keeps processing the queue.
|
|
33
|
+
- When the handler queue is full, the update is dropped and an error is logged instead of raising ``queue.Full``.
|
|
34
|
+
- ``get_chats`` no longer sends the ``offset_order`` and ``offset_chat_id`` parameters. tdlib removed them from ``getChats`` in 1.8.0 and silently ignored them since then, so passing them had no effect. The signature is now ``get_chats(limit=100, chat_list=None)``, which also makes it possible to read the archive and chat folders instead of only the main chat list. This is a breaking change for code that passes the offsets.
|
|
35
|
+
- Added ``load_chats``, which wraps the tdlib ``loadChats`` method.
|
|
36
|
+
|
|
37
|
+
[0.19.0] - 2024-06-23
|
|
38
|
+
---------------------
|
|
39
|
+
|
|
40
|
+
- Python versions 3.7 and 3.8 are no longer supported.
|
|
41
|
+
- tdlib 1.8.31.
|
|
42
|
+
|
|
43
|
+
[0.18.0] - 2023-03-13
|
|
44
|
+
---------------------
|
|
45
|
+
|
|
46
|
+
- Added support for tdlib > 1.8.5. (thanks to @JleMyP)
|
|
47
|
+
|
|
48
|
+
[0.17.0] - 2023-01-25
|
|
49
|
+
---------------------
|
|
50
|
+
|
|
51
|
+
- Added ``import_contacts`` method. (thanks to @vlad-lf)
|
|
52
|
+
- Added markup support. It is now possible to send formatted text (html/markdown and telegram-specific formats, for example hidden spoiler styling) (thanks to @SKY-ALIN)
|
|
53
|
+
|
|
54
|
+
[0.16.0] - 2022-08-18
|
|
55
|
+
---------------------
|
|
56
|
+
|
|
57
|
+
- Search for the system library first, and fallback to the embedded one if the system was not found.
|
|
58
|
+
- Fixed the finding system library mechanism (thanks to @weirdo-neutrino)
|
|
59
|
+
- tdlib v1.8.5
|
|
60
|
+
|
|
61
|
+
[0.15.0] - 2021-12-03
|
|
62
|
+
---------------------
|
|
63
|
+
|
|
64
|
+
- tdlib v1.7.9. Fixes ``UPDATE_APP_TO_LOGIN`` errors.
|
|
65
|
+
|
|
66
|
+
[0.14.0] - 2020-12-17
|
|
67
|
+
---------------------
|
|
68
|
+
|
|
69
|
+
- tdlib v1.7.0
|
|
70
|
+
|
|
71
|
+
[0.13.0] - 2020-11-16
|
|
72
|
+
---------------------
|
|
73
|
+
|
|
74
|
+
- Non-blocking login, see ``examples/get_me_non_blocking_login.py`` (thanks to @melfnt).
|
|
75
|
+
- Better stop. python-telegram calls ``close`` and waits until tdlib is closed.
|
|
76
|
+
|
|
77
|
+
[0.12.0] - 2020-03-29
|
|
78
|
+
---------------------
|
|
79
|
+
|
|
80
|
+
- New example: ``examples/clear_group_messages.py`` (thanks to @h4x3rotab)
|
|
81
|
+
- Proxy support (thanks to @h4x3rotab)
|
|
82
|
+
- New methods: ``delete_messages``, ``get_supergroup_full_info``, ``create_basic_group_chat``. (thanks to @h4x3rotab)
|
|
83
|
+
- Fix #67: fixed infinite waiting for a result during login or for an ``ok`` result type.
|
|
84
|
+
- New Telegram initialization parameter: ``use_secret_chats`` (``True`` by default) (thanks to @DopeforHope)
|
|
85
|
+
- Fix #81: ``encryption_key`` for tdlib database encryption is now being sent to tdlib as a base64 encoded string.
|
|
86
|
+
|
|
87
|
+
[0.11.0] - 2020-02-15
|
|
88
|
+
---------------------
|
|
89
|
+
|
|
90
|
+
- ``tdlib`` upgraded to ``v1.6.0`` (from `this repository <https://github.com/alexander-akhmetov/tdlib-compiled>`_)
|
|
91
|
+
- Added a new parameter to the ``call_method``: ``block=False``. If it is set to ``True``, the method waits for the result from tdlib.
|
|
92
|
+
- Added ``Telegram.get_message`` method (thanks to @ali-shokoohi)
|
|
93
|
+
- Fixed a race condition when in some cases ``AsyncResult.wait()`` could raise ``TimeoutError`` or end up in an endless loop. (thanks to @akamaus)
|
|
94
|
+
- Added a new method: ``get_user``.
|
|
95
|
+
- Added ``Telegram.remove_update_handler`` function to remove update handlers.
|
|
96
|
+
|
|
97
|
+
[0.10.0] - 2019-04-10
|
|
98
|
+
---------------------
|
|
99
|
+
|
|
100
|
+
- **Incompatible** Linux library has been changed, now it's compiled on Ubuntu with libc.
|
|
101
|
+
|
|
102
|
+
[0.9.0] - 2019-04-05
|
|
103
|
+
--------------------
|
|
104
|
+
|
|
105
|
+
- **Incompatible** default path for files is changed. Now the library uses an md5 hash of the phone number or bot token instead of just a phone number.
|
|
106
|
+
It should not be noticeable for most cases, but if you rely on locally saved files or database, you need to pass the ``files_directory`` parameter to the ``telegram.client.Telegram``.
|
|
107
|
+
- Fixed problem with randomly raised "Database encryption key is needed" errors during login process. (#12)
|
|
108
|
+
- Fixed ``stop`` method execution. (#8)
|
|
109
|
+
- Added ``examples/bot_login.py`` example.
|
|
110
|
+
|
|
111
|
+
[0.8.0] - 2019-03-17
|
|
112
|
+
--------------------
|
|
113
|
+
|
|
114
|
+
- ``telegram.client.Telegram`` now supports any update type with a new method ``add_update_handler(handler_type, func)``
|
|
115
|
+
- ``tdlib v 1.3.0``
|
|
116
|
+
- Fixed problem with openssl in Dockerfile (#4)
|
|
117
|
+
|
|
118
|
+
[0.7.0]
|
|
119
|
+
-------
|
|
120
|
+
|
|
121
|
+
- New method ``getMe`` with an example.
|
|
122
|
+
|
|
123
|
+
[0.6.1] - 2018-05-01
|
|
124
|
+
--------------------
|
|
125
|
+
|
|
126
|
+
- Fixes for the Linux pre-compiled tdlib library.
|
|
127
|
+
|
|
128
|
+
[0.6.0] - 2018-05-01
|
|
129
|
+
--------------------
|
|
130
|
+
|
|
131
|
+
- Fixes for the Linux pre-compiled tdlib library.
|
|
132
|
+
|
|
133
|
+
[0.5.0] - 2018-05-01
|
|
134
|
+
--------------------
|
|
135
|
+
|
|
136
|
+
- New **required** parameter in the ``telegram.client.Telegram``: ``database_encryption_key``.
|
|
137
|
+
|
|
138
|
+
- Compiled ``tdlib`` files now are in the pypi package (Linux and MacOS).
|
|
139
|
+
|
|
140
|
+
- Default location of the tdlib's files changed to ``/tmp/.tdlib_files/{phone_number}``.
|
|
141
|
+
|
|
142
|
+
- Now you can define additional optional params:
|
|
143
|
+
|
|
144
|
+
* use_test_dc (default False)
|
|
145
|
+
* device_model
|
|
146
|
+
* system_version
|
|
147
|
+
* system_language_code
|
|
148
|
+
* application_version
|
|
149
|
+
* use_message_database (default True)
|
|
150
|
+
|
|
151
|
+
- Added new example: ``chat_stats.py``.
|
|
152
|
+
|
|
153
|
+
[0.4.0] - 2018-04-29
|
|
154
|
+
--------------------
|
|
155
|
+
|
|
156
|
+
Added two new methods:
|
|
157
|
+
|
|
158
|
+
- ``get_instant_view`` - get instant view of a web page
|
|
159
|
+
- ``call_method`` - call any method with any params
|
|
160
|
+
|
|
161
|
+
New example: `get_instant_view.py <https://github.com/alexander-akhmetov/python-telegram/blob/main/examples/get_instant_view.py>`_
|
|
162
|
+
|
|
163
|
+
[0.3.1] - 2018-04-29
|
|
164
|
+
--------------------
|
|
165
|
+
|
|
166
|
+
- Logging level in the examples changed to ``INFO``.
|
|
167
|
+
- Added new ``Makefile`` command: ``docker-echo-bot``.
|
|
168
|
+
- All ``docker-`` commands in the ``Makefile`` now mount ``/tmp/`` from
|
|
169
|
+
a host machine to store tdlib's files.
|
|
170
|
+
|
|
171
|
+
[0.3.0] - 2018-04-28
|
|
172
|
+
--------------------
|
|
173
|
+
|
|
174
|
+
- Added ``Dockerfile`` and ``Makefile`` with some examples.
|
|
175
|
+
- Changed directory for tdlib files to
|
|
176
|
+
``/tmp/.tdlib_files_{self.phone}/``.
|