InlineKeyboardButton(text="Open Webview", web_app=WebAppInfo(url="https://example.com/"))
from aiogram import types
from aiogram.utils.keyboard import InlineKeyboardBuilder
builder = InlineKeyboardBuilder()
# 1 вариант (в строку)
builder.row(
types.InlineKeyboardButton(text, callback_data),
types.InlineKeyboardButton(text, callback_data)
)
# ---
# 2 вариант (в строку)
builder.button(text, callback_data)
builder.button(text, callback_data)
# ---
# 1 вариант (в столбец)
builder.row(
types.InlineKeyboardButton(text, callback_data),
types.InlineKeyboardButton(text, callback_data),
width=1
)
# ---
# 2 вариант (в столбец)
builder.button(text, callback_data)
builder.button(text, callback_data)
builder.adjust(1)
# ---
kb = [
[
types.InlineKeyboardButton(text, callback_data),
types.InlineKeyboardButton(text, callback_data)
],
[
types.InlineKeyboardButton(text, callback_data)
]
]
keyboard = types.InlineKeyboardMarkup(inline_keyboard=kb)
await callback.message.answer('второй vds', reply_markup=keyboard)
await callback.message.edit_text('второй vds', reply_markup=keyboard)
import asyncio
from typing import List, Union
from aiogram import types
from aiogram.dispatcher.handler import CancelHandler
from aiogram.dispatcher.middlewares import BaseMiddleware
class AlbumMiddleware(BaseMiddleware):
"""This middleware is for capturing media groups."""
album_data: dict = {}
def __init__(self, latency: Union[int, float] = 0.01):
"""
You can provide custom latency to make sure
albums are handled properly in highload.
"""
self.latency = latency
super().__init__()
async def on_process_message(self, message: types.Message, data: dict):
if not message.media_group_id:
return
try:
self.album_data[message.media_group_id].append(message)
raise CancelHandler() # Tell aiogram to cancel handler for this group element
except KeyError:
self.album_data[message.media_group_id] = [message]
await asyncio.sleep(self.latency)
message.conf["is_last"] = True
data["album"] = self.album_data[message.media_group_id]
async def on_post_process_message(self, message: types.Message, result: dict, data: dict):
"""Clean up after handling our album."""
if message.media_group_id and message.conf.get("is_last"):
del self.album_data[message.media_group_id]
@dp.message_handler(content_types=['photo'], is_media_group=True)
async def all_message(message: types.Message, album: List[types.Message]):
media_group = types.MediaGroup()
for obj in album:
if obj.photo:
file_id = obj.photo[-1].file_id
else:
file_id = obj[obj.content_type].file_id
try:
media_group.attach({"media": file_id, "type": obj.content_type})
except ValueError:
return await message.answer("This type of album is not supported by aiogram.")
await message.bot.send_media_group(chat_id=chat_id, media=media_group)
class MyStates:
balance = None # Определите состояние balance
from aiogram.dispatcher.filters.state import State, StatesGroup
class MyStates(StatesGroup):
balance = State()