telegram.helpers Module¶
This module contains convenience helper functions.
Changed in version 20.0: Previously, the contents of this module were available through the (no longer existing)
module telegram.utils.helpers
.
- telegram.helpers.create_deep_linked_url(bot_username, payload=None, group=False)[source]¶
Creates a deep-linked URL for this
bot_username
with the specifiedpayload
. See https://core.telegram.org/bots/features#deep-linking to learn more.The
payload
may consist of the following characters:A-Z, a-z, 0-9, _, -
Note
Works well in conjunction with
CommandHandler("start", callback, filters=filters.Regex('payload'))
Examples
create_deep_linked_url(bot.get_me().username, "some-params")
- Parameters:
- Returns:
An URL to start the bot with specific parameters.
- Return type:
- Raises:
ValueError – If the length of the
payload
exceeds 64 characters, contains invalid characters, or if thebot_username
is less than 4 characters.
- telegram.helpers.effective_message_type(entity)[source]¶
Extracts the type of message as a string identifier from a
telegram.Message
or atelegram.Update
.- Parameters:
entity (
telegram.Update
|telegram.Message
) – Theupdate
ormessage
to extract from.- Returns:
One of
telegram.constants.MessageType
if the entity contains a message that matches one of those types.None
otherwise.- Return type:
- telegram.helpers.escape_markdown(text, version=1, entity_type=None)[source]¶
Helper function to escape telegram markup symbols.
Changed in version 20.3: Custom emoji entity escaping is now supported.
- Parameters:
version (
int
|str
) – Use to specify the version of telegrams Markdown. Either1
or2
. Defaults to1
.entity_type (
str
, optional) – For the entity types'pre'
,'code'
and the link part of'text_link'
and'custom_emoji'
, only certain characters need to be escaped in'MarkdownV2'
. See the official API documentation for details. Only valid in combination withversion=2
, will be ignored else.
- telegram.helpers.mention_html(user_id, name)[source]¶
Helper function to create a user mention as HTML tag.