I am trying to send videos with buttons and get the button input to further proceed. I am using the latest version of python and aiogram.
This is only a snipped, all variables are defined.
from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton, FSInputFile
from aiogram import Bot, types
import os
async def send_videos(bot: Bot, video_path: str, chat_id: int, buttons: bool):
"""
Sends all videos from the directory. If used with buttons
"""
try:
for filename in os.listdir(video_path):
video_file = FSInputFile(path=video_path, filename=filename)
if buttons:
keyboard = InlineKeyboardMarkup(inline_keyboard=[
[
InlineKeyboardButton(text="de", callback_data="de"),
InlineKeyboardButton(text="en", callback_data="en"),
InlineKeyboardButton(text="fr", callback_data="fr"),
InlineKeyboardButton(text="es", callback_data="es"),
InlineKeyboardButton(text="jp", callback_data="jp"),
InlineKeyboardButton(text="cn", callback_data="cn"),
InlineKeyboardButton(text="kr", callback_data="kr")
]
])
await bot.send_video(chat_id=chat_id, video=video_file, caption=filename, reply_markup=keyboard)
else:
await bot.send_video(chat_id=chat_id, video=video_file, caption=filename)
except Exception as e:
logger.warning(f"An error occurred while sending the videos: {e}")
async def handle_button_click(callback_query: types.CallbackQuery):
language = callback_query.data
...
main():
path = os.path.join(os.getcwd(), "Videos")
bot = Bot(token=get_token())
await send_videos(bot, path, chat_id, buttons=True)
My implementation of handle_button_click wouldn’t work. I tried some methods but couldn’t come to a working solution. How can I wait for the button click to proceed the script?
I also get following error from the send_video function:
An error occurred while sending the videos: HTTP Client says - ClientOSError: [Errno 13] Can not write request body for https://api.telegram.org/bot(token)/sendVideo
This error shouldn’t be because of the video. The test case video is a 8 MB mp4.