init
This commit is contained in:
57
bot/handlers2.py
Normal file
57
bot/handlers2.py
Normal file
@@ -0,0 +1,57 @@
|
||||
from aiogram import Router
|
||||
from aiogram.filters import Command
|
||||
from aiogram.filters.callback_data import CallbackData
|
||||
from aiogram.fsm.context import FSMContext
|
||||
from aiogram.types import (
|
||||
CallbackQuery,
|
||||
InlineKeyboardButton,
|
||||
InlineKeyboardMarkup,
|
||||
Message,
|
||||
)
|
||||
|
||||
from bot.ai_roles import ROLES
|
||||
from bot.ai_tool import get_gigachat_response
|
||||
|
||||
handlers_router = Router()
|
||||
|
||||
|
||||
class RoleSelect(CallbackData, prefix="role_select"):
|
||||
role: str
|
||||
|
||||
|
||||
@handlers_router.message(Command(commands=["start"]))
|
||||
async def start_handler(message: Message) -> None:
|
||||
await message.answer(
|
||||
text="Привет!\n\nЯ бот для важных переговоров!\n\nПросто отправь мне свой текст..."
|
||||
)
|
||||
|
||||
|
||||
@handlers_router.callback_query(RoleSelect.filter())
|
||||
async def select_role(
|
||||
query: CallbackQuery, callback_data: RoleSelect, state: FSMContext
|
||||
) -> None:
|
||||
user_text = await state.get_value("user_text")
|
||||
|
||||
ai_response = await get_gigachat_response(
|
||||
user_text=user_text, role=callback_data.role
|
||||
)
|
||||
|
||||
await query.message.edit_text(text=ai_response, reply_markup=None)
|
||||
|
||||
|
||||
@handlers_router.message()
|
||||
async def echo_handler(message: Message, state: FSMContext) -> None:
|
||||
await state.update_data(user_text=message.text)
|
||||
keyboards = [
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
text=v.get("name"), callback_data=RoleSelect(role=k).pack()
|
||||
)
|
||||
]
|
||||
for k, v in ROLES.items()
|
||||
]
|
||||
|
||||
await message.answer(
|
||||
text="Выбери в каком стиле хочешь получить ответ:",
|
||||
reply_markup=InlineKeyboardMarkup(inline_keyboard=keyboards),
|
||||
)
|
||||
Reference in New Issue
Block a user