Move Examples To Documentation (#3089)

This commit is contained in:
Bibo-Joshi 2022-06-09 17:22:32 +02:00 committed by GitHub
parent 11007c1715
commit 67e7468366
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
47 changed files with 416 additions and 105 deletions

View file

@ -151,7 +151,7 @@ Resources
- The `package documentation <https://docs.python-telegram-bot.org/>`_ is the technical reference for ``python-telegram-bot``. - The `package documentation <https://docs.python-telegram-bot.org/>`_ is the technical reference for ``python-telegram-bot``.
It contains descriptions of all available classes, modules, methods and arguments. It contains descriptions of all available classes, modules, methods and arguments.
- The `wiki <https://github.com/python-telegram-bot/python-telegram-bot/wiki/>`_ is home to number of more elaborate introductions of the different features of ``python-telegram-bot`` and other useful resources that go beyond the technical documentation. - The `wiki <https://github.com/python-telegram-bot/python-telegram-bot/wiki/>`_ is home to number of more elaborate introductions of the different features of ``python-telegram-bot`` and other useful resources that go beyond the technical documentation.
- Our `examples directory <https://github.com/python-telegram-bot/python-telegram-bot/blob/master/examples/README.md>`_ contains several examples that showcase the different features of both the Bot API and ``python-telegram-bot``. - Our `examples section <https://docs.python-telegram-bot.org/examples.html>`_ contains several examples that showcase the different features of both the Bot API and ``python-telegram-bot``.
Even if it is not your approach for learning, please take a look at ``echobot.py``. It is the de facto base for most of the bots out there. Even if it is not your approach for learning, please take a look at ``echobot.py``. It is the de facto base for most of the bots out there.
The code for these examples is released to the public domain, so you can start by grabbing the code and building on top of it. The code for these examples is released to the public domain, so you can start by grabbing the code and building on top of it.
- The `official Telegram Bot API documentation <https://core.telegram.org/bots/api>`_ is of course always worth a read. - The `official Telegram Bot API documentation <https://core.telegram.org/bots/api>`_ is of course always worth a read.

View file

@ -148,7 +148,7 @@ Resources
- The `package documentation <https://docs.python-telegram-bot.org/>`_ is the technical reference for ``python-telegram-bot``. - The `package documentation <https://docs.python-telegram-bot.org/>`_ is the technical reference for ``python-telegram-bot``.
It contains descriptions of all available classes, modules, methods and arguments. It contains descriptions of all available classes, modules, methods and arguments.
- The `wiki <https://github.com/python-telegram-bot/python-telegram-bot/wiki/>`_ is home to number of more elaborate introductions of the different features of ``python-telegram-bot`` and other useful resources that go beyond the technical documentation. - The `wiki <https://github.com/python-telegram-bot/python-telegram-bot/wiki/>`_ is home to number of more elaborate introductions of the different features of ``python-telegram-bot`` and other useful resources that go beyond the technical documentation.
- Our `examples directory <https://github.com/python-telegram-bot/python-telegram-bot/blob/master/examples/README.md>`_ contains several examples that showcase the different features of both the Bot API and ``python-telegram-bot``. - Our `examples section <https://docs.python-telegram-bot.org/examples.html>`_ contains several examples that showcase the different features of both the Bot API and ``python-telegram-bot``.
Even if it is not your approach for learning, please take a look at ``echobot.py``. It is the de facto base for most of the bots out there. Even if it is not your approach for learning, please take a look at ``echobot.py``. It is the de facto base for most of the bots out there.
The code for these examples is released to the public domain, so you can start by grabbing the code and building on top of it. The code for these examples is released to the public domain, so you can start by grabbing the code and building on top of it.
- The `official Telegram Bot API documentation <https://core.telegram.org/bots/api>`_ is of course always worth a read. - The `official Telegram Bot API documentation <https://core.telegram.org/bots/api>`_ is of course always worth a read.

View file

@ -0,0 +1,7 @@
``arbitrarycallbackdatabot.py``
===============================
.. literalinclude:: ../../examples/arbitrarycallbackdatabot.py
:language: python
:linenos:

View file

@ -0,0 +1,7 @@
``chatmemberbot.py``
====================
.. literalinclude:: ../../examples/chatmemberbot.py
:language: python
:linenos:

View file

@ -0,0 +1,7 @@
``contexttypesbot.py``
======================
.. literalinclude:: ../../examples/contexttypesbot.py
:language: python
:linenos:

View file

@ -0,0 +1,14 @@
``conversationbot.py``
======================
.. literalinclude:: ../../examples/conversationbot.py
:language: python
:linenos:
.. _conversationbot-diagram:
State Diagram
-------------
.. image:: ../../examples/conversationbot.png

View file

@ -0,0 +1,14 @@
``conversationbot2.py``
=======================
.. literalinclude:: ../../examples/conversationbot2.py
:language: python
:linenos:
.. _conversationbot2-diagram:
State Diagram
-------------
.. image:: ../../examples/conversationbot2.png

View file

@ -0,0 +1,7 @@
``customwebhookbot.py``
=======================
.. literalinclude:: ../../examples/customwebhookbot.py
:language: python
:linenos:

View file

@ -0,0 +1,7 @@
``deeplinking.py``
==================
.. literalinclude:: ../../examples/deeplinking.py
:language: python
:linenos:

View file

@ -0,0 +1,7 @@
``echobot.py``
==============
.. literalinclude:: ../../examples/echobot.py
:language: python
:linenos:

View file

@ -0,0 +1,7 @@
``errorhandlerbot.py``
======================
.. literalinclude:: ../../examples/errorhandlerbot.py
:language: python
:linenos:

View file

@ -0,0 +1,7 @@
``inlinebot.py``
================
.. literalinclude:: ../../examples/inlinebot.py
:language: python
:linenos:

View file

@ -0,0 +1,7 @@
``inlinekeyboard.py``
=====================
.. literalinclude:: ../../examples/inlinekeyboard.py
:language: python
:linenos:

View file

@ -0,0 +1,7 @@
``inlinekeyboard2.py``
======================
.. literalinclude:: ../../examples/inlinekeyboard2.py
:language: python
:linenos:

View file

@ -0,0 +1,14 @@
``nestedconversationbot.py``
============================
.. literalinclude:: ../../examples/nestedconversationbot.py
:language: python
:linenos:
.. _nestedconversationbot-diagram:
State Diagram
-------------
.. image:: ../../examples/nestedconversationbot.png

View file

@ -0,0 +1,16 @@
``passportbot.py``
==================
.. literalinclude:: ../../examples/passportbot.py
:language: python
:linenos:
.. _passportbot-html:
HTML Page
---------
.. literalinclude:: ../../examples/passportbot.html
:language: html
:linenos:

View file

@ -0,0 +1,7 @@
``paymentbot.py``
=================
.. literalinclude:: ../../examples/paymentbot.py
:language: python
:linenos:

View file

@ -0,0 +1,7 @@
``persistentconversationbot.py``
================================
.. literalinclude:: ../../examples/persistentconversationbot.py
:language: python
:linenos:

View file

@ -0,0 +1,7 @@
``pollbot.py``
==============
.. literalinclude:: ../../examples/pollbot.py
:language: python
:linenos:

View file

@ -0,0 +1,11 @@
`rawapibot.py`
==============
This example uses only the pure, "bare-metal" API wrapper.
.. literalinclude:: ../../examples/rawapibot.py
:language: python
:linenos:

194
docs/source/examples.rst Normal file
View file

@ -0,0 +1,194 @@
Examples
========
In this section we display 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
:any:`examples.rawapibot` example, they all use the high-level
framework this library provides with the
:any:`telegram.ext <telegram.ext>` submodule.
All examples are licensed under the `CC0
License <https://github.com/python-telegram-bot/python-telegram-bot/blob/master/examples/LICENSE.txt>`__
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.
:any:`examples.echobot`
-----------------------
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.
:any:`examples.timerbot`
------------------------
This bot uses the
:class:`telegram.ext.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 <https://github.com/python-telegram-bot/python-telegram-bot/wiki/Extensions-%E2%80%93-JobQueue>`__.
:any:`examples.conversationbot`
-------------------------------
A common task for a bot is to ask information from the user. In v5.0 of
this library, we introduced the
:class:`telegram.ext.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 :ref:`state diagrem <conversationbot-diagram>`.
:any:`examples.conversationbot2`
--------------------------------
A more complex example of a bot that uses the ``ConversationHandler``.
It is also more confusing. Good thing there is a :ref:`fancy state diagram <conversationbot2-diagram>`.
for this one, too!
:any:`examples.nestedconversationbot`
-------------------------------------
A even more complex example of a bot that uses the nested
``ConversationHandler``\ s. While its certainly not that complex that
you couldnt built it without nested ``ConversationHanldler``\ s, it
gives a good impression on how to work with them. Of course, there is a
:ref:`fancy state diagram <nestedconversationbot-diagram>`
for this example, too!
:any:`examples.persistentconversationbot`
-----------------------------------------
A basic example of a bot store conversation state and user_data over
multiple restarts.
:any:`examples.inlinekeyboard`
------------------------------
This example sheds some light on inline keyboards, callback queries and
message editing. A wiki site explaining this examples lives
`here <https://github.com/python-telegram-bot/python-telegram-bot/wiki/InlineKeyboard-Example>`__.
:any:`examples.inlinekeyboard2`
-------------------------------
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.
:any:`examples.deeplinking`
---------------------------
A basic example on how to use deeplinking with inline keyboards.
:any:`examples.inlinebot`
-------------------------
A basic example of an `inline
bot <https://core.telegram.org/bots/inline>`__. Dont forget to enable
inline mode with `@BotFather <https://telegram.me/BotFather>`_.
:any:`examples.pollbot`
-----------------------
This example sheds some light on polls, poll answers and the
corresponding handlers.
:any:`examples.passportbot`
---------------------------
A basic example of a bot that can accept passports. Use in combination
with the :ref:`HTML page <passportbot-html>`.
Dont forget to enable and configure payments with
`@BotFather <https://telegram.me/BotFather>`_. Check out this
`guide <https://github.com/python-telegram-bot/python-telegram-bot/wiki/Telegram-Passport>`__
on Telegram passports in PTB.
:any:`examples.paymentbot`
--------------------------
A basic example of a bot that can accept payments. Dont forget to
enable and configure payments with
`@BotFather <https://telegram.me/BotFather>`_.
:any:`examples.errorhandlerbot`
-------------------------------
A basic example on how to set up a custom error handler.
:any:`examples.chatmemberbot`
-----------------------------
A basic example on how ``(my_)chat_member`` updates can be used.
:any:`examples.webappbot`
-------------------------
A basic example of how `Telegram
WebApps <https://core.telegram.org/bots/webapps>`__ can be used. Use in
combination with the :ref:`HTML page <webappbot-html>`.
For your convenience, this file is hosted by the PTB team such that you
dont need to host it yourself. Uses the
`iro.js <https://iro.js.org>`__ JavaScript library to showcase a
user interface that is hard to achieve with native Telegram
functionality.
:any:`examples.contexttypesbot`
-------------------------------
This example showcases how ``telegram.ext.ContextTypes`` can be used to
customize the ``context`` argument of handler and job callbacks.
:any:`examples.customwebhookbot`
--------------------------------
This example showcases how a custom webhook setup can be used in
combination with ``telegram.ext.Application``.
:any:`examples.arbitrarycallbackdatabot`
----------------------------------------
This example showcases how PTBs “arbitrary callback data” feature can be
used.
Pure API
--------
The :any:`examples.rawapibot` example example uses only the pure, “bare-metal” API wrapper.
.. toctree::
:hidden:
examples.arbitrarycallbackdatabot
examples.chatmemberbot
examples.contexttypesbot
examples.conversationbot
examples.conversationbot2
examples.customwebhookbot
examples.deeplinking
examples.echobot
examples.errorhandlerbot
examples.inlinebot
examples.inlinekeyboard
examples.inlinekeyboard2
examples.nestedconversationbot
examples.passportbot
examples.paymentbot
examples.persistentconversationbot
examples.pollbot
examples.rawapibot
examples.timerbot
examples.webappbot

View file

@ -0,0 +1,7 @@
``timerbot.py``
===============
.. literalinclude:: ../../examples/timerbot.py
:language: python
:linenos:

View file

@ -0,0 +1,16 @@
``webappbot.py``
================
.. literalinclude:: ../../examples/webappbot.py
:language: python
:linenos:
.. _webappbot-html:
HTML Page
---------
.. literalinclude:: ../../examples/webappbot.html
:language: html
:linenos:

View file

@ -5,7 +5,7 @@
.. include:: ../../README.rst .. include:: ../../README.rst
.. The toctrees are hidden such that they don't reander on the start page but still include the contents into the documentation. .. The toctrees are hidden such that they don't render on the start page but still include the contents into the documentation.
.. toctree:: .. toctree::
:hidden: :hidden:
@ -16,6 +16,13 @@
telegram_auxil telegram_auxil
Telegrams Bot API Docs <https://core.telegram.org/bots/api> Telegrams Bot API Docs <https://core.telegram.org/bots/api>
.. toctree::
:hidden:
:caption: Resources
examples
Wiki <https://github.com/python-telegram-bot/python-telegram-bot/wiki>
.. toctree:: .. toctree::
:hidden: :hidden:
:caption: Project :caption: Project

View file

@ -1,71 +1,5 @@
# Examples # Examples
## ⚠️ The examples in this directory are subject to changes and may not work on the PTB version that you are using. You can find the examples compatible with a specific version at https://github.com/python-telegram-bot/python-telegram-bot/tree/v<X.Y>/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`](#pure-api) example, they all use the high-level framework this library provides with the [`telegram.ext`](https://docs.python-telegram-bot.org/telegram.ext.html) submodule. A description of the examples in this directory can be found in the [documentation](https://docs.python-telegram-bot.org/examples.html).
All examples are licensed under the [CC0 License](LICENSE.txt) and are therefore fully dedicated to the public domain. You can use them as the base for your own bots without worrying about copyrights. All examples are licensed under the [CC0 License](https://github.com/python-telegram-bot/python-telegram-bot/blob/master/examples/LICENSE.txt) 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`](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`](timerbot.py)
This bot uses the [`JobQueue`](https://docs.python-telegram-bot.org/telegram.ext.jobqueue.html) 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](https://github.com/python-telegram-bot/python-telegram-bot/wiki/Extensions-%E2%80%93-JobQueue).
### [`conversationbot.py`](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`](https://docs.python-telegram-bot.org/telegram.ext.conversationhandler.html) 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](conversationbot.png).
### [`conversationbot2.py`](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](conversationbot2.png) for this one, too!
### [`nestedconversationbot.py`](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](nestedconversationbot.png) for this example, too!
### [`persistentconversationbot.py`](persistentconversationbot.py)
A basic example of a bot store conversation state and user_data over multiple restarts.
### [`inlinekeyboard.py`](inlinekeyboard.py)
This example sheds some light on inline keyboards, callback queries and message editing. A wiki site explaining this examples lives [here](https://github.com/python-telegram-bot/python-telegram-bot/wiki/InlineKeyboard-Example).
### [`inlinekeyboard2.py`](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`](deeplinking.py)
A basic example on how to use deeplinking with inline keyboards.
### [`inlinebot.py`](inlinebot.py)
A basic example of an [inline bot](https://core.telegram.org/bots/inline). Don't forget to enable inline mode with [@BotFather](https://t.me/BotFather).
### [`pollbot.py`](pollbot.py)
This example sheds some light on polls, poll answers and the corresponding handlers.
### [`passportbot.py`](passportbot.py)
A basic example of a bot that can accept passports. Use in combination with [`passportbot.html`](passportbot.html). Don't forget to enable and configure payments with [@BotFather](https://t.me/BotFather). Check out this [guide](https://github.com/python-telegram-bot/python-telegram-bot/wiki/Telegram-Passport) on Telegram passports in PTB.
### [`paymentbot.py`](paymentbot.py)
A basic example of a bot that can accept payments. Don't forget to enable and configure payments with [@BotFather](https://t.me/BotFather).
### [`errorhandlerbot.py`](errorhandlerbot.py)
A basic example on how to set up a custom error handler.
### [`chatmemberbot.py`](chatmemberbot.py)
A basic example on how `(my_)chat_member` updates can be used.
### [`webappbot.py`](webappbot.py)
A basic example of how [Telegram WebApps](https://core.telegram.org/bots/webapps) can be used.
Use in combination with [`webappbot.html`](webappbot.html).
For your convenience, this file is hosted by the PTB team such that you don't need to host it yourself.
Uses the [`iro.js`](https://iro.js.org) JavaScript library to showcase a user interface that is hard to achieve with native Telegram functionality.
### [`contexttypesbot.py`](contexttypesbot.py)
This example showcases how `telegram.ext.ContextTypes` can be used to customize the `context` argument of handler and job callbacks.
### [`customwebhookbot.py`](customwebhookbot.py)
This example showcases how a custom webhook setup can be used in combination with `telegram.ext.Application`.
### [`arbitrarycallbackdatabot.py`](arbitrarycallbackdatabot.py)
This example showcases how PTBs "arbitrary callback data" feature can be used.
## Pure API
The [`rawapibot.py`](rawapibot.py) example uses only the pure, "bare-metal" API wrapper.

View file

@ -21,7 +21,7 @@ if __version_info__ < (20, 0, 0, "alpha", 1):
raise RuntimeError( raise RuntimeError(
f"This example is not compatible with your current PTB version {TG_VER}. To view the " f"This example is not compatible with your current PTB version {TG_VER}. To view the "
f"{TG_VER} version of this example, " f"{TG_VER} version of this example, "
f"visit https://github.com/python-telegram-bot/python-telegram-bot/tree/v{TG_VER}/examples" f"visit https://docs.python-telegram-bot.org/en/v{TG_VER}/examples.html"
) )
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update
from telegram.ext import ( from telegram.ext import (

View file

@ -25,7 +25,7 @@ if __version_info__ < (20, 0, 0, "alpha", 1):
raise RuntimeError( raise RuntimeError(
f"This example is not compatible with your current PTB version {TG_VER}. To view the " f"This example is not compatible with your current PTB version {TG_VER}. To view the "
f"{TG_VER} version of this example, " f"{TG_VER} version of this example, "
f"visit https://github.com/python-telegram-bot/python-telegram-bot/tree/v{TG_VER}/examples" f"visit https://docs.python-telegram-bot.org/en/v{TG_VER}/examples.html"
) )
from telegram import Chat, ChatMember, ChatMemberUpdated, Update from telegram import Chat, ChatMember, ChatMemberUpdated, Update
from telegram.constants import ParseMode from telegram.constants import ParseMode

View file

@ -25,7 +25,7 @@ if __version_info__ < (20, 0, 0, "alpha", 1):
raise RuntimeError( raise RuntimeError(
f"This example is not compatible with your current PTB version {TG_VER}. To view the " f"This example is not compatible with your current PTB version {TG_VER}. To view the "
f"{TG_VER} version of this example, " f"{TG_VER} version of this example, "
f"visit https://github.com/python-telegram-bot/python-telegram-bot/tree/v{TG_VER}/examples" f"visit https://docs.python-telegram-bot.org/en/v{TG_VER}/examples.html"
) )
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update
from telegram.constants import ParseMode from telegram.constants import ParseMode

View file

@ -27,7 +27,7 @@ if __version_info__ < (20, 0, 0, "alpha", 1):
raise RuntimeError( raise RuntimeError(
f"This example is not compatible with your current PTB version {TG_VER}. To view the " f"This example is not compatible with your current PTB version {TG_VER}. To view the "
f"{TG_VER} version of this example, " f"{TG_VER} version of this example, "
f"visit https://github.com/python-telegram-bot/python-telegram-bot/tree/v{TG_VER}/examples" f"visit https://docs.python-telegram-bot.org/en/v{TG_VER}/examples.html"
) )
from telegram import ReplyKeyboardMarkup, ReplyKeyboardRemove, Update from telegram import ReplyKeyboardMarkup, ReplyKeyboardRemove, Update
from telegram.ext import ( from telegram.ext import (

View file

@ -28,7 +28,7 @@ if __version_info__ < (20, 0, 0, "alpha", 1):
raise RuntimeError( raise RuntimeError(
f"This example is not compatible with your current PTB version {TG_VER}. To view the " f"This example is not compatible with your current PTB version {TG_VER}. To view the "
f"{TG_VER} version of this example, " f"{TG_VER} version of this example, "
f"visit https://github.com/python-telegram-bot/python-telegram-bot/tree/v{TG_VER}/examples" f"visit https://docs.python-telegram-bot.org/en/v{TG_VER}/examples.html"
) )
from telegram import ReplyKeyboardMarkup, ReplyKeyboardRemove, Update from telegram import ReplyKeyboardMarkup, ReplyKeyboardRemove, Update
from telegram.ext import ( from telegram.ext import (

View file

@ -36,7 +36,7 @@ if __version_info__ < (20, 0, 0, "alpha", 1):
raise RuntimeError( raise RuntimeError(
f"This example is not compatible with your current PTB version {TG_VER}. To view the " f"This example is not compatible with your current PTB version {TG_VER}. To view the "
f"{TG_VER} version of this example, " f"{TG_VER} version of this example, "
f"visit https://github.com/python-telegram-bot/python-telegram-bot/tree/v{TG_VER}/examples" f"visit https://docs.python-telegram-bot.org/en/v{TG_VER}/examples.html"
) )
from telegram import Update from telegram import Update

View file

@ -31,7 +31,7 @@ if __version_info__ < (20, 0, 0, "alpha", 1):
raise RuntimeError( raise RuntimeError(
f"This example is not compatible with your current PTB version {TG_VER}. To view the " f"This example is not compatible with your current PTB version {TG_VER}. To view the "
f"{TG_VER} version of this example, " f"{TG_VER} version of this example, "
f"visit https://github.com/python-telegram-bot/python-telegram-bot/tree/v{TG_VER}/examples" f"visit https://docs.python-telegram-bot.org/en/v{TG_VER}/examples.html"
) )
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update, helpers from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update, helpers
from telegram.constants import ParseMode from telegram.constants import ParseMode

View file

@ -28,7 +28,7 @@ if __version_info__ < (20, 0, 0, "alpha", 1):
raise RuntimeError( raise RuntimeError(
f"This example is not compatible with your current PTB version {TG_VER}. To view the " f"This example is not compatible with your current PTB version {TG_VER}. To view the "
f"{TG_VER} version of this example, " f"{TG_VER} version of this example, "
f"visit https://github.com/python-telegram-bot/python-telegram-bot/tree/v{TG_VER}/examples" f"visit https://docs.python-telegram-bot.org/en/v{TG_VER}/examples.html"
) )
from telegram import ForceReply, Update from telegram import ForceReply, Update
from telegram.ext import Application, CommandHandler, ContextTypes, MessageHandler, filters from telegram.ext import Application, CommandHandler, ContextTypes, MessageHandler, filters

View file

@ -19,7 +19,7 @@ if __version_info__ < (20, 0, 0, "alpha", 1):
raise RuntimeError( raise RuntimeError(
f"This example is not compatible with your current PTB version {TG_VER}. To view the " f"This example is not compatible with your current PTB version {TG_VER}. To view the "
f"{TG_VER} version of this example, " f"{TG_VER} version of this example, "
f"visit https://github.com/python-telegram-bot/python-telegram-bot/tree/v{TG_VER}/examples" f"visit https://docs.python-telegram-bot.org/en/v{TG_VER}/examples.html"
) )
from telegram import Update from telegram import Update
from telegram.constants import ParseMode from telegram.constants import ParseMode

View file

@ -29,7 +29,7 @@ if __version_info__ < (20, 0, 0, "alpha", 1):
raise RuntimeError( raise RuntimeError(
f"This example is not compatible with your current PTB version {TG_VER}. To view the " f"This example is not compatible with your current PTB version {TG_VER}. To view the "
f"{TG_VER} version of this example, " f"{TG_VER} version of this example, "
f"visit https://github.com/python-telegram-bot/python-telegram-bot/tree/v{TG_VER}/examples" f"visit https://docs.python-telegram-bot.org/en/v{TG_VER}/examples.html"
) )
from telegram import InlineQueryResultArticle, InputTextMessageContent, Update from telegram import InlineQueryResultArticle, InputTextMessageContent, Update
from telegram.constants import ParseMode from telegram.constants import ParseMode

View file

@ -19,7 +19,7 @@ if __version_info__ < (20, 0, 0, "alpha", 1):
raise RuntimeError( raise RuntimeError(
f"This example is not compatible with your current PTB version {TG_VER}. To view the " f"This example is not compatible with your current PTB version {TG_VER}. To view the "
f"{TG_VER} version of this example, " f"{TG_VER} version of this example, "
f"visit https://github.com/python-telegram-bot/python-telegram-bot/tree/v{TG_VER}/examples" f"visit https://docs.python-telegram-bot.org/en/v{TG_VER}/examples.html"
) )
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update
from telegram.ext import Application, CallbackQueryHandler, CommandHandler, ContextTypes from telegram.ext import Application, CallbackQueryHandler, CommandHandler, ContextTypes

View file

@ -27,7 +27,7 @@ if __version_info__ < (20, 0, 0, "alpha", 1):
raise RuntimeError( raise RuntimeError(
f"This example is not compatible with your current PTB version {TG_VER}. To view the " f"This example is not compatible with your current PTB version {TG_VER}. To view the "
f"{TG_VER} version of this example, " f"{TG_VER} version of this example, "
f"visit https://github.com/python-telegram-bot/python-telegram-bot/tree/v{TG_VER}/examples" f"visit https://docs.python-telegram-bot.org/en/v{TG_VER}/examples.html"
) )
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update
from telegram.ext import ( from telegram.ext import (

View file

@ -28,7 +28,7 @@ if __version_info__ < (20, 0, 0, "alpha", 1):
raise RuntimeError( raise RuntimeError(
f"This example is not compatible with your current PTB version {TG_VER}. To view the " f"This example is not compatible with your current PTB version {TG_VER}. To view the "
f"{TG_VER} version of this example, " f"{TG_VER} version of this example, "
f"visit https://github.com/python-telegram-bot/python-telegram-bot/tree/v{TG_VER}/examples" f"visit https://docs.python-telegram-bot.org/en/v{TG_VER}/examples.html"
) )
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update
from telegram.ext import ( from telegram.ext import (

View file

@ -25,7 +25,7 @@ if __version_info__ < (20, 0, 0, "alpha", 1):
raise RuntimeError( raise RuntimeError(
f"This example is not compatible with your current PTB version {TG_VER}. To view the " f"This example is not compatible with your current PTB version {TG_VER}. To view the "
f"{TG_VER} version of this example, " f"{TG_VER} version of this example, "
f"visit https://github.com/python-telegram-bot/python-telegram-bot/tree/v{TG_VER}/examples" f"visit https://docs.python-telegram-bot.org/en/v{TG_VER}/examples.html"
) )
from telegram import Update from telegram import Update
from telegram.ext import Application, ContextTypes, MessageHandler, filters from telegram.ext import Application, ContextTypes, MessageHandler, filters

View file

@ -17,7 +17,7 @@ if __version_info__ < (20, 0, 0, "alpha", 1):
raise RuntimeError( raise RuntimeError(
f"This example is not compatible with your current PTB version {TG_VER}. To view the " f"This example is not compatible with your current PTB version {TG_VER}. To view the "
f"{TG_VER} version of this example, " f"{TG_VER} version of this example, "
f"visit https://github.com/python-telegram-bot/python-telegram-bot/tree/v{TG_VER}/examples" f"visit https://docs.python-telegram-bot.org/en/v{TG_VER}/examples.html"
) )
from telegram import LabeledPrice, ShippingOption, Update from telegram import LabeledPrice, ShippingOption, Update
from telegram.ext import ( from telegram.ext import (

View file

@ -28,7 +28,7 @@ if __version_info__ < (20, 0, 0, "alpha", 1):
raise RuntimeError( raise RuntimeError(
f"This example is not compatible with your current PTB version {TG_VER}. To view the " f"This example is not compatible with your current PTB version {TG_VER}. To view the "
f"{TG_VER} version of this example, " f"{TG_VER} version of this example, "
f"visit https://github.com/python-telegram-bot/python-telegram-bot/tree/v{TG_VER}/examples" f"visit https://docs.python-telegram-bot.org/en/v{TG_VER}/examples.html"
) )
from telegram import ReplyKeyboardMarkup, ReplyKeyboardRemove, Update from telegram import ReplyKeyboardMarkup, ReplyKeyboardRemove, Update
from telegram.ext import ( from telegram.ext import (

View file

@ -20,7 +20,7 @@ if __version_info__ < (20, 0, 0, "alpha", 1):
raise RuntimeError( raise RuntimeError(
f"This example is not compatible with your current PTB version {TG_VER}. To view the " f"This example is not compatible with your current PTB version {TG_VER}. To view the "
f"{TG_VER} version of this example, " f"{TG_VER} version of this example, "
f"visit https://github.com/python-telegram-bot/python-telegram-bot/tree/v{TG_VER}/examples" f"visit https://docs.python-telegram-bot.org/en/v{TG_VER}/examples.html"
) )
from telegram import ( from telegram import (
KeyboardButton, KeyboardButton,

View file

@ -21,7 +21,7 @@ if __version_info__ < (20, 0, 0, "alpha", 1):
raise RuntimeError( raise RuntimeError(
f"This example is not compatible with your current PTB version {TG_VER}. To view the " f"This example is not compatible with your current PTB version {TG_VER}. To view the "
f"{TG_VER} version of this example, " f"{TG_VER} version of this example, "
f"visit https://github.com/python-telegram-bot/python-telegram-bot/tree/v{TG_VER}/examples" f"visit https://docs.python-telegram-bot.org/en/v{TG_VER}/examples.html"
) )
from telegram import Bot from telegram import Bot
from telegram.error import Forbidden, NetworkError from telegram.error import Forbidden, NetworkError

View file

@ -31,7 +31,7 @@ if __version_info__ < (20, 0, 0, "alpha", 1):
raise RuntimeError( raise RuntimeError(
f"This example is not compatible with your current PTB version {TG_VER}. To view the " f"This example is not compatible with your current PTB version {TG_VER}. To view the "
f"{TG_VER} version of this example, " f"{TG_VER} version of this example, "
f"visit https://github.com/python-telegram-bot/python-telegram-bot/tree/v{TG_VER}/examples" f"visit https://docs.python-telegram-bot.org/en/v{TG_VER}/examples.html"
) )
from telegram import Update from telegram import Update
from telegram.ext import Application, CommandHandler, ContextTypes from telegram.ext import Application, CommandHandler, ContextTypes

View file

@ -22,7 +22,7 @@ if __version_info__ < (20, 0, 0, "alpha", 1):
raise RuntimeError( raise RuntimeError(
f"This example is not compatible with your current PTB version {TG_VER}. To view the " f"This example is not compatible with your current PTB version {TG_VER}. To view the "
f"{TG_VER} version of this example, " f"{TG_VER} version of this example, "
f"visit https://github.com/python-telegram-bot/python-telegram-bot/tree/v{TG_VER}/examples" f"visit https://docs.python-telegram-bot.org/en/v{TG_VER}/examples.html"
) )
from telegram import KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove, Update, WebAppInfo from telegram import KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove, Update, WebAppInfo
from telegram.ext import Application, CommandHandler, ContextTypes, MessageHandler, filters from telegram.ext import Application, CommandHandler, ContextTypes, MessageHandler, filters

View file

@ -644,8 +644,7 @@ class ApplicationBuilder(Generic[BT, CCT, UD, CD, BD, JQ]):
"""Sets the private key and corresponding password for decryption of telegram passport data """Sets the private key and corresponding password for decryption of telegram passport data
for :attr:`telegram.ext.Application.bot`. for :attr:`telegram.ext.Application.bot`.
.. seealso:: `passportbot.py <https://github.com/python-telegram-bot/python-telegram-bot\ .. seealso:: :any:`examples.passportbot`, `Telegram Passports
/tree/master/examples#passportbotpy>`_, `Telegram Passports
<https://github.com/python-telegram-bot/python-telegram-bot/wiki/Telegram-Passport>`_ <https://github.com/python-telegram-bot/python-telegram-bot/wiki/Telegram-Passport>`_
Args: Args:
@ -704,8 +703,7 @@ class ApplicationBuilder(Generic[BT, CCT, UD, CD, BD, JQ]):
.. seealso:: `Arbitrary callback_data <https://github.com/python-telegram-bot\ .. seealso:: `Arbitrary callback_data <https://github.com/python-telegram-bot\
/python-telegram-bot/wiki/Arbitrary-callback_data>`_, /python-telegram-bot/wiki/Arbitrary-callback_data>`_,
`arbitrarycallbackdatabot.py <https://github.com/python-telegram-bot\ :any:`examples.arbitrarycallbackdatabot`
/python-telegram-bot/tree/master/examples#arbitrarycallbackdatabotpy>`_
Args: Args:
arbitrary_callback_data (:obj:`bool` | :obj:`int`): If :obj:`True` is passed, the arbitrary_callback_data (:obj:`bool` | :obj:`int`): If :obj:`True` is passed, the
@ -794,8 +792,7 @@ class ApplicationBuilder(Generic[BT, CCT, UD, CD, BD, JQ]):
instantiated. instantiated.
.. seealso:: `JobQueue <https://github.com/python-telegram-bot/python-telegram-bot/wiki\ .. seealso:: `JobQueue <https://github.com/python-telegram-bot/python-telegram-bot/wiki\
/Extensions-%E2%80%93-JobQueue>`_, `timerbot.py <https://github.com\ /Extensions-%E2%80%93-JobQueue>`_, :any:`examples.timerbot`
/python-telegram-bot/python-telegram-bot/tree/master/examples#timerbotpy>`_
Note: Note:
* :meth:`telegram.ext.JobQueue.set_application` will be called automatically by * :meth:`telegram.ext.JobQueue.set_application` will be called automatically by
@ -832,8 +829,7 @@ class ApplicationBuilder(Generic[BT, CCT, UD, CD, BD, JQ]):
.. seealso:: `Making your bot persistent <https://github.com/python-telegram-bot\ .. seealso:: `Making your bot persistent <https://github.com/python-telegram-bot\
/python-telegram-bot/wiki/Making-your-bot-persistent>`_, /python-telegram-bot/wiki/Making-your-bot-persistent>`_,
`persistentconversationbot.py <https://github.com/python-telegram-bot\ :any:`examples.persistentconversationbot`
/python-telegram-bot/tree/master/examples#persistentconversationbotpy>`_
Warning: Warning:
If a :class:`telegram.ext.ContextTypes` instance is set via :meth:`context_types`, If a :class:`telegram.ext.ContextTypes` instance is set via :meth:`context_types`,
@ -855,8 +851,7 @@ class ApplicationBuilder(Generic[BT, CCT, UD, CD, BD, JQ]):
"""Sets a :class:`telegram.ext.ContextTypes` instance for """Sets a :class:`telegram.ext.ContextTypes` instance for
:attr:`telegram.ext.Application.context_types`. :attr:`telegram.ext.Application.context_types`.
.. seealso:: `contexttypesbot.py <https://github.com/python-telegram-bot\ .. seealso:: :any:`examples.contexttypesbot`
/python-telegram-bot/tree/master/examples#contexttypesbotpy>`_
Args: Args:
context_types (:class:`telegram.ext.ContextTypes`): The context types. context_types (:class:`telegram.ext.ContextTypes`): The context types.

View file

@ -183,10 +183,8 @@ class ConversationHandler(BaseHandler[Update, CCT]):
attribute or else the latter will be ignored. You may map :attr:`END` to one of the parents attribute or else the latter will be ignored. You may map :attr:`END` to one of the parents
states to continue the parent conversation after the child conversation has ended or even states to continue the parent conversation after the child conversation has ended or even
map a state to :attr:`END` to end the *parent* conversation from within the child map a state to :attr:`END` to end the *parent* conversation from within the child
conversation. For an example on nested :class:`ConversationHandler` s, see our `examples`_. conversation. For an example on nested :class:`ConversationHandler` s, see
:any:`examples.conversationbot`.
.. _`examples`: https://github.com/python-telegram-bot/python-telegram-bot/tree/master\
/examples#examples
Args: Args:
entry_points (List[:class:`telegram.ext.BaseHandler`]): A list of :obj:`BaseHandler` entry_points (List[:class:`telegram.ext.BaseHandler`]): A list of :obj:`BaseHandler`