bots fsm for people
Convenient FSM implementation for telegram/vk
Supports python3.7+
Library only
pip install state-manager
Library and vkwave
pip install state-manager[vk]
Library and aiogram
pip install state-manager[telegram]
Full installation
pip install state-manager[full]
from vkwave.bots import SimpleLongPollBotimport loggingfrom state_manager.routes.vkwave.state import VkWaveMainStateRouterfrom state_manager.models.state_managers.vkwave import VkWaveStateManagerlogging.basicConfig(level=logging.INFO)bot = SimpleLongPollBot(tokens="your token", group_id=123123,)main_state = VkWaveMainStateRouter(bot)@main_state.message_handler()async def home(event: bot.SimpleBotEvent, state_manager: VkWaveStateManager):await event.answer("go to home2")await state_manager.set_next_state("home2")@main_state.message_handler()async def home2(event: bot.SimpleBotEvent, state_manager: VkWaveStateManager):await event.answer("go to home")await state_manager.back_to_pre_state()main_state.install()bot.run_forever(ignore_errors=True)
import loggingfrom aiogram import Bot, Dispatcher, executor, typesfrom state_manager.models.state_managers.aiogram import AiogramStateManagerfrom state_manager.routes.aiogram.state import AiogramMainStateRouterlogging.basicConfig(level=logging.INFO)bot = Bot(token='your token')dp = Dispatcher(bot)main_state = AiogramMainStateRouter(dp)main_state.install()@main_state.message_handler()async def home(msg: types.Message, state_manager: AiogramStateManager):await msg.answer("go to home2")await state_manager.set_next_state("home2")@main_state.message_handler()async def home2(msg: types.Message, state_manager: AiogramStateManager):await msg.answer("go to home")await state_manager.set_next_state("home")executor.start_polling(dp, skip_updates=True)
The library currently supports:
If you do not pass arguments to install, Redis Storage is used, which takes the settings from env.
Settings:
The library supports out of the box:
You can also write your filters.
aiogram, vkwave