v1.8.1: fix consent flow — split-based word matching, refuse words before quick_intent, operator handler, plain text phones, clarify_intent post-processing

This commit is contained in:
2026-06-01 19:54:11 +03:00
parent cc87bcf72c
commit a64a274829
5 changed files with 142 additions and 25 deletions
+39 -7
View File
@@ -119,9 +119,45 @@ async def handle_message(user_id: int, text: str) -> None:
state = conv.state
logger.info(f"handle_message: user={user_id} state={state} conv_id={conv.id}")
text_lower = text.strip().lower()
refuse_words = ["нет", "не даю", "не хочу", "отказ", "отмена", "no", "cancel", "я отказался"]
operator_words = ["оператор", "живой человек", "связать с оператором", "переключить на оператора"]
if any(w in text_lower for w in operator_words):
from app.config_reader import config_reader
phones = config_reader.get_phones()
email = config_reader.get_site_mail()
phone_text = "\n".join(f"📞 {phone}" for phone, _ in phones)
await max_api.send_message(
user_id,
"К сожалению, я не могу переключить вас на оператора.\n\n"
"Но вы можете связаться с нами напрямую:\n"
f"{phone_text}\n"
f"📧 {email}\n\n"
"Мы обязательно ответим и поможем!",
)
return
if state in ("greeting", "analyzing", "awaiting_input"):
await analyze_and_respond(user_id, conv.id, text)
elif state in ("awaiting_consent", "consent_refused", "awaiting_contact"):
if any(w in text_lower for w in refuse_words):
if state == "awaiting_consent":
from app.handlers.consent import handle_consent_no
await handle_consent_no(user_id, conv.id)
elif state == "consent_refused":
from app.handlers.consent import handle_refused_again
await handle_refused_again(user_id, conv.id, text)
elif state == "awaiting_contact":
async with async_session() as db:
conv_upd = await db.get(BotConversation, conv.id)
if conv_upd:
conv_upd.state = "consent_refused"
await db.commit()
from app.handlers.consent import handle_refused_again
await handle_refused_again(user_id, conv.id, text)
return
quick_intent = await yandex_gpt.analyze_intent(text)
if quick_intent == "question":
await analyze_and_respond(user_id, conv.id, text)
@@ -272,19 +308,15 @@ async def _send_contacts(user_id: int) -> None:
phones = config_reader.get_phones()
email = config_reader.get_site_mail()
phone_text = "\n".join(
f"📞 {phone} — [позвонить](tel:{link})"
for phone, link in phones
)
phone_text = "\n".join(f"📞 {phone}" for phone, _ in phones)
message = (
"Вы можете связаться с нами:\n\n"
f"{phone_text}\n"
f"📧 [Написать на почту](mailto:{email})\n\n"
f"Или написать на почту: {email}"
f"📧 {email}"
)
await max_api.send_message(user_id, message, format="markdown")
await max_api.send_message(user_id, message)
async def _get_knowledge_base_context(query: str) -> str: