Defaults

final class telegram.ext.Defaults(parse_mode=None, disable_notification=None, disable_web_page_preview=None, quote=None, tzinfo=datetime.timezone.utc, block=True, allow_sending_without_reply=None, protect_content=None, link_preview_options=None, do_quote=None)[source]

Bases: object

Convenience Class to gather all parameters with a (user defined) default value

Changed in version 20.0: Removed the argument and attribute timeout. Specify default timeout behavior for the networking backend directly via telegram.ext.ApplicationBuilder instead.

Parameters:
  • parse_mode (str, optional) – Mode for parsing entities. See telegram.constants.ParseMode and formatting options for more details.

  • disable_notification (bool, optional) – Sends the message silently. Users will receive a notification with no sound.

  • disable_web_page_preview (bool, optional) –

    Disables link previews for links in this message. Mutually exclusive with link_preview_options.

    Deprecated since version 20.8: Use link_preview_options instead. This parameter will be removed in future versions.

  • allow_sending_without_reply (bool, optional) – Pass True, if the message should be sent even if the specified replied-to message is not found.. Will be used for telegram.ReplyParameters.allow_sending_without_reply.

  • quote (bool, optional) –

    If set to True, the reply is sent as an actual reply to this message. If reply_to_message_id is passed, this parameter will be ignored. Default: True in group chats and False in private chats.

    Deprecated since version 20.8: Use do_quote instead. This parameter will be removed in future versions.

  • tzinfo (datetime.tzinfo, optional) – A timezone to be used for all date(time) inputs appearing throughout PTB, i.e. if a timezone naive date(time) object is passed somewhere, it will be assumed to be in tzinfo. If the telegram.ext.JobQueue is used, this must be a timezone provided by the pytz module. Defaults to pytz.utc, if available, and datetime.timezone.utc otherwise.

  • block (bool, optional) – Default setting for the BaseHandler.block parameter of handlers and error handlers registered through Application.add_handler() and Application.add_error_handler(). Defaults to True.

  • protect_content (bool, optional) –

    Protects the contents of the sent message from forwarding and saving.

    Added in version 20.0.

  • link_preview_options (telegram.LinkPreviewOptions, optional) –

    Link preview generation options for all outgoing messages. Mutually exclusive with disable_web_page_preview. This object is used for the corresponding parameter of telegram.Bot.send_message(), telegram.Bot.edit_message_text(), and telegram.InputTextMessageContent if not specified. If a value is specified for the corresponding parameter, only those parameters of telegram.LinkPreviewOptions will be overridden that are not explicitly set.

    Example

    from telegram import LinkPreviewOptions
    from telegram.ext import Defaults, ExtBot
    
    defaults = Defaults(
        link_preview_options=LinkPreviewOptions(show_above_text=True)
    )
    chat_id = 123
    
    async def main():
        async with ExtBot("Token", defaults=defaults) as bot:
            # The link preview will be shown above the text.
            await bot.send_message(chat_id, "https://python-telegram-bot.org")
    
            # The link preview will be shown below the text.
            await bot.send_message(
                chat_id,
                "https://python-telegram-bot.org",
                link_preview_options=LinkPreviewOptions(show_above_text=False)
            )
    
            # The link preview will be shown above the text, but the preview will
            # show Telegram.
            await bot.send_message(
                chat_id,
                "https://python-telegram-bot.org",
                link_preview_options=LinkPreviewOptions(url="https://telegram.org")
            )
    

    Added in version 20.8.

  • do_quote (bool, optional) –

    If set to True, the reply is sent as an actual reply to this message. If reply_to_message_id is passed, this parameter will be ignored. Default: True in group chats and False in private chats.

    Added in version 20.8.

__eq__(other)[source]

Defines equality condition for the Defaults object. Two objects of this class are considered to be equal if all their parameters are identical.

Returns:

True if both objects have all parameters identical. False otherwise.

__hash__()[source]

Builds a hash value for this object such that the hash of two objects is equal if and only if the objects are equal in terms of __eq__().

Returns:

int The hash value of the object.

property allow_sending_without_reply[source]

Optional. Pass True, if the message should be sent even if the specified replied-to message is not found.

Type:

bool

property block[source]

Optional. Default setting for the BaseHandler.block parameter of handlers and error handlers registered through Application.add_handler() and Application.add_error_handler().

Type:

bool

property disable_notification[source]

Optional. Sends the message silently. Users will receive a notification with no sound.

Type:

bool

property disable_web_page_preview[source]

Optional. Disables link previews for links in all outgoing messages.

Deprecated since version 20.8: Use link_preview_options instead. This attribute will be removed in future versions.

Type:

bool

property do_quote[source]

Optional. If set to True, the reply is sent as an actual reply to this message. If reply_to_message_id is passed, this parameter will be ignored. Default: True in group chats and False in private chats.

Added in version 20.8.

Type:

bool

property explanation_parse_mode[source]

Optional. Alias for parse_mode, used for the corresponding parameter of telegram.Bot.send_poll().

Type:

str

Optional. Link preview generation options for all outgoing messages.

Added in version 20.8.

Type:

telegram.LinkPreviewOptions

property parse_mode[source]

Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or URLs in your bot’s message.

Type:

str

property protect_content[source]

Optional. Protects the contents of the sent message from forwarding and saving.

Added in version 20.0.

Type:

bool

property question_parse_mode[source]

Optional. Alias for parse_mode, used for the corresponding parameter of telegram.Bot.send_poll().

Added in version 21.2.

Type:

str

property quote[source]

Optional. If set to True, the reply is sent as an actual reply to this message. If reply_to_message_id is passed, this parameter will be ignored. Default: True in group chats and False in private chats.

Deprecated since version 20.8: Use do_quote instead. This attribute will be removed in future versions.

Type:

bool

property quote_parse_mode[source]

Optional. Alias for parse_mode, used for the corresponding parameter of telegram.ReplyParameters().

Type:

str

property text_parse_mode[source]

Optional. Alias for parse_mode, used for the corresponding parameter of telegram.InputPollOption.

Added in version 21.2.

Type:

str

property tzinfo[source]

A timezone to be used for all date(time) objects appearing throughout PTB.

Type:

tzinfo