-
Notifications
You must be signed in to change notification settings - Fork 5
Introduction to the API
The API is exposed via the telegram.Bot
class. The methods have names as described in the official Telegram Bot API, but equivalent snake_case methods are available for PEP8 enthusiasts. So for example telegram.Bot.send_message
is the same as telegram.Bot.sendMessage
.
To generate an Access Token, you have to talk to BotFather and follow a few simple steps (described here).
For full details see the Bots: An introduction for developers.
To get a feeling for the API and how to speak to it with python-telegram-bot
, please open a Python command line and follow the next few steps.
First, create an instance of the telegram.Bot
. 'TOKEN'
should be replaced by the API token you received from @BotFather
:
>>> import telegram
>>> bot = telegram.Bot(token='TOKEN')
To check if your credentials are correct, call the getMe API method:
>>> print(bot.getMe())
{"first_name": "Toledo's Palace Bot", "username": "ToledosPalaceBot"}
Note: Bots can't initiate conversations with users. A user must either add them to a group or send them a message first. People can use telegram.me/<bot_username>
links or username search to find your bot.
If you want to continue learning about the API, read Code snippets.
To get real and start building your first bot using the telegram.ext
classes, read Extensions
Wiki of python-telegram-bot
© Copyright 2015-2022 – Licensed by Creative Commons
- Types of Handlers
- Advanced Filters
- Storing data
- Making your bot persistent
- Adding Defaults
- Exception Handling
- Job Queue
- Arbitrary
callback_data
- Avoiding flood limits
- Frequently requested design patterns
- Code snippets
- Performance Optimizations
- Webhooks
- Telegram Passport
- Bots built with PTB
- Automated Bot Tests