Skip to main content

Async framework for VK Teams bots (aiogram-style)

Project description

solobot-vkteams

Асинхронный Python-фреймворк для создания ботов VK Teams (Mail.ru / ICQ), вдохновлённый aiogram.

Возможности

  • API в стиле aiogram — Bot → Dispatcher → Router → Handlers
  • ФильтрыCommand, Regexp, ChatTypeFilter, CallbackData, HasFile, HasImage, IsReply, IsForward и другие
  • Magic Filter — цепочки атрибутов вида F.text.startswith("привет")
  • FSM — конечный автомат с State / StatesGroup и подключаемым хранилищем (MemoryStorage)
  • Треды (Threads) — создание и работа с обсуждениями в чатах
  • Middleware — внешние и внутренние middleware для каждого роутера
  • Inline-клавиатуры — удобный API для построения кнопок
  • Полностью асинхронный — построен на aiohttp
  • Типизированный — включает py.typed, совместим с mypy / pyright

Установка

pip install solobot-vkteams

Быстрый старт

import asyncio
from solobot_vkteams import Bot, Dispatcher, Router, Message, Command, F

TOKEN = "YOUR_TOKEN_HERE"
API_URL = "https://myteam.mail.ru/bot/v1"

bot = Bot(token=TOKEN, api_url_base=API_URL)
dp = Dispatcher()
router = Router()


@router.message(Command("start"))
async def on_start(event: Message, bot: Bot):
    await event.answer("Привет!")


@router.message(F.text)
async def on_text(event: Message, bot: Bot):
    await event.reply(f"Вы написали: {event.text}")


dp.include_router(router)
asyncio.run(dp.run_polling(bot))

Inline-клавиатуры

from solobot_vkteams import InlineKeyboardMarkup, InlineKeyboardButton

kb = InlineKeyboardMarkup()
kb.row(
    InlineKeyboardButton(text="Да", callback_data="yes"),
    InlineKeyboardButton(text="Нет", callback_data="no"),
)

await bot.send_text(chat_id=chat_id, text="Выберите:", inline_keyboard_markup=kb)

FSM (конечный автомат)

from solobot_vkteams import State, StatesGroup, FSMContext

class Form(StatesGroup):
    name = State()
    age = State()

@router.message(Command("form"))
async def start_form(event: Message, bot: Bot, state: FSMContext):
    await state.set_state(Form.name)
    await event.answer("Как вас зовут?")

@router.message(Form.name)
async def process_name(event: Message, bot: Bot, state: FSMContext):
    await state.update_data(name=event.text)
    await state.set_state(Form.age)
    await event.answer("Сколько вам лет?")

Треды (Threads)

from solobot_vkteams import Thread

# Создание треда
@router.message(Command("createthread"))
async def cmd_create_thread(event: Message, bot: Bot):
    thread = await event.add_thread()
    await thread.send_text("👋 Обсуждение начато!")

# Отправка сообщения в тред
await bot.send_text(
    chat_id=thread_id,
    text="Сообщение в треде"
)

Требования

  • Python 3.12+
  • aiohttp >= 3.9

Лицензия

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

solobot_vkteams-0.2.1.tar.gz (19.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

solobot_vkteams-0.2.1-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

Details for the file solobot_vkteams-0.2.1.tar.gz.

File metadata

  • Download URL: solobot_vkteams-0.2.1.tar.gz
  • Upload date:
  • Size: 19.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for solobot_vkteams-0.2.1.tar.gz
Algorithm Hash digest
SHA256 57beb28605909f4fb904b116ee57bbc4721475cae3875ab242c23f20890eeffe
MD5 11d09980df2c581903565fced27dcf26
BLAKE2b-256 2346497672aa13b5ab8a4a7bc270af020efd170f8edb7bbd500c8ffbcbfa9cd4

See more details on using hashes here.

File details

Details for the file solobot_vkteams-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for solobot_vkteams-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4e05c0d65233ba221681bb4d4402d5c488de928c640cd57ab3a2f7654393029a
MD5 a13b58b738c5f4127ab6495ab5cdd9a5
BLAKE2b-256 a5e0402819f659a58bd5e9a0cccdc83370d2fceaa2e15b2c5ef386088ca5ae4d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page