Есть код получения и обработки медиа группы в канале телеграм ботом на aiogram 2, как сделать тоже самое на telebot?

Смотрел Middleware в telebot, все бы работало да не хватает поля conf класса TelegramObject, да и вообще класса TelegramObject. Пытался через updates, выскакивала ошибка: Error code: 409. Description: Conflict: terminated by other getUpdates request; make sure that only one bot instance is running, помогите реализовать эту идею на telebot..

class AlbumMiddleware(BaseMiddleware):
    album_data: dict = {}

    def __init__(self, latency: Union[int, float] = 0.01):
        """
        You can provide custom latency to make sure
        albums are handled properly in highload.
        """
        self.latency = latency
        super().__init__()

    async def on_process_channel_post(self, message: types.Message, data: dict):
        if not message.media_group_id:
            return
        try:
            self.album_data[message.media_group_id].append(message)
            raise CancelHandler()  # Tell aiogram to cancel handler for this group element
        except KeyError:
            self.album_data[message.media_group_id] = [message]
            await asyncio.sleep(self.latency)
            message.conf["is_last"] = True
            data["album"] = self.album_data[message.media_group_id]

    async def on_post_process_channel_post(self, message: types.Message, result: dict, data: dict):
        """Clean up after handling our album."""
        if message.media_group_id and message.conf.get("is_last"):
            del self.album_data[message.media_group_id]

@dp.channel_post_handler(lambda mes: mes.media_group_id, content_types=types.ContentType.ANY)
async def catcher(message: types.Message, album: List[types.Message]):
    attachments = []
    text = ''
    print('media_group')
    for obj in album[:1]:
        if obj.photo:
            file_id = obj.photo[-1].file_id
            if obj.caption:
                text = obj.caption
            file_info = await bot.get_file(file_id)
            r = wget.download(f'http://api.telegram.org/file/bot{token}/{file_info.file_path}', out='downloads/')
            attachments.append(r)
        else:
            try:
                if obj.caption:
                    text = obj.caption
                file_id = obj[obj.content_type].file_id
                file_info = await bot.get_file(file_id)
                r = wget.download(f'http://api.telegram.org/file/bot{token}/{file_info.file_path}', out='downloads/')
                attachments.append(r)
            except ValueError:
                print("This type of album is not supported by aiogram.")
                return False
    for obj in album[1:]:
        if obj.photo:
            file_id = obj.photo[-1].file_id
            file_info = await bot.get_file(file_id)
            r = wget.download(f'http://api.telegram.org/file/bot{token}/{file_info.file_path}', out='downloads/')
            attachments.append(r)
        else:
            try:
                file_id = obj[obj.content_type].file_id
                file_info = await bot.get_file(file_id)
                r = wget.download(f'http://api.telegram.org/file/bot{token}/{file_info.file_path}', out='downloads/')
                attachments.append(r)
            except ValueError:
                print("This type of album is not supported by aiogram.")
                return False
    send_post(text, attachments)

Ответы (0 шт):