'the loop of sending messages python-telegram-bot-api aiogram
I am writing a bot that will give out various media by certain tags. the user writes a request, it is processed and everything found in the database is converted into a list of links of these media, which will then be sent to the user. For example, the script found 100 media satisfying the search query.
how to issue messages in a loop of n messages (for example, n = 10), and to continue issuing, you need to press the inline button? I thought to use AsyncIOScheduler, but as far as I understand, it outputs a cycle over a time interval, but I need exactly the trigger of pressing the button what do I need to use for this? any scheduler or other handlers?
I was asked to insert a bot initialization block, I don't understand why, if it's standard for any python telegram bot, but okay, here it is
#import block
import asyncio
import string
from asyncio.log import logger
import json
from aiogram.bot.api import TelegramAPIServer
from apscheduler.schedulers.asyncio import AsyncIOScheduler
import logging
import sqlite3
from aiogram.utils.callback_data import CallbackData
from aiogram import Bot, Dispatcher, executor, types
from aiogram.bot import bot
from aiogram.contrib.fsm_storage.memory import MemoryStorage
from aiogram.contrib.middlewares.logging import LoggingMiddleware
from aiogram.utils.markdown import hlink
import config
from utils import States
# Init block
logging.basicConfig(level=logging.INFO)
bot = Bot(token=config.API_TOKEN)
dp = Dispatcher(bot, storage=MemoryStorage())
dp.middleware.setup(LoggingMiddleware())
cb = CallbackData('id', 'action')
for example, my unfinished code
@dp.message_handler(state=States.S_SEND)
async def senn_media(link_list, message: types.Message):
chat_id = message.chat.id
for length in range(10):
caption1 = ("some text")
media1 = link_list[array]
await bot.send_video(chat_id, media1, caption=caption1, parse_mode="HTML")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
