Aiogram Webhook(heroku) Не работает FSM
При команде /start ставится state, потом если написать что-нибудь бот ответит(как и должно быть), а после перестает что-либо делать. Пробовал код в state.proxy() пихать(как сейчас), просто после state.proxy() писать. Не знаю что делать вообщем.
Код:
import os
from aiogram import Bot
from aiogram.contrib.fsm_storage.memory import MemoryStorage
from aiogram.dispatcher import Dispatcher, FSMContext
from aiogram.dispatcher.filters.state import StatesGroup, State
from aiogram.types import Message
from aiogram.utils.executor import start_webhook
TOKEN = os.environ['TOKEN']
WEBHOOK_HOST = 'https://типа url' # name your app
WEBHOOK_PATH = '/webhook/'
WEBHOOK_URL = f"{WEBHOOK_HOST}{WEBHOOK_PATH}"
WEBAPP_HOST = '0.0.0.0'
WEBAPP_PORT = os.environ.get('PORT')
logging.basicConfig(level=logging.INFO)
bot = Bot(token=TOKEN)
storage = MemoryStorage()
dp = Dispatcher(bot, storage=storage)
class Form(StatesGroup):
hey = State()
hey2 = State()
hey3 = State()
@dp.message_handler(commands='start')
async def welcome(message: Message):
await bot.send_message(chat_id=message.chat.id, text='hellO!')
await Form.hey.set()
@dp.message_handler(state=Form.hey)
async def hey(message: Message, state: FSMContext):
async with state.proxy() as data:
data['hey'] = message.text
await bot.send_message(chat_id=message.chat.id, text='hello1')
await Form.next()
@dp.message_handler(state=Form.hey)
async def hey2(message: Message, state: FSMContext):
async with state.proxy() as data:
data['hey2'] = message.text
await bot.send_message(chat_id=message.chat.id, text='hello3')
await Form.next()
@dp.message_handler(state=Form.hey)
async def hey3(message: Message, state: FSMContext):
async with state.proxy() as data:
data['hey3'] = message.text
await bot.send_message(chat_id=message.chat.id, text='hello3')
await state.finish()
async def on_startup(dp):
await bot.set_webhook(WEBHOOK_URL)
logging.info(dp)
async def on_shutdown(dp):
logging.info(dp)
if __name__ == '__main__':
start_webhook(dispatcher=dp, webhook_path=WEBHOOK_PATH,
on_startup=on_startup, on_shutdown=on_shutdown,
host=WEBAPP_HOST, port=WEBAPP_PORT)
Ответы (1 шт):
Автор решения: Алексей
→ Ссылка
@dp.message_handler(state=Form.hey). . .@dp.message_handler(state=Form.hey). . .@dp.message_handler(state=Form.hey)
Должно быть hey, hey2, hey3