pytgbot - Telegram Bot API 5
.7
Version 5.7 (stable) ![Join pytgbot group on telegram](https://github.com/camo/087d941e8df1311c32eb818a86edefe518d55f8ff934721b6c229a8670235e13/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f54656c656772616d25323047726f75702d4a6f696e2d626c75652e737667)
Native python package with a pure Python interface for the Telegram Bot API.
The code is generated directly from the API documentation, meaning up-to-date code is a matter of minutes.
- Updated with official API changes
If you're using this library to build your Telegram Bots, We'd love to know and share the bot with the world. Tell us about it - here
Check out the Who's using pytgbot wiki page to know more about what people have been building with this library.
Released versions can be found at several locations:
- The python package index (
pip install
), - on GitHub in the release section
- and in the git files as regular tags.
The latest version seems to be version 4.9.1
. For other releases you must adapt the examples below.
pip install pytgbot==4.9.1
git clone -b v4.9.1 https://github.com/luckydonald/pytgbot.git
cd pytgbot
python setup.py install
To get the most current code manually
git clone https://github.com/luckydonald/pytgbot.git
cd pytgbot
python setup.py install
The latest version seems to be version 4.9.1
. For other releases you must adapt the examples below.
pip install -U pytgbot==4.9.1
cd pytgbot
git fetch
git checkout v4.9.1
python setup.py install
To get the most current code manually
cd pytgbot
git fetch
git checkout master
git pull
python setup.py install
from pytgbot import Bot
API_KEY='123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11' # change this to the token you get from @BotFather
CHAT='@username' # can be a @username or a id, change this to your own @username or id for example.
bot = Bot(API_KEY)
# sending messages:
bot.send_message(CHAT, "Example Text!")
# getting events:
for x in bot.get_updates():
print(x)
All the functions can be found in the Bot
class in the pytgbot/bot.py file.
They are pythonic in small letters with underscores instead of camel case, for example getUpdates is bot.get_updates()
.
You can always inspect the documentation inside the code.
You can also use the python help()
command in the interactive interpreter:
>>> from pytgbot import Bot
>>> help(Bot)
>>> # or
>>> help(Bot.get_updates)
If you want to use a custom Telegram API server, e.g. https://telegram.rest/ it is as simple as setting base_url
and download_url
when creating the bot:
bot = Bot(API_KEY, base_url="https://telegram.rest/bot{api_key}/{command}", download_url="https://telegram.rest/file/bot{api_key}/{file}")
Have a look into the examples folder.
First you should set logging to level DEBUG
to see what's going on.
# add this to the first lines in your file
import logging
logging.basicConfig(level=logging.DEBUG)
If you are about to open a new issue, search the existing ones (open and closed) first. Sometimes they are already reported or even solved.
Best way to apply changes is to create a patch from the commit containing the new generated files output
.
git apply --verbose --reject --no-index -C1 --whitespace=fix --ignore-space-change --ignore-whitespace --directory pytgbot/ NAME.patch
find ./pytgbot/ -type f -name '*.rej' | xargs --replace={} --max-args=1 echo "{} {}"
find ./pytgbot/ -type f -name '*.rej' | xargs --replace={} --max-args=1 bash -c 'file="{}";file="${file%.*}"; echo wiggle --replace ${file} {};'
wiggle --replace pytgbot
You may need to install wiggle: brew install wiggle
See also https://stackoverflow.com/questions/4770177/git-patch-does-not-apply