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,69 @@
|
||||
from app.settings_cache import SettingsCache
|
||||
from app.conversation import get_or_create_user, get_open_conversation, create_conversation, add_message, get_template_rendered
|
||||
from app.fsm import BotState, FSM
|
||||
from app.keyboards.inline import build_main_menu_buttons
|
||||
|
||||
|
||||
async def handle_photo_report(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_PHOTO_REPORT:
|
||||
FSM.set_state(max_user_id, BotState.FEATURE_PHOTO_REPORT)
|
||||
await max_api.send_message(max_user_id,
|
||||
"📸 **Фото-отчёт**\n\n"
|
||||
"Отправьте фото проблемы и опишите, что произошло.\n"
|
||||
"Вы можете прикрепить документ (PDF, DOCX, XLSX, TXT)."
|
||||
)
|
||||
return
|
||||
|
||||
user = await get_or_create_user(db, max_user_id)
|
||||
conv = await get_open_conversation(db, user.id)
|
||||
if not conv:
|
||||
conv = await create_conversation(db, user.id)
|
||||
|
||||
has_attachment = user_data.get("has_attachment", False)
|
||||
attachment_type = user_data.get("attachment_type", "")
|
||||
attachment_path = user_data.get("attachment_path", "")
|
||||
|
||||
conv.inquiry_text = text or "Фото-отчёт"
|
||||
conv.has_attachment = has_attachment
|
||||
conv.attachment_type = attachment_type
|
||||
conv.attachment_path = attachment_path
|
||||
conv.priority = "high"
|
||||
await db.flush()
|
||||
|
||||
await add_message(db, conv.id, "in", text, has_attachment, attachment_type, attachment_path)
|
||||
|
||||
ooh = not SettingsCache.is_work_hours()
|
||||
if ooh:
|
||||
start = SettingsCache.get_int("work_hours_start", 9)
|
||||
end = SettingsCache.get_int("work_hours_end", 18)
|
||||
ooh_text = await get_template_rendered(db, "out_of_hours",
|
||||
work_hours_start=start, work_hours_end=end)
|
||||
await max_api.send_message(max_user_id, ooh_text)
|
||||
|
||||
text = await get_template_rendered(db, "confirmation_ooh" if ooh else "confirmation",
|
||||
first_name=user.first_name, conv_id=conv.id)
|
||||
await max_api.send_message(max_user_id, text, format="markdown")
|
||||
|
||||
from app.integrations import _1c_unf as ic_integration
|
||||
await ic_integration.send_to_1c(db, conv)
|
||||
|
||||
from app.models.models import Incident
|
||||
incident = Incident(
|
||||
object_id=0,
|
||||
reported_by=None,
|
||||
title=f"Фото-отчёт от {user.first_name or 'клиента'}",
|
||||
description=text or "Фото-отчёт через бота",
|
||||
severity="P3",
|
||||
status="open",
|
||||
)
|
||||
db.add(incident)
|
||||
await db.flush()
|
||||
conv.attachment_path = f"incident_{incident.id}"
|
||||
|
||||
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)
|
||||
Reference in New Issue
Block a user