33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
from app.settings_cache import SettingsCache
|
|
from app.conversation import get_or_create_user, get_open_conversation, get_template_rendered
|
|
from app.fsm import BotState, FSM
|
|
|
|
|
|
async def handle_handoff_request(bot, user_data: dict, db, max_api):
|
|
max_user_id = user_data["user_id"]
|
|
user = await get_or_create_user(db, max_user_id)
|
|
|
|
if not SettingsCache.is_work_hours():
|
|
from app.handlers.out_of_hours import handle_out_of_hours
|
|
await handle_out_of_hours(bot, user_data, db, max_api)
|
|
return
|
|
|
|
text = await get_template_rendered(db, "handoff")
|
|
await max_api.send_message(max_user_id, text)
|
|
|
|
conv = await get_open_conversation(db, user.id)
|
|
if conv:
|
|
conv.status = "handoff"
|
|
conv.priority = "high"
|
|
await db.flush()
|
|
|
|
from app.integrations import _1c_unf as ic_integration
|
|
await ic_integration.send_to_1c(db, conv)
|
|
|
|
FSM.set_state(max_user_id, BotState.HANDOFF_REQUEST)
|
|
|
|
|
|
async def handle_inquiry_fallback(bot, user_data, db, max_api):
|
|
from app.handlers.inquiry import handle_inquiry
|
|
await handle_inquiry(bot, user_data, db, max_api)
|