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
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
telsdk-0.1.2.tar.gz
(7.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file telsdk-0.1.2.tar.gz.
File metadata
- Download URL: telsdk-0.1.2.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/5.1.1 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e94ea04923fab36025f16ff74bcb7dd04a8ca78ed81056914b3a33b88207b9cc
|
|
| MD5 |
e01aba4539c06b3abb2f9ecb7379ebd4
|
|
| BLAKE2b-256 |
581d5685bd659be2ad5441e5473f14a25e59906bd4d90b00cac77ca8c5f3b995
|
File details
Details for the file TelSDK-0.1.2-py2.py3-none-any.whl.
File metadata
- Download URL: TelSDK-0.1.2-py2.py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/5.1.1 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5205e117c7f1e8d0bd0d4a6ae6b519d110a30c2322477a20e974e4450003f05f
|
|
| MD5 |
8b5f740b66798ed06bed160e8d7820ba
|
|
| BLAKE2b-256 |
1b2790f999a6d2a005635bd7fcd3b37a657a1c4703f818195f2eaebcf31ff3d8
|