python-telegram-bot/examples
Bibo-Joshi ed147813ab
API 5.3 (#2572)
* BotCommandScopes

* pre-commit

* typo

Co-authored-by: Harshil <37377066+harshil21@users.noreply.github.com>

* rename kickChatMember & getChatMembersCount method

Signed-off-by: starry69 <starry369126@outlook.com>

* add `language_code` and `scope` to `get/set_my_commands`

and add `delete_my_commands()`

* add `input_field_placeholder` to replykeyboardmarkup.py and forcereply.py

also improved/fixed docs along the way

* showcase `input_field_placeholder` in conversationbot.py

* review 1

'i will not go away' has gone away 😢

* deprecate `Bot.commands` and make sure its only used for default scope

* review 2 (use constants for scope)

* Review

Signed-off-by: starry69 <starry369126@outlook.com>

* doc updates

* New ChatMember classes

Signed-off-by: starry69 <starry369126@outlook.com>

* Address review

Signed-off-by: starry69 <starry369126@outlook.com>

* add versionadded tags again

Signed-off-by: starry69 <starry369126@outlook.com>

* Improve tests & add a deprecation note to ChatMember

* test_official

* Documentation tweaks

* Bump bot api version number

* but bot

* Rename chat shortcuts

Signed-off-by: starry69 <starry369126@outlook.com>

* deepsource

Signed-off-by: starry69 <starry369126@outlook.com>

* add missing slot in botcommandscope & missing slot tests

Co-authored-by: Harshil <37377066+harshil21@users.noreply.github.com>
Co-authored-by: starry69 <starry369126@outlook.com>
Co-authored-by: Harshil <ilovebhagwan@gmail.com>
2021-07-01 17:45:19 +02:00
..
arbitrarycallbackdatabot.py Arbitrary callback_data (#1844) 2021-06-06 11:48:48 +02:00
chatmemberbot.py Doc Fixes (#2495) 2021-06-06 12:16:23 +02:00
contexttypesbot.py Add ContextTypes & BasePersistence.refresh_user/chat/bot_data (#2262) 2021-06-06 10:37:53 +02:00
conversationbot.png [ci skip] add state diagrams for conversation handler examples 2016-10-28 08:26:02 +02:00
conversationbot.py API 5.3 (#2572) 2021-07-01 17:45:19 +02:00
conversationbot2.png [ci skip] add state diagrams for conversation handler examples 2016-10-28 08:26:02 +02:00
conversationbot2.py Doc Fixes (#2495) 2021-06-06 12:16:23 +02:00
deeplinking.py Remove Deprecated pass_args from Deeplinking Example (#2550) 2021-06-07 09:05:17 +02:00
echobot.py Doc Fixes (#2495) 2021-06-06 12:16:23 +02:00
errorhandlerbot.py Doc Fixes (#2495) 2021-06-06 12:16:23 +02:00
inlinebot.py Doc Fixes (#2495) 2021-06-06 12:16:23 +02:00
inlinekeyboard.py Doc Fixes (#2495) 2021-06-06 12:16:23 +02:00
inlinekeyboard2.py Doc Fixes (#2495) 2021-06-06 12:16:23 +02:00
LICENSE.txt dedicate examples to the public domain (CC0) 2015-12-25 15:19:17 +01:00
nestedconversationbot.png Nested ConversationHandlers (#1512) 2019-10-11 22:59:36 +03:00
nestedconversationbot.py Doc Fixes (#2495) 2021-06-06 12:16:23 +02:00
passportbot.html Prepare for 11.0.0 release 2018-08-29 15:21:02 +02:00
passportbot.py Doc Fixes (#2495) 2021-06-06 12:16:23 +02:00
paymentbot.py Doc Fixes (#2495) 2021-06-06 12:16:23 +02:00
persistentconversationbot.py Doc Fixes (#2495) 2021-06-06 12:16:23 +02:00
pollbot.py Doc Fixes (#2495) 2021-06-06 12:16:23 +02:00
rawapibot.py Improve Code Quality (#2536) 2021-05-27 20:34:58 +02:00
README.md Doc Fixes (#2495) 2021-06-06 12:16:23 +02:00
timerbot.py Doc Fixes (#2495) 2021-06-06 12:16:23 +02:00

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.

Do note that we ignore one pythonic convention. Best practice would dictate, in many handler callbacks function signatures, to replace the argument context with an underscore, since context is an unused local variable in those callbacks. However, since these are examples and not having a name for that argument confuses beginners, we decided to have it present.

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 ConversationHandlers. While it's certainly not that complex that you couldn't built it without nested ConversationHanldlers, 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.

contexttypesbot.py

This example showcases how telegram.ext.ContextTypes can be used to customize the context argument of handler and job callbacks.

arbitrarycallbackdatabot.py

This example showcases how PTBs "arbitrary callback data" feature can be used.

Pure API

The rawapibot.py example uses only the pure, "bare-metal" API wrapper.