β¨οΈ KeyboardsΒΆ
Raito has two keyboard decorators. Both return a ready aiogram markup, so you never manage builders or markup objects at the call site.
@rt.keyboard.staticβ declare the layout as the functionβs return value;@rt.keyboard.dynamicβ build it imperatively with a builder.
Static β layout by return valueΒΆ
Return a list of rows. Each item is either a button (a str or a
tuple) or a row (a list of buttons):
from raito import rt
@rt.keyboard.static(inline=False)
def start_markup():
return [
"π Throw a ball", # a row with one button
["π FAQ", "π Leaderboard"], # a row with two buttons
]
For inline keyboards a button is a (text, value) tuple. value becomes
callback_data, unless it looks like a URL (https://, tg://,
t.me/...), in which case it becomes a URL button:
@rt.keyboard.static(inline=True)
def info_markup():
return [
("π¬ Support", "support"), # callback button
[("π Privacy", "privacy"), ("π TOS", "terms")], # a two-button row
("π Website", "https://example.com"), # URL button
]
The decorator returns a ReplyKeyboardMarkup or InlineKeyboardMarkup
depending on inline=. Call the function to get the markup:
await message.answer("Menu:", reply_markup=start_markup())
Dynamic β build with a builderΒΆ
When the layout depends on data, take the builder as the first argument and add buttons yourself. Any extra parameters are yours to pass at call time:
from aiogram.utils.keyboard import InlineKeyboardBuilder
from raito import rt
@rt.keyboard.dynamic(1, 2, inline=True)
def links_markup(builder: InlineKeyboardBuilder, privacy_url: str, tos_url: str):
builder.button(text="π¬ Support", callback_data="support")
builder.button(text="π Privacy", url=privacy_url)
builder.button(text="π TOS", url=tos_url)
await message.answer(
"Links:",
reply_markup=links_markup(privacy_url="...", tos_url="..."),
)
ParametersΒΆ
Parameter |
Meaning |
|---|---|
|
Build an inline ( |
|
Row-size pattern for |
|
Auto-arrange buttons with |
|
Repeat the |
Set adjust=False to lay the keyboard out yourself β useful when the shape is
conditional:
@rt.keyboard.dynamic(adjust=False)
def admin_markup(builder: InlineKeyboardBuilder, show_balance: bool = False):
sizes = [1]
builder.button(text="π€ Users", callback_data="users")
if show_balance:
builder.button(text="π€ Withdraw", callback_data="withdraw")
builder.button(text="π₯ Deposit", callback_data="deposit")
sizes.append(2)
builder.adjust(*sizes)