4689a80c2e
Telegram Passport (#1174): - Add full support for telegram passport. - New types: PassportData, PassportFile, EncryptedPassportElement, EncryptedCredentials, PassportElementError, PassportElementErrorDataField, PassportElementErrorFrontSide, PassportElementErrorReverseSide, PassportElementErrorSelfie, PassportElementErrorFile and PassportElementErrorFiles. - New bot method: set_passport_data_errors - New filter: Filters.passport_data - Field passport_data field on Message - PassportData is automagically decrypted when you specify your private key when creating Updater or Bot. - PassportFiles is also automagically decrypted as you download/retrieve them. - See new passportbot.py example for details on how to use, or go to our telegram passport wiki page for more info - NOTE: Passport decryption requires new dependency `cryptography`. Inputfile rework (#1184): - Change how Inputfile is handled internally - This allows support for specifying the thumbnails of photos and videos using the thumb= argument in the different send_ methods. - Also allows Bot.send_media_group to actually finally send more than one media. - Add thumb to Audio, Video and Videonote - Add Bot.edit_message_media together with InputMediaAnimation, InputMediaAudio, and inputMediaDocument. Other Bot API 4.0 changes: - Add forusquare_type to Venue, InlineQueryResultVenue, InputVenueMessageContent, and Bot.send_venue. (#1170) - Add vCard support by adding vcard field to Contact, InlineQueryResultContact, InputContactMessageContent, and Bot.send_contact. (#1166) - Support new message entities: CASHTAG and PHONE_NUMBER. (#1179) - Cashtag seems to be things like $USD and $GBP, but it seems telegram doesn't currently send them to bots. - Phone number also seems to have limited support for now - Add Bot.send_animation, add width, height, and duration to Animation, and add Filters.animation. (#1172) Co-authored-by: Jasmin Bom <jsmnbom@gmail.com> Co-authored-by: code1mountain <32801117+code1mountain@users.noreply.github.com> Co-authored-by: Eldinnie <pieter.schutz+github@gmail.com> Co-authored-by: mathefreak1 <mathefreak@hi2.in> |
||
---|---|---|
.. | ||
conversationbot.png | ||
conversationbot.py | ||
conversationbot2.png | ||
conversationbot2.py | ||
echobot.py | ||
echobot2.py | ||
inlinebot.py | ||
inlinekeyboard.py | ||
LICENSE.txt | ||
passportbot.html | ||
passportbot.py | ||
paymentbot.py | ||
README.md | ||
timerbot.py |
Examples
In this folder there are small examples to show what a bot written with python-telegram-bot
looks like. Some bots focus on one specific aspect of the Telegram Bot API while others focus on one of the mechanics of this library. Except for the echobot.py
example, they all use the high-level framework this library provides with the telegram.ext
submodule.
All examples are licensed under the CC0 License and are therefore fully dedicated to the public domain. You can use them as the base for your own bots without worrying about copyrights.
echobot2.py
This is probably the base for most of the bots made with python-telegram-bot
. It simply replies to each text message with a message that contains the same text.
timerbot.py
This bot uses the JobQueue
class to send timed messages. The user sets a timer by using /set
command with a specific time, for example /set 30
. The bot then sets up a job to send a message to that user after 30 seconds. The user can also cancel the timer by sending /unset
. To learn more about the JobQueue
, read this wiki article.
conversationbot.py
A common task for a bot is to ask information from the user. In v5.0 of this library, we introduced the ConversationHandler
for that exact purpose. This example uses it to retrieve user-information in a conversation-like style. To get a better understanding, take a look at the state diagram.
conversationbot2.py
A more complex example of a bot that uses the ConversationHandler
. It is also more confusing. Good thing there is a fancy state diagram for this one, too!
inlinekeyboard.py
This example sheds some light on inline keyboards, callback queries and message editing.
inlinebot.py
A basic example of an inline bot. Don't forget to enable inline mode with @BotFather.
paymentbot.py
A basic example of a bot that can accept payments. Don't forget to enable and configure payments with @BotFather.
Pure API
The echobot.py
example uses only the pure, "bare-metal" API wrapper.