feat: implement adapter/telegram/ with aiogram 3.x
Virtual DM chats, FSM (idle/waiting_response/settings states), SQLite local DB for tg_users+chats, converter, keyboards, and handlers for /start, /new, /chats, /settings, confirm callbacks.
This commit is contained in:
parent
a3449fc864
commit
9c555261b3
15 changed files with 791 additions and 0 deletions
0
adapter/telegram/keyboards/__init__.py
Normal file
0
adapter/telegram/keyboards/__init__.py
Normal file
16
adapter/telegram/keyboards/chat.py
Normal file
16
adapter/telegram/keyboards/chat.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
# adapter/telegram/keyboards/chat.py
|
||||
from __future__ import annotations
|
||||
|
||||
from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup
|
||||
|
||||
|
||||
def chats_list_keyboard(chats: list[dict], active_chat_id: str | None) -> InlineKeyboardMarkup:
|
||||
buttons = []
|
||||
for chat in chats:
|
||||
mark = "● " if chat["chat_id"] == active_chat_id else ""
|
||||
buttons.append([InlineKeyboardButton(
|
||||
text=f"{mark}{chat['name']}",
|
||||
callback_data=f"switch:{chat['chat_id']}:{chat['name']}",
|
||||
)])
|
||||
buttons.append([InlineKeyboardButton(text="➕ Новый чат", callback_data="new_chat")])
|
||||
return InlineKeyboardMarkup(inline_keyboard=buttons)
|
||||
11
adapter/telegram/keyboards/confirm.py
Normal file
11
adapter/telegram/keyboards/confirm.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
# adapter/telegram/keyboards/confirm.py
|
||||
from __future__ import annotations
|
||||
|
||||
from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup
|
||||
|
||||
|
||||
def confirm_keyboard(action_id: str) -> InlineKeyboardMarkup:
|
||||
return InlineKeyboardMarkup(inline_keyboard=[[
|
||||
InlineKeyboardButton(text="✅ Да", callback_data=f"confirm:yes:{action_id}"),
|
||||
InlineKeyboardButton(text="❌ Нет", callback_data=f"confirm:no:{action_id}"),
|
||||
]])
|
||||
52
adapter/telegram/keyboards/settings.py
Normal file
52
adapter/telegram/keyboards/settings.py
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
# adapter/telegram/keyboards/settings.py
|
||||
from __future__ import annotations
|
||||
|
||||
from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup
|
||||
|
||||
from platform.interface import UserSettings
|
||||
|
||||
|
||||
def settings_main_keyboard() -> InlineKeyboardMarkup:
|
||||
return InlineKeyboardMarkup(inline_keyboard=[
|
||||
[
|
||||
InlineKeyboardButton(text="🧩 Скиллы", callback_data="settings:skills"),
|
||||
InlineKeyboardButton(text="🔗 Коннекторы", callback_data="settings:connectors"),
|
||||
],
|
||||
[
|
||||
InlineKeyboardButton(text="🧠 Личность", callback_data="settings:soul"),
|
||||
InlineKeyboardButton(text="🔒 Безопасность", callback_data="settings:safety"),
|
||||
],
|
||||
[
|
||||
InlineKeyboardButton(text="💳 Подписка", callback_data="settings:plan"),
|
||||
],
|
||||
])
|
||||
|
||||
|
||||
def skills_keyboard(skills: dict[str, bool]) -> InlineKeyboardMarkup:
|
||||
buttons = []
|
||||
for skill, enabled in skills.items():
|
||||
icon = "✅" if enabled else "❌"
|
||||
buttons.append([InlineKeyboardButton(
|
||||
text=f"{icon} {skill}",
|
||||
callback_data=f"toggle_skill:{skill}",
|
||||
)])
|
||||
buttons.append([InlineKeyboardButton(text="← Назад", callback_data="settings:back")])
|
||||
return InlineKeyboardMarkup(inline_keyboard=buttons)
|
||||
|
||||
|
||||
def safety_keyboard(safety: dict[str, bool]) -> InlineKeyboardMarkup:
|
||||
buttons = []
|
||||
for trigger, enabled in safety.items():
|
||||
icon = "✅" if enabled else "❌"
|
||||
buttons.append([InlineKeyboardButton(
|
||||
text=f"{icon} {trigger}",
|
||||
callback_data=f"toggle_safety:{trigger}",
|
||||
)])
|
||||
buttons.append([InlineKeyboardButton(text="← Назад", callback_data="settings:back")])
|
||||
return InlineKeyboardMarkup(inline_keyboard=buttons)
|
||||
|
||||
|
||||
def back_keyboard() -> InlineKeyboardMarkup:
|
||||
return InlineKeyboardMarkup(inline_keyboard=[
|
||||
[InlineKeyboardButton(text="← Назад", callback_data="settings:back")],
|
||||
])
|
||||
Loading…
Add table
Add a link
Reference in a new issue