All Projects → Tishka17 → aiogram_dialog

Tishka17 / aiogram_dialog

Licence: Apache-2.0 license
GUI framework on top of aiogram

Programming Languages

python
139335 projects - #7 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to aiogram dialog

Aiogram
Is a pretty simple and fully asynchronous framework for Telegram Bot API written in Python 3.7 with asyncio and aiohttp.
Stars: ✭ 2,195 (+734.6%)
Mutual labels:  telegram-bot-api, aiogram
webhook-aiogram-heroku
A sample telegram bot made with aiogram, that fetches updates using the web-hook connection. Can be easily deployed to Heroku.
Stars: ✭ 36 (-86.31%)
Mutual labels:  telegram-bot-api, aiogram
antirobot aiogram
Телеграм бот для блокировки спама
Stars: ✭ 26 (-90.11%)
Mutual labels:  telegram-bot-api, aiogram
aiogram-structured
Code your aiogram bot faster, easier & modular.
Stars: ✭ 32 (-87.83%)
Mutual labels:  telegram-bot-api, aiogram
telegram-standup-bot
Very simple telegram bot for submitting daily standups
Stars: ✭ 23 (-91.25%)
Mutual labels:  telegram-bot-api
react-telegram
(WIP) A React custom renderer for the Telegram Bot API.
Stars: ✭ 14 (-94.68%)
Mutual labels:  telegram-bot-api
wikibot
A 🤖 which provides features from Wikipedia like summary, title searches, location API etc.
Stars: ✭ 25 (-90.49%)
Mutual labels:  telegram-bot-api
kuafu
This is a tool library that includes log, fsm, state machine...
Stars: ✭ 83 (-68.44%)
Mutual labels:  fsm
tdlight-java
Complete Bot and Userbot Telegram library based on TDLib
Stars: ✭ 128 (-51.33%)
Mutual labels:  telegram-bot-api
telegram
Golang Telegram Bot API
Stars: ✭ 13 (-95.06%)
Mutual labels:  telegram-bot-api
flow
A Statically Type Checked State Machine DSL for Kotlin
Stars: ✭ 74 (-71.86%)
Mutual labels:  fsm
raider
OWASP Raider: a novel framework for manipulating the HTTP processes of persistent sessions
Stars: ✭ 88 (-66.54%)
Mutual labels:  fsm
telegram-bot-sdk
🤖 Telegram Bot API PHP SDK. Create Telegram Bots with PHP Easily! [WIP - DO NOT USE IN PRODUCTION YET]
Stars: ✭ 64 (-75.67%)
Mutual labels:  telegram-bot-api
telegram bot
Script ini digunakan untuk mengontrol MikroTik Anda hanya dengan menggunakan sosial media Telegram.
Stars: ✭ 27 (-89.73%)
Mutual labels:  telegram-bot-api
github client
Open source bot telegram menggunakan bahasa code dart
Stars: ✭ 24 (-90.87%)
Mutual labels:  telegram-bot-api
telegram-log
Send a Telegram message when your scripts fire an exception or when they finish their execution.
Stars: ✭ 16 (-93.92%)
Mutual labels:  telegram-bot-api
Nutgram
The Telegram bot framework that doesn't drive you nuts.
Stars: ✭ 206 (-21.67%)
Mutual labels:  telegram-bot-api
stateless
Finite State Machine porting from Stateless C#
Stars: ✭ 25 (-90.49%)
Mutual labels:  fsm
finch
A Golang Telegram Bot framework
Stars: ✭ 23 (-91.25%)
Mutual labels:  telegram-bot-api
telresender
A Telegram bot, which resend your message to another account
Stars: ✭ 22 (-91.63%)
Mutual labels:  telegram-bot-api

Aiogram Dialog

PyPI version Doc downloads license

Version status:

  • v1.x - stable release, supports aiogram v2.x, bugfix only
  • v2.x - beta, future release, supports aiogram v3.x

About

aiogram-dialog is 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 retriving, 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 logic
  • limited scope of context - any dialog keeps some data until closed, multiple opened dialogs process their data separately

Designing you bot with aiogram-dialog you think 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 see documentation and examples

Supported features:

  • Rich text rendering using format function or Jinja2 template engine.
  • Automatic message updating after user actions
  • Multiple independent dialog stacks with own data storage and transitions
  • Inline keyboard widgets like SwitchTo, Start, Cancel for state switching, Calendar for 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.

Usage

Example below is suitable for aiogram_dialog v2.x and aiogram v3.x

Declaring Window

Each window consists of:

  • Text widgets. Render text of message.
  • Keyboard widgets. Render inline keyboard
  • Media widget. Renders media if neede
  • Message handler. Called when user sends a message when window is shown
  • Data getter functions (getter=). They load data from any source which can be used in text/keyboard
  • State. Used when switching between windows

Info: always create State inside StatesGroup

from aiogram.filters.state import StatesGroup, State
from aiogram_dialog.widgets.text import Format, Const
from aiogram_dialog.widgets.kbd import Button
from aiogram_dialog import Window


class MySG(StatesGroup):
    main = State()


async def get_data(**kwargs):
    return {"name": "world"}


Window(
    Format("Hello, {name}!"),
    Button(Const("Empty button"), id="nothing"),
    state=MySG.main,
    getter=get_data,
)

Declaring dialog

Window itself can do nothing, just prepares message. To use it you need dialog:

from aiogram.filters.state import StatesGroup, State
from aiogram_dialog import Dialog, Window


class MySG(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 same StatesGroup

After creating dialog you need to register it using DialogRegistry:

from aiogram import Dispatcher
from aiogram_dialog import DialogRegistry

...
dp = Dispatcher(storage=storage)  # create as usual
registry = DialogRegistry(dp)  # create registry
registry.register(name_dialog)  # create

Then start dialog when you are ready to use it. Dialog is started via start method of DialogManager instance. You should provide corresponding state to switch into (usually it is state of first window in dialog).

For example in /start command handler:

async def user_start(message: Message, dialog_manager: DialogManager):
    await dialog_manager.start(MySG.first, mode=StartMode.RESET_STACK)

dp.message.register(user_start, F.text == "/start")

Info: Always set mode=StartMode.RESET_STACK in your top level start command. Otherwise, dialogs are stacked just as they do on your mobile phone, so you can reach stackoverflow error

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].