GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add Version Check to Examples (#3036) · MSutt/python-telegram-bot@3013870

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • .github/workflows
    • example_notifier.yml
  • examples
    • README.md
    • arbitrarycallbackdatabot.py
    • chatmemberbot.py
    • contexttypesbot.py
    • conversationbot.py
    • conversationbot2.py
    • deeplinking.py
    • echobot.py
    • errorhandlerbot.py
    • inlinebot.py
    • inlinekeyboard.py
    • inlinekeyboard2.py
    • nestedconversationbot.py
    • passportbot.py
    • paymentbot.py
    • persistentconversationbot.py
    • pollbot.py
    • rawapibot.py
    • timerbot.py
  • telegram
    • _bot.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.github/workflows/example_notifier.yml‎

Copy file name to clipboardExpand all lines: .github/workflows/example_notifier.yml
-16Lines changed: 0 additions & 16 deletions
This file was deleted.
Collapse file

‎examples/README.md‎

Copy file name to clipboardExpand all lines: examples/README.md
+3-2Lines changed: 3 additions & 2 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
# Examples
2+
## ⚠️ 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
23

34
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://python-telegram-bot.readthedocs.io/en/latest/telegram.ext.html) submodule.
45

56
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.
67

78
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.
89

9-
### [`echobot.py`](https://github.com/python-telegram-bot/python-telegram-bot/blob/master/examples/echobot.py)
10+
### [`echobot.py`](https://github.com/python-telegram-bot/python-telegram-bot/blob/master/examples/echobot.py)
1011
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.
1112

12-
### [`timerbot.py`](https://github.com/python-telegram-bot/python-telegram-bot/blob/master/examples/timerbot.py)
13+
### [`timerbot.py`](https://github.com/python-telegram-bot/python-telegram-bot/blob/master/examples/timerbot.py)
1314
This bot uses the [`JobQueue`](https://python-telegram-bot.readthedocs.io/en/latest/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).
1415

1516
### [`conversationbot.py`](https://github.com/python-telegram-bot/python-telegram-bot/blob/master/examples/conversationbot.py)
Collapse file

‎examples/arbitrarycallbackdatabot.py‎

Copy file name to clipboardExpand all lines: examples/arbitrarycallbackdatabot.py
+14-1Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
# pylint: disable=unused-argument
2+
# pylint: disable=unused-argument, wrong-import-position
33
# This program is dedicated to the public domain under the CC0 license.
44

55
"""This example showcases how PTBs "arbitrary callback data" feature can be used.
@@ -10,6 +10,19 @@
1010
import logging
1111
from typing import List, Tuple, cast
1212

13+
from telegram import __version__ as TG_VER
14+
15+
try:
16+
from telegram import __version_info__
17+
except ImportError:
18+
__version_info__ = (0, 0, 0, 0, 0) # type: ignore[assignment]
19+
20+
if __version_info__ < (20, 0, 0, "alpha", 1):
21+
raise RuntimeError(
22+
f"This example is not compatible with your current PTB version {TG_VER}. To view the "
23+
f"{TG_VER} version of this example, "
24+
f"visit https://github.com/python-telegram-bot/python-telegram-bot/tree/v{TG_VER}/examples"
25+
)
1326
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update
1427
from telegram.ext import (
1528
Application,
Collapse file

‎examples/chatmemberbot.py‎

Copy file name to clipboardExpand all lines: examples/chatmemberbot.py
+14-1Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
# pylint: disable=unused-argument
2+
# pylint: disable=unused-argument, wrong-import-position
33
# This program is dedicated to the public domain under the CC0 license.
44

55
"""
@@ -14,6 +14,19 @@
1414
import logging
1515
from typing import Optional, Tuple
1616

17+
from telegram import __version__ as TG_VER
18+
19+
try:
20+
from telegram import __version_info__
21+
except ImportError:
22+
__version_info__ = (0, 0, 0, 0, 0) # type: ignore[assignment]
23+
24+
if __version_info__ < (20, 0, 0, "alpha", 1):
25+
raise RuntimeError(
26+
f"This example is not compatible with your current PTB version {TG_VER}. To view the "
27+
f"{TG_VER} version of this example, "
28+
f"visit https://github.com/python-telegram-bot/python-telegram-bot/tree/v{TG_VER}/examples"
29+
)
1730
from telegram import Chat, ChatMember, ChatMemberUpdated, Update
1831
from telegram.constants import ParseMode
1932
from telegram.ext import Application, ChatMemberHandler, CommandHandler, ContextTypes
Collapse file

‎examples/contexttypesbot.py‎

Copy file name to clipboardExpand all lines: examples/contexttypesbot.py
+14-1Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
# pylint: disable=unused-argument
2+
# pylint: disable=unused-argument, wrong-import-position
33
# This program is dedicated to the public domain under the CC0 license.
44

55
"""
@@ -14,6 +14,19 @@
1414
from collections import defaultdict
1515
from typing import DefaultDict, Optional, Set
1616

17+
from telegram import __version__ as TG_VER
18+
19+
try:
20+
from telegram import __version_info__
21+
except ImportError:
22+
__version_info__ = (0, 0, 0, 0, 0) # type: ignore[assignment]
23+
24+
if __version_info__ < (20, 0, 0, "alpha", 1):
25+
raise RuntimeError(
26+
f"This example is not compatible with your current PTB version {TG_VER}. To view the "
27+
f"{TG_VER} version of this example, "
28+
f"visit https://github.com/python-telegram-bot/python-telegram-bot/tree/v{TG_VER}/examples"
29+
)
1730
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update
1831
from telegram.constants import ParseMode
1932
from telegram.ext import (
Collapse file

‎examples/conversationbot.py‎

Copy file name to clipboardExpand all lines: examples/conversationbot.py
+14-1Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
# pylint: disable=unused-argument
2+
# pylint: disable=unused-argument, wrong-import-position
33
# This program is dedicated to the public domain under the CC0 license.
44

55
"""
@@ -16,6 +16,19 @@
1616

1717
import logging
1818

19+
from telegram import __version__ as TG_VER
20+
21+
try:
22+
from telegram import __version_info__
23+
except ImportError:
24+
__version_info__ = (0, 0, 0, 0, 0) # type: ignore[assignment]
25+
26+
if __version_info__ < (20, 0, 0, "alpha", 1):
27+
raise RuntimeError(
28+
f"This example is not compatible with your current PTB version {TG_VER}. To view the "
29+
f"{TG_VER} version of this example, "
30+
f"visit https://github.com/python-telegram-bot/python-telegram-bot/tree/v{TG_VER}/examples"
31+
)
1932
from telegram import ReplyKeyboardMarkup, ReplyKeyboardRemove, Update
2033
from telegram.ext import (
2134
Application,
Collapse file

‎examples/conversationbot2.py‎

Copy file name to clipboardExpand all lines: examples/conversationbot2.py
+14-1Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
# pylint: disable=unused-argument
2+
# pylint: disable=unused-argument, wrong-import-position
33
# This program is dedicated to the public domain under the CC0 license.
44

55
"""
@@ -17,6 +17,19 @@
1717
import logging
1818
from typing import Dict
1919

20+
from telegram import __version__ as TG_VER
21+
22+
try:
23+
from telegram import __version_info__
24+
except ImportError:
25+
__version_info__ = (0, 0, 0, 0, 0) # type: ignore[assignment]
26+
27+
if __version_info__ < (20, 0, 0, "alpha", 1):
28+
raise RuntimeError(
29+
f"This example is not compatible with your current PTB version {TG_VER}. To view the "
30+
f"{TG_VER} version of this example, "
31+
f"visit https://github.com/python-telegram-bot/python-telegram-bot/tree/v{TG_VER}/examples"
32+
)
2033
from telegram import ReplyKeyboardMarkup, ReplyKeyboardRemove, Update
2134
from telegram.ext import (
2235
Application,
Collapse file

‎examples/deeplinking.py‎

Copy file name to clipboardExpand all lines: examples/deeplinking.py
+14-1Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
# pylint: disable=unused-argument
2+
# pylint: disable=unused-argument, wrong-import-position
33
# This program is dedicated to the public domain under the CC0 license.
44

55
"""Bot that explains Telegram's "Deep Linking Parameters" functionality.
@@ -20,6 +20,19 @@
2020

2121
import logging
2222

23+
from telegram import __version__ as TG_VER
24+
25+
try:
26+
from telegram import __version_info__
27+
except ImportError:
28+
__version_info__ = (0, 0, 0, 0, 0) # type: ignore[assignment]
29+
30+
if __version_info__ < (20, 0, 0, "alpha", 1):
31+
raise RuntimeError(
32+
f"This example is not compatible with your current PTB version {TG_VER}. To view the "
33+
f"{TG_VER} version of this example, "
34+
f"visit https://github.com/python-telegram-bot/python-telegram-bot/tree/v{TG_VER}/examples"
35+
)
2336
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update, helpers
2437
from telegram.constants import ParseMode
2538
from telegram.ext import Application, CallbackQueryHandler, CommandHandler, ContextTypes, filters
Collapse file

‎examples/echobot.py‎

Copy file name to clipboardExpand all lines: examples/echobot.py
+14-1Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
# pylint: disable=unused-argument
2+
# pylint: disable=unused-argument, wrong-import-position
33
# This program is dedicated to the public domain under the CC0 license.
44

55
"""
@@ -17,6 +17,19 @@
1717

1818
import logging
1919

20+
from telegram import __version__ as TG_VER
21+
22+
try:
23+
from telegram import __version_info__
24+
except ImportError:
25+
__version_info__ = (0, 0, 0, 0, 0) # type: ignore[assignment]
26+
27+
if __version_info__ < (20, 0, 0, "alpha", 1):
28+
raise RuntimeError(
29+
f"This example is not compatible with your current PTB version {TG_VER}. To view the "
30+
f"{TG_VER} version of this example, "
31+
f"visit https://github.com/python-telegram-bot/python-telegram-bot/tree/v{TG_VER}/examples"
32+
)
2033
from telegram import ForceReply, Update
2134
from telegram.ext import Application, CommandHandler, ContextTypes, MessageHandler, filters
2235

Collapse file

‎examples/errorhandlerbot.py‎

Copy file name to clipboardExpand all lines: examples/errorhandlerbot.py
+14-1Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
# pylint: disable=unused-argument
2+
# pylint: disable=unused-argument, wrong-import-position
33
# This program is dedicated to the public domain under the CC0 license.
44

55
"""This is a very simple example on how one could implement a custom error handler."""
@@ -8,6 +8,19 @@
88
import logging
99
import traceback
1010

11+
from telegram import __version__ as TG_VER
12+
13+
try:
14+
from telegram import __version_info__
15+
except ImportError:
16+
__version_info__ = (0, 0, 0, 0, 0) # type: ignore[assignment]
17+
18+
if __version_info__ < (20, 0, 0, "alpha", 1):
19+
raise RuntimeError(
20+
f"This example is not compatible with your current PTB version {TG_VER}. To view the "
21+
f"{TG_VER} version of this example, "
22+
f"visit https://github.com/python-telegram-bot/python-telegram-bot/tree/v{TG_VER}/examples"
23+
)
1124
from telegram import Update
1225
from telegram.constants import ParseMode
1326
from telegram.ext import Application, CommandHandler, ContextTypes

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.