telegram.utils.helpers Module¶
This module contains helper functions.
-
telegram.utils.helpers.create_deep_linked_url(bot_username, payload=None, group=False)¶ Creates a deep-linked URL for this
bot_usernamewith the specifiedpayload. See https://core.telegram.org/bots#deep-linking to learn more.The
payloadmay 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: - bot_username (
str) – The username to link to - payload (
str, optional) – Parameters to encode in the created URL - group (
bool, optional) – If True the user is prompted to select a group to add the bot to. If False, opens a one-on-one conversation with the bot. Defaults to False.
Returns: An URL to start the bot with specific parameters
Return type: str- bot_username (
-
telegram.utils.helpers.decode_conversations_from_json(json_string)¶ Helper method to decode a conversations dict (that uses tuples as keys) from a JSON-string created with
_encode_conversations_to_json.Parameters: json_string ( str) – The conversations dict as JSON string.Returns: The conversations dict after decoding Return type: dict
-
telegram.utils.helpers.decode_user_chat_data_from_json(data)¶ Helper method to decode chat or user data (that uses ints as keys) from a JSON-string.
Parameters: data ( str) – The user/chat_data dict as JSON string.Returns: The user/chat_data defaultdict after decoding Return type: dict
-
telegram.utils.helpers.effective_message_type(entity)¶ Extracts the type of message as a string identifier from a
telegram.Messageor atelegram.Update.Parameters: entity ( Update|Message) –Returns: One of Message.MESSAGE_TYPESReturn type: str
-
telegram.utils.helpers.enocde_conversations_to_json(conversations)¶ Helper method to encode a conversations dict (that uses tuples as keys) to a JSON-serializable way. Use
_decode_conversations_from_jsonto decode.Parameters: conversations ( dict) – The conversations dict to transofrm to JSON.Returns: The JSON-serialized conversations dict Return type: str
-
telegram.utils.helpers.escape_markdown(text)¶ Helper function to escape telegram markup symbols.
-
telegram.utils.helpers.from_timestamp(unixtime)¶ Parameters: unixtime (int) – Returns: Return type: datetime.datetime
-
telegram.utils.helpers.get_signal_name(signum)¶ Returns the signal name of the given signal number.
-
telegram.utils.helpers.mention_html(user_id, name)¶ Parameters: - user_id (
int) – - name (
str) –
Returns: The inline mention for the user as html.
Return type: str- user_id (
-
telegram.utils.helpers.mention_markdown(user_id, name)¶ Parameters: - user_id (
int) – - name (
str) –
Returns: The inline mention for the user as markdown.
Return type: str- user_id (
-
telegram.utils.helpers.to_timestamp(dt_obj)¶ Parameters: dt_obj ( datetime.datetime) –Returns: Return type: int