Use MessageLimit.DEEP_LINK_LENGTH in helpers.create_deep_linked_url (#4597)

This commit is contained in:
Luis Pérez 2024-12-07 05:25:13 -04:00 committed by GitHub
parent 43279543a3
commit ce9742a602
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 5 deletions

View file

@ -1836,7 +1836,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

View file

@ -36,7 +36,7 @@ from html import escape
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
@ -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.
"""
@ -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(