mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 18:19:34 +00:00
Implemented a MediaGroupBuilder class in 'aiogram/utils/media_group.py' to help construct media groups. The class supports addition of different media types (audio, photo, video, document) to the media group with a maximum limit of 10 files. The functionality is demonstrated and usage is documented in 'docs/utils/media_group.rst'. Added related test cases in 'tests/test_utils/test_media_group.py'. This is to streamline and simplify the process of media group creation
46 lines
1.5 KiB
ReStructuredText
46 lines
1.5 KiB
ReStructuredText
===================
|
|
Media group builder
|
|
===================
|
|
|
|
This module provides a builder for media groups, it can be used to build media groups
|
|
for :class:`aiogram.types.input_media_photo.InputMediaPhoto`, :class:`aiogram.types.input_media_video.InputMediaVideo`,
|
|
:class:`aiogram.types.input_media_document.InputMediaDocument` and :class:`aiogram.types.input_media_audio.InputMediaAudio`.
|
|
|
|
.. warning::
|
|
|
|
:class:`aiogram.types.input_media_animation.InputMediaAnimation`
|
|
is not supported yet in the Bot API to send as media group.
|
|
|
|
|
|
Usage
|
|
=====
|
|
|
|
.. code-block:: python
|
|
|
|
media_group = MediaGroupBuilder(caption="Media group caption")
|
|
|
|
# Add photo
|
|
media_group.add_photo(media="https://picsum.photos/200/300")
|
|
# Dynamically add photo with known type without using separate method
|
|
media_group.add(type="photo", media="https://picsum.photos/200/300")
|
|
# ... or video
|
|
media_group.add(type="video", media=FSInputFile("media/video.mp4"))
|
|
|
|
|
|
To send media group use :meth:`aiogram.methods.send_media_group.SendMediaGroup` method,
|
|
but when you use :class:`aiogram.utils.media_group.MediaGroupBuilder`
|
|
you should pass ``media`` argument as ``media_group.build()``.
|
|
|
|
If you specify ``caption`` in :class:`aiogram.utils.media_group.MediaGroupBuilder`
|
|
it will be used as ``caption`` for first media in group.
|
|
|
|
.. code-block:: python
|
|
|
|
await bot.send_media_group(chat_id=chat_id, media=media_group.build())
|
|
|
|
|
|
References
|
|
==========
|
|
|
|
.. autoclass:: aiogram.utils.media_group.MediaGroupBuilder
|
|
:members:
|