Skip to content

Start using MessageLimit.DEEP_LINK_LENGTH constant #4597

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion telegram/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -1835,7 +1835,6 @@ class MessageLimit(IntEnum):
:paramref:`~telegram.Bot.edit_message_text.text` parameter of
:meth:`telegram.Bot.edit_message_text`.
"""
# TODO this constant is not used. helpers.py contains 64 as a number
DEEP_LINK_LENGTH = 64
""":obj:`int`: Maximum number of characters for a deep link."""
# TODO this constant is not used anywhere
Expand Down
11 changes: 7 additions & 4 deletions telegram/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from typing import TYPE_CHECKING, Optional, Union

from telegram._utils.types import MarkdownVersion
from telegram.constants import MessageType
from telegram.constants import MessageLimit, MessageType

if TYPE_CHECKING:
from telegram import Message, Update
Expand Down Expand Up @@ -173,7 +173,8 @@ def create_deep_linked_url(
:obj:`str`: An URL to start the bot with specific parameters.

Raises:
:exc:`ValueError`: If the length of the :paramref:`payload` exceeds 64 characters,
:exc:`ValueError`: If the length of the :paramref:`payload` exceeds \
:tg-const:`telegram.constants.MessageLimit.DEEP_LINK_LENGTH` characters,
contains invalid characters, or if the :paramref:`bot_username` is less than 4
characters.
"""
Expand All @@ -184,8 +185,10 @@ def create_deep_linked_url(
if not payload:
return base_url

if len(payload) > 64:
raise ValueError("The deep-linking payload must not exceed 64 characters.")
if len(payload) > MessageLimit.DEEP_LINK_LENGTH:
raise ValueError(
f"The deep-linking payload must not exceed {MessageLimit.DEEP_LINK_LENGTH} characters."
)

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