Answer the question
In order to leave comments, you need to log in
Can aiogram and flask be friends?
Can aiogram and flask be friends?
How to make "flask" and "aiogram" friends, the web interface will be written in "flask" and the bot in "aiogram" to launch the bot with a single button click in the web interface. Is it possible to run polling in a separate thread and how to do it?
webhook not considered
Answer the question
In order to leave comments, you need to log in
You can run in a separate process, so that later, if necessary, you can stop this process:
from multiprocessing import Process
from flask import Flask
from aiogram import Bot, Dispatcher, executor, types
import config
app = Flask(import_name=__name__)
bot = Bot(token=config.BOT_TOKEN)
dispatcher = Dispatcher(bot=bot)
def bot_start_polling():
executor.start_polling(dispatcher=dispatcher, skip_updates=True)
@dispatcher.message_handler(commands=['start'])
async def bot_handler_start(message: types.Message):
await message.reply('Foo')
@app.get(rule='/start_bot')
def start_bot():
bot_process = Process(target=bot_start_polling)
bot_process.start()
return str(bot_process.pid)
if __name__ == '__main__':
app.run()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question