Как сделать бота на Aiogram, который при подписке на канал отправляет пользователю несколько сообщений с паузами между ними
from aiogram.utils.chat_action import ChatActionSender
from aiogram.types import InlineKeyboardButton
from aiogram import Bot, Dispatcher, types
from asyncio import gather, run
from storages import *
import logging
import asyncio
bot = Bot(token=TOKEN)
dp = Dispatcher()
inline_button = InlineKeyboardButton(text="Подписаться", url="https://t.me/+ouYL3ISpgQxiMjVi")
board = [[inline_button]]
menu = types.InlineKeyboardMarkup(inline_keyboard=board)
@dp.chat_join_request()
async def start(update: types.ChatJoinRequest):
print("[New client][ID] --> ", update.from_user.id)
await update.approve()
await bot.send_message(chat_id=update.from_user.id, text=first_message)
await sender(update.from_user.id)
async def sender(id_chat):
await asyncio.sleep(first_video_duration)
await send_video(id_chat, first_video_path)
await asyncio.sleep(second_video_duration)
await send_video(id_chat, second_video_path)
await asyncio.sleep(third_video_duration)
await send_video(id_chat, third_video_path)
await asyncio.sleep(fourth_video_duration)
await send_video(id_chat, fourth_video_path)
await asyncio.sleep(fifth_video_duration)
await send_video(id_chat, fifth_video_path)
await asyncio.sleep(sixth_video_duration)
await send_video(id_chat, sixth_video_path)
await asyncio.sleep(seventh_video_duration)
await send_video(id_chat, seventh_video_path)
await send_video(id_chat, final_video_path)
async def send_video(id_chat, path):
async with ChatActionSender.upload_video(chat_id=id_chat, bot=bot):
if path == final_video_path:
await bot.send_video_note(chat_id=id_chat,
video_note=types.FSInputFile(path=path),
reply_markup=menu)
else:
await bot.send_video_note(chat_id=id_chat,
video_note=types.FSInputFile(path=path))
async def launch_bot():
await dp.start_polling(bot)
async def main():
await gather(
launch_bot()
)
if __name__ == '__main__':
run(main())
Есть такой код. При подписке, бот отправляет сообщение и несколько видео-кружочков с паузами, но при подписке нескольких клиентов одновременно появляется следующая ошибка
Cause exception while process update id=533293884 by bot id=7388211844
TelegramNetworkError: HTTP Client says - Request timeout error
Traceback (most recent call last):
File "/usr/local/lib/python3.12/dist-packages/aiogram/client/session/aiohttp.p y", line 170, in make_request
async with session.post(
File "/usr/local/lib/python3.12/dist-packages/aiohttp/client.py", line 1197, i n __aenter__
self._resp = await self._coro
^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/aiohttp/client.py", line 507, in _request
with timer:
File "/usr/local/lib/python3.12/dist-packages/aiohttp/helpers.py", line 735, i n __exit__
raise asyncio.TimeoutError from None
TimeoutError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.12/dist-packages/aiogram/dispatcher/dispatcher.py ", line 309, in _process_update
response = await self.feed_update(bot, update, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/aiogram/dispatcher/dispatcher.py ", line 158, in feed_update
response = await self.update.wrap_outer_middleware(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/aiogram/dispatcher/middlewares/e rror.py", line 25, in __call__
return await handler(event, data)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/aiogram/dispatcher/middlewares/u ser_context.py", line 49, in __call__
return await handler(event, data)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/aiogram/fsm/middleware.py", line 42, in __call__
return await handler(event, data)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/aiogram/dispatcher/event/telegra m.py", line 121, in trigger
return await wrapped_inner(event, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/aiogram/dispatcher/event/handler .py", line 43, in call
return await wrapped()
^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/aiogram/dispatcher/dispatcher.py ", line 276, in _listen_update
return await self.propagate_event(update_type=update_type, event=event, **kw args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^
File "/usr/local/lib/python3.12/dist-packages/aiogram/dispatcher/router.py", l ine 142, in propagate_event
return await observer.wrap_outer_middleware(_wrapped, event=event, data=kwar gs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^
File "/usr/local/lib/python3.12/dist-packages/aiogram/dispatcher/router.py", l ine 137, in _wrapped
return await self._propagate_event(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/aiogram/dispatcher/router.py", l ine 162, in _propagate_event
response = await observer.trigger(event, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/aiogram/dispatcher/event/telegra m.py", line 121, in trigger
return await wrapped_inner(event, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/aiogram/dispatcher/event/handler .py", line 43, in call
return await wrapped()
^^^^^^^^^^^^^^^
File "/root/39/main.py", line 23, in start
await sender(update.from_user.id)
File "/root/39/main.py", line 28, in sender
await send_video(id_chat, first_video_path)
File "/root/39/main.py", line 58, in send_video
await bot.send_video_note(chat_id=id_chat,
File "/usr/local/lib/python3.12/dist-packages/aiogram/client/bot.py", line 332 2, in send_video_note
return await self(call, request_timeout=request_timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/aiogram/client/bot.py", line 480 , in __call__
return await self.session(self, method, timeout=request_timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/aiogram/client/session/base.py", line 254, in __call__
return cast(TelegramType, await middleware(bot, method))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/aiogram/client/session/aiohttp.p y", line 175, in make_request
raise TelegramNetworkError(method=method, message="Request timeout error")
aiogram.exceptions.TelegramNetworkError: HTTP Client says - Request timeout error