Package: aiogram-dialog
Aiogram DialogVersion status:v2.x - actual release, supports aiogram v3.xv1.x - old release, supports aiogram v2.x, critical fix onlyAboutaiogram-dialogis a framework for developing interactive messages and menus in your telegram bot like a normal GUI application.It is inspired by ideas of Android SDK and other tools.Main ideas are:split data retrieving, rendering and action processing- you need nothing to do for showing same content after some actions, also you can show same data in multiple ways.reusable widgets- you can create calendar or multiselect at any point of your application without copy-pasting its internal logiclimited scope of context- any dialog keeps some data until closed, multiple opened dialogs process their data separatelyDesigning you bot withaiogram-dialogyouthink about user, what he sees and what he does. Then you split this vision into reusable parts and design your bot combining dialogs, widows and widgets. By this moment you can review interface and add your core logic.Many components are ready for use, but you can extend and add your own widgets and even core features.For more details seedocumentationandexamplesSupported features:Rich text rendering usingformatfunction orJinja2template engine.Automatic message updating after user actionsMultiple independent dialog stacks with own data storage and transitionsInline keyboard widgets likeSwitchTo,Start,Cancelfor state switching,Calendarfor date selection and others.Stateful widgets:Checkbox,Multiselect,Counter,TextInput. They record user actions and allow you to retrieve this data later.Multiple buttons layouts including simple grouping (Group,Column), page scrolling (ScrollingGroup), repeating of same buttons for list of data (ListGroup).Sending media (like photo or video) with fileid caching and handling switching to/from message with no media.Different rules of transitions between windows/dialogs like keeping only one dialog on top of stack or force sending enw message instead of updating one.Offline HTML-preview for messages and transitions diagram. They can be used to check all states without emulating real use cases or exported for demonstration purposes.UsageExample below is suitable for aiogram_dialog v2.x and aiogram v3.xDeclaring WindowEach window consists of:Text widgets. Render text of message.Keyboard widgets. Render inline keyboardMedia widget. Renders media if needMessage handler. Called when user sends a message when window is shownData getter functions (getter=). They load data from any source which can be used in text/keyboardState. Used when switching between windowsInfo:always createStateinsideStatesGroupfromaiogram.filters.stateimportStatesGroup,Statefromaiogram_dialog.widgets.textimportFormat,Constfromaiogram_dialog.widgets.kbdimportButtonfromaiogram_dialogimportWindowclassMySG(StatesGroup):main=State()asyncdefget_data(**kwargs):return{"name":"world"}Window(Format("Hello,{name}!"),Button(Const("Empty button"),id="nothing"),state=MySG.main,getter=get_data,)Declaring dialogWindow itself can do nothing, just prepares message. To use it you need dialog:fromaiogram.filters.stateimportStatesGroup,Statefromaiogram_dialogimportDialog,WindowclassMySG(StatesGroup):first=State()second=State()dialog=Dialog(Window(...,state=MySG.first),Window(...,state=MySG.second),)Info:All windows in a dialog MUST have states from then sameStatesGroupAfter creating a dialog you need to register it into the Dispatcher and set it up using thesetup_dialogsfunction:fromaiogramimportDispatcherfromaiogram_dialogimportsetup_dialogs...dp=Dispatcher(storage=storage)# create as usualdp.include_router(dialog)setup_dialogs(dp)Then start dialog when you are ready to use it. Dialog is started viastartmethod ofDialogManagerinstance. You
should provide corresponding state to switch into (usually it is state of first window in dialog).For example in/startcommand handler:asyncdefuser_start(message:Message,dialog_manager:DialogManager):awaitdialog_manager.start(MySG.first,mode=StartMode.RESET_STACK)dp.message.register(user_start,F.text=="/start")Info:Always setmode=StartMode.RESET_STACKin your top level start command. Otherwise, dialogs are stacked just as they do
on your mobile phone, so you can reach stackoverflow error