8bf88c3231
* Add deepsource config
* Update Badges
* Update Badges some more
* Stupid change to trigger analysis of all files
* Try to get ignore right
* Update badges again
* Get started on fixing issues
* Fix some more issues
* Remove more plank lines
* Docs for de_json/list & to_dict/json
* Some improvements from deepcode.ai
* Some more improvements
* Some more improvements
* More docstrnigs & let's run DS on the tests just for fun
* Autofix issues in 10 files
Resolved issues in the following files via DeepSource Autofix:
1. tests/conftest.py
2. tests/test_bot.py
3. tests/test_commandhandler.py
4. tests/test_conversationhandler.py
5. tests/test_dispatcher.py
6. tests/test_filters.py
7. tests/test_inputmedia.py
8. tests/test_messagehandler.py
9. tests/test_official.py
10. tests/test_persistence.py
* Some more improvements for tests, but that shall be enough
* Some more docstrings for functions
* Some minor stuff, try to fix tests
* Update DS config
* Still more docs
* Doc fixes
* More fixes
* Fix: indent docstring
* Some fixes
* Revert "Stupid change to trigger analysis of all files"
This reverts commit
|
||
---|---|---|
.. | ||
chatmemberbot.py | ||
conversationbot.png | ||
conversationbot.py | ||
conversationbot2.png | ||
conversationbot2.py | ||
deeplinking.py | ||
echobot.py | ||
errorhandlerbot.py | ||
inlinebot.py | ||
inlinekeyboard.py | ||
inlinekeyboard2.py | ||
LICENSE.txt | ||
nestedconversationbot.png | ||
nestedconversationbot.py | ||
passportbot.html | ||
passportbot.py | ||
paymentbot.py | ||
persistentconversationbot.py | ||
pollbot.py | ||
rawapibot.py | ||
README.md | ||
timerbot.py |
Examples
In this folder 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 rawapibot.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.
echobot.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!
nestedconversationbot.py
A even more complex example of a bot that uses the nested ConversationHandler
s. While it's certainly not that complex that you couldn't built it without nested ConversationHanldler
s, it gives a good impression on how to work with them. Of course, there is a fancy state diagram for this example, too!
persistentconversationbot.py
A basic example of a bot store conversation state and user_data over multiple restarts.
inlinekeyboard.py
This example sheds some light on inline keyboards, callback queries and message editing. A wikipedia site explaining this examples lives at https://git.io/JOmFw.
inlinekeyboard2.py
A more complex example about inline keyboards, callback queries and message editing. This example showcases how an interactive menu could be build using inline keyboards.
deeplinking.py
A basic example on how to use deeplinking with inline keyboards.
inlinebot.py
A basic example of an inline bot. Don't forget to enable inline mode with @BotFather.
pollbot.py
This example sheds some light on polls, poll answers and the corresponding handlers.
passportbot.py
A basic example of a bot that can accept passports. Use in combination with passportbot.html
. Don't forget to enable and configure payments with @BotFather. Check out this guide on Telegram passports in PTB.
paymentbot.py
A basic example of a bot that can accept payments. Don't forget to enable and configure payments with @BotFather.
errorhandlerbot.py
A basic example on how to set up a custom error handler.
chatmemberbot.py
A basic example on how (my_)chat_member
updates can be used.
Pure API
The rawapibot.py
example uses only the pure, "bare-metal" API wrapper.