Simple Telegram BOT library.
Example Usage
Example with poll method:
# -*-coding:utf8;-*-
from TelegramSDK import telegram as bot
# telegram token is automatic loaded from environment variable TELEGRAM_BOT_TOKEN but you can also set it manually
bot.set_token("your token")
# call this function if you run on old device
# bot.disable_ssl()
def handler(data):
bot.update(data)
download_photo = bot.download_file("/tmp", filter=(".jpeg", ".jpg", ".png"))
if len(download_photo):
bot.reply_message("Photo downloaded: {}".format(download_photo))
else:
try:
# user not send any file
bot.reply_message("OK: " + bot.data.message.text)
"""
or reply with file bot.reply_file("path/to/file/example.pdf", caption="example file!")
"""
except BaseException as e:
# handle user send file but not photo
bot.reply_message("file not supported!")
bot.poll(handler, worker=5, debug=True)
Example with webhook (flask, bottle etc)
@post("/webhook")
def handler():
bot.update(request.json)
bot.reply_message("OK: " + bot.data.message.text)
TelegramSDK has built-in session function based zcache, for example:
if bot.get_session():
count = bot.get_session() + 1
bot.set_session(count, ttl=3600)
bot.reply_message("count: %d" % count)
else:
bot.set_session(1, ttl=3600)
bot.reply_message("count: 1")
for more doc please read the source code.
License
MIT
Metadata
Release files for TelSDK 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| telsdk-0.1.2.tar.gz | 7.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| TelSDK-0.1.2-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 15.8 kB
Release files / telsdk-0.1.2.tar.gz
| Download URL | telsdk-0.1.2.tar.gz |
|---|---|
| Size | 7.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e94ea04923fab36025f16ff74bcb7dd04a8ca78ed81056914b3a33b88207b9cc
|
|
BLAKE2b-256 checksum How to use checksums |
581d5685bd659be2ad5441e5473f14a25e59906bd4d90b00cac77ca8c5f3b995
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.6
|
Release files / TelSDK-0.1.2-py2.py3-none-any.whl
| Download URL | TelSDK-0.1.2-py2.py3-none-any.whl |
|---|---|
| Size | 8.4 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
5205e117c7f1e8d0bd0d4a6ae6b519d110a30c2322477a20e974e4450003f05f
|
|
BLAKE2b-256 checksum How to use checksums |
1b2790f999a6d2a005635bd7fcd3b37a657a1c4703f818195f2eaebcf31ff3d8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.6
|
Security for TelSDK 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.