Skip to content
Back to top
View this page

# InputMediaAnimation

class telegram.InputMediaAnimation(media, caption=None, parse_mode=None, width=None, height=None, duration=None, caption_entities=None, filename=None, has_spoiler=None, thumbnail=None, show_caption_above_media=None, *, api_kwargs=None)

  Bases: `telegram.InputMedia`

  Represents an animation file (GIF or H.264/MPEG-4 AVC video without sound) to be sent.

  Note

  When using a `telegram.Animation` for the `media` attribute, it will take the width, height and duration from that animation, unless otherwise specified with the optional arguments.

  See also

  Working with Files and Media

  Use In

  `telegram.Bot.edit_message_media()`

  Changed in version 20.5: Removed the deprecated argument and attribute `thumb`.

  Parameters:

    - media (`str` | file object | `InputFile` | `bytes` | `pathlib.Path` | `telegram.Animation`) –

      File to send. Pass a `file_id` as String to send a file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one. To upload a file, you can either pass a file object (e.g. `open("filename", "rb")`) or the file contents as bytes. If the bot is running in `local_mode`, passing the path of the file (as string or `pathlib.Path` object) is supported as well. Lastly you can pass an existing `telegram.Animation` object to send.

      Changed in version 13.2: Accept `bytes` as input.

    - filename (`str`, optional) –

      Custom file name for the animation, when uploading a new file. Convenience parameter, useful e.g. when sending files generated by the `tempfile` module.

      Added in version 13.1.

    - caption (`str`, optional) – Caption of the animation to be sent, 0-`1024` characters after entities parsing.

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

    - caption_entities (Sequence[`telegram.MessageEntity`], optional) –

      Sequence of special entities that appear in the caption, which can be specified instead of `parse_mode`.

      Changed in version 20.0: Accepts any `collections.abc.Sequence` as input instead of just a list. The input is converted to a tuple.

    - width (`int`, optional) – Animation width.

    - height (`int`, optional) – Animation height.

    - duration (`int` | `datetime.timedelta`, optional) –

      Animation duration in seconds.

      Changed in version v22.2: `datetime.timedelta` objects are accepted in addition to plain `int` values.

    - has_spoiler (`bool`, optional) –

      Pass `True`, if the animation needs to be covered with a spoiler animation.

      Added in version 20.0.

    - thumbnail (file object | `bytes` | `pathlib.Path` | `str`, optional) –

      Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail’s width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can’t be reused and can be only uploaded as a new file. To upload a file, you can either pass a file object (e.g. `open("filename", "rb")`) or the file contents as bytes. If the bot is running in `local_mode`, passing the path of the file (as string or `pathlib.Path` object) is supported as well.

      Added in version 20.2.

    - show_caption_above_media (`bool`, optional) –

      Pass `True`, if the caption must be shown above the message media.

      Added in version 21.3.

  type

    `'animation'`.

    Type:

      `str`

  media

    Animation to send.

    Type:

      `str` | `telegram.InputFile`

  caption

    Optional. Caption of the animation to be sent, 0-`1024` characters after entities parsing.

    Type:

      `str`

  parse_mode

    Optional. The parse mode to use for text formatting.

    Type:

      `str`

  caption_entities

    Optional. Tuple of special entities that appear in the caption, which can be specified instead of `parse_mode`.

    Changed in version 20.0:

    - This attribute is now an immutable tuple.

    - This attribute is now always a tuple, that may be empty.

    Type:

      tuple[`telegram.MessageEntity`]

  width

    Optional. Animation width.

    Type:

      `int`

  height

    Optional. Animation height.

    Type:

      `int`

  duration

    Optional. Animation duration in seconds.

    Deprecated since version v22.2: In a future major version this attribute will be of type `datetime.timedelta`. You can opt-in early by setting PTB_TIMEDELTA=true or `PTB_TIMEDELTA=1` as an environment variable.

    Type:

      `int` | `datetime.timedelta`

  has_spoiler

    Optional. `True`, if the animation is covered with a spoiler animation.

    Added in version 20.0.

    Type:

      `bool`

  thumbnail

    Optional. Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail’s width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can’t be reused and can be only uploaded as a new file.

    Added in version 20.2.

    Type:

      `telegram.InputFile`

  show_caption_above_media

    Optional. `True`, if the caption must be shown above the message media.

    Added in version 21.3.

    Type:

      `bool`