mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-12-13 18:30:40 +01:00
Use MessageLimit.DEEP_LINK_LENGTH
in helpers.create_deep_linked_url
(#4597)
This commit is contained in:
parent
43279543a3
commit
ce9742a602
2 changed files with 7 additions and 5 deletions
|
@ -1836,7 +1836,6 @@ class MessageLimit(IntEnum):
|
||||||
:paramref:`~telegram.Bot.edit_message_text.text` parameter of
|
:paramref:`~telegram.Bot.edit_message_text.text` parameter of
|
||||||
:meth:`telegram.Bot.edit_message_text`.
|
:meth:`telegram.Bot.edit_message_text`.
|
||||||
"""
|
"""
|
||||||
# TODO this constant is not used. helpers.py contains 64 as a number
|
|
||||||
DEEP_LINK_LENGTH = 64
|
DEEP_LINK_LENGTH = 64
|
||||||
""":obj:`int`: Maximum number of characters for a deep link."""
|
""":obj:`int`: Maximum number of characters for a deep link."""
|
||||||
# TODO this constant is not used anywhere
|
# TODO this constant is not used anywhere
|
||||||
|
|
|
@ -36,7 +36,7 @@ from html import escape
|
||||||
from typing import TYPE_CHECKING, Optional, Union
|
from typing import TYPE_CHECKING, Optional, Union
|
||||||
|
|
||||||
from telegram._utils.types import MarkdownVersion
|
from telegram._utils.types import MarkdownVersion
|
||||||
from telegram.constants import MessageType
|
from telegram.constants import MessageLimit, MessageType
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from telegram import Message, Update
|
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.
|
:obj:`str`: An URL to start the bot with specific parameters.
|
||||||
|
|
||||||
Raises:
|
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
|
contains invalid characters, or if the :paramref:`bot_username` is less than 4
|
||||||
characters.
|
characters.
|
||||||
"""
|
"""
|
||||||
|
@ -184,8 +185,10 @@ def create_deep_linked_url(
|
||||||
if not payload:
|
if not payload:
|
||||||
return base_url
|
return base_url
|
||||||
|
|
||||||
if len(payload) > 64:
|
if len(payload) > MessageLimit.DEEP_LINK_LENGTH:
|
||||||
raise ValueError("The deep-linking payload must not exceed 64 characters.")
|
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):
|
if not re.match(r"^[A-Za-z0-9_-]+$", payload):
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
|
|
Loading…
Reference in a new issue