python-telegram-bot/examples
Poolitzer 55e3ecf9f8
API 4.6 (#1723)
* First take on 4.6 support

* improved docs

* Minor doc formattings

* added poll and poll_answer to filters

* added tests, fixed mentioned issues

* added poll_answer + poll filter tests

* Update docs according to official API docs

* introducing pollhandler and pollanswerhandler

* First take on 4.6 support

* improved docs

* Minor doc formattings

* added poll and poll_answer to filters

* added tests, fixed mentioned issues

* added poll_answer + poll filter tests

* Update docs according to official API docs

* introducing pollhandler and pollanswerhandler

* correct_option_id validated with None

when trying to send a poll with correct option id 0 it was failing. Now None check is done so that even when 0 is passed it is assigned.

* improving example

* improving code

* adding poll filter example to the pollbot.py

* Update Readme

* simplify pollbot.py and add some comments

* add tests for Poll(Answer)Handler

* We just want Filters.poll, not Filters.update.poll

* Make test_official fail again

* Handle ME.language in M._parse_*

Co-authored-by: Hinrich Mahler <hinrich.mahler@freenet.de>
Co-authored-by: Sharun Kumar <715417+sharunkumar@users.noreply.github.com>
2020-03-29 09:52:30 +02:00
..
conversationbot.png
conversationbot.py
conversationbot2.png
conversationbot2.py
deeplinking.py
echobot.py
echobot2.py
inlinebot.py
inlinekeyboard.py Answer CQs and use edit_message_text in examples (#1721) 2020-03-28 12:07:23 +01:00
inlinekeyboard2.py Answer CQs and use edit_message_text in examples (#1721) 2020-03-28 12:07:23 +01:00
LICENSE.txt
nestedconversationbot.png
nestedconversationbot.py Answer CQs and use edit_message_text in examples (#1721) 2020-03-28 12:07:23 +01:00
passportbot.html
passportbot.py
paymentbot.py
persistentconversationbot.py Fix typo in example text (#1703) 2020-01-26 22:35:34 +02:00
pollbot.py API 4.6 (#1723) 2020-03-29 09:52:30 +02:00
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 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!

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!

inlinekeyboard.py

This example sheds some light on inline keyboards, callback queries and message editing.

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.

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.

persistentconversationbot.py

A basic example of a bot store conversation state and user_data over multiple restarts.

Pure API

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