v1.6.0: max_bot fixes — feature keys, flush→commit, test-run, categories, broadcast page, proxy error handling, deploy scripts
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
from app.settings_cache import SettingsCache
|
||||
from app.conversation import get_or_create_user, get_template_rendered
|
||||
from app.fsm import BotState, FSM
|
||||
from app.keyboards.inline import build_main_menu_buttons
|
||||
|
||||
|
||||
async def handle_reminders(bot, user_data: dict, db, max_api):
|
||||
max_user_id = user_data["user_id"]
|
||||
text = user_data.get("text", "").strip()
|
||||
|
||||
if FSM.get_state(max_user_id) != BotState.FEATURE_REMINDERS:
|
||||
FSM.set_state(max_user_id, BotState.FEATURE_REMINDERS)
|
||||
user = await get_or_create_user(db, max_user_id)
|
||||
phone = user.phone or ""
|
||||
|
||||
from sqlalchemy import select, func
|
||||
from app.models.models import BotConversation, BotTicket, Customer
|
||||
|
||||
open_convs = await db.execute(
|
||||
select(func.count(BotConversation.id))
|
||||
.where(BotConversation.status.in_(["open", "handoff"]))
|
||||
)
|
||||
total_open = open_convs.scalar() or 0
|
||||
|
||||
open_tickets = await db.execute(
|
||||
select(func.count(BotTicket.id))
|
||||
.where(BotTicket.status.in_(["open", "in_progress"]))
|
||||
)
|
||||
total_tickets = open_tickets.scalar() or 0
|
||||
|
||||
my_convs = await db.execute(
|
||||
select(func.count(BotConversation.id))
|
||||
.where(BotConversation.user_id == user.id, BotConversation.status.in_(["open", "handoff"]))
|
||||
)
|
||||
my_open = my_convs.scalar() or 0
|
||||
|
||||
text = (
|
||||
"🔔 **Напоминания**\n\n"
|
||||
f"У вас открыто обращений: {my_open}\n"
|
||||
f"Всего в системе: {total_open} обращений, {total_tickets} заявок\n\n"
|
||||
"Напоминания о плановом ТО настраиваются в портале."
|
||||
)
|
||||
await max_api.send_message(max_user_id, text, format="markdown")
|
||||
FSM.transition(max_user_id, "done")
|
||||
buttons = build_main_menu_buttons()
|
||||
menu_text = await get_template_rendered(db, "main_menu")
|
||||
await max_api.send_message_with_keyboard(max_user_id, menu_text, buttons)
|
||||
return
|
||||
Reference in New Issue
Block a user