8000 Use `MessageLimit.DEEP_LINK_LENGTH` in `helpers.create_deep_linked_ur… · vavasik800/python-telegram-bot@ce9742a · GitHub 65EB
[go: up one dir, main page]

Skip to content

Commit ce9742a

Browse files
authored
Use MessageLimit.DEEP_LINK_LENGTH in helpers.create_deep_linked_url (python-telegram-bot#4597)
1 parent 4327954 commit ce9742a

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

telegram/constants.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1836,7 +1836,6 @@ class MessageLimit(IntEnum):
18361836
:paramref:`~telegram.Bot.edit_message_text.text` parameter of
18371837
:meth:`telegram.Bot.edit_message_text`.
18381838
"""
1839-
# TODO this constant is not used. helpers.py contains 64 as a number
18401839
DEEP_LINK_LENGTH = 64
18411840
""":obj:`int`: Maximum number of characters for a deep link."""
18421841
# TODO this constant is not used anywhere

telegram/helpers.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from typing import TYPE_CHECKING, Optional, Union
3737

3838
from telegram._utils.types import MarkdownVersion
39-
from telegram.constants import MessageType
39+
from telegram.constants import MessageLimit, MessageType
4040

4141
if TYPE_CHECKING:
4242
from telegram import Message, Update
@@ -173,7 +173,8 @@ def create_deep_linked_url(
173173
:obj:`str`: An URL to start the bot with specific parameters.
174174
175175
Raises:
176-
:exc:`ValueError`: If the length of the :paramref:`payload` exceeds 64 characters,
176+
:exc:`ValueError`: If the length of the :paramref:`payload` exceeds \
177+
:tg-const:`telegram.constants.MessageLimit.DEEP_LINK_LENGTH` characters,
177178
contains invalid characters, or if the :paramref:`bot_username` is less than 4
178179
characters.
179180
"""
@@ -184,8 +185,10 @@ def create_deep_linked_url(
184185
if not payload:
185186
return base_url
186187

187-
if len(payload) > 64:
188-
raise ValueError("The deep-linking payload must not exceed 64 characters.")
188+
if len(payload) > MessageLimit.DEEP_LINK_LENGTH:
189+
raise ValueError(
190+
f"The deep-linking payload must not exceed {MessageLimit.DEEP_LINK_LENGTH} characters."
191+
)
189192

190193
if not re.match(r"^[A-Za-z0-9_-]+$", payload):
191194
raise ValueError(

0 commit comments

Comments
 (0)
0