Update engine/flow_router.py
Browse files- engine/flow_router.py +84 -12
engine/flow_router.py
CHANGED
|
@@ -85,7 +85,8 @@ def is_adults(text: str) -> bool:
|
|
| 85 |
def is_children(text: str) -> bool:
|
| 86 |
t = normalize_text(text)
|
| 87 |
return contains_any(t, [
|
| 88 |
-
"اطفال", "أطفال", "طفل", "children", "kids",
|
|
|
|
| 89 |
])
|
| 90 |
|
| 91 |
|
|
@@ -185,6 +186,51 @@ def wants_new_topic(text: str) -> bool:
|
|
| 185 |
])
|
| 186 |
|
| 187 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
def route_message(state: str, text: str, session: dict):
|
| 189 |
t = normalize_text(text)
|
| 190 |
flow_data = session.get("flow_data", {}) or {}
|
|
@@ -244,6 +290,9 @@ def route_message(state: str, text: str, session: dict):
|
|
| 244 |
flow_data["customer_type"] = "current"
|
| 245 |
return current_student_menu_reply(flow_data)
|
| 246 |
|
|
|
|
|
|
|
|
|
|
| 247 |
return ask_new_or_current_reply(flow_data)
|
| 248 |
|
| 249 |
# =========================
|
|
@@ -304,6 +353,16 @@ def route_message(state: str, text: str, session: dict):
|
|
| 304 |
# WAITING_BEGINNER_SCHEDULE_CHOICE
|
| 305 |
# =========================
|
| 306 |
if state == WAITING_BEGINNER_SCHEDULE_CHOICE:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 307 |
if contains_any(t, ["تم", "اخترت", "اختارت", "جاهز", "جاهزة"]):
|
| 308 |
return pdf_102_reply(flow_data)
|
| 309 |
|
|
@@ -326,6 +385,16 @@ def route_message(state: str, text: str, session: dict):
|
|
| 326 |
# WAITING_PDF_102_CONFIRMATION
|
| 327 |
# =========================
|
| 328 |
if state == WAITING_PDF_102_CONFIRMATION:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 329 |
if contains_any(t, ["تم", "خلصت", "قريت", "اطلعت", "جاهز", "جاهزة"]):
|
| 330 |
return payment_methods_reply(flow_data)
|
| 331 |
|
|
@@ -345,6 +414,16 @@ def route_message(state: str, text: str, session: dict):
|
|
| 345 |
# WAITING_PLACEMENT_TEST_CONFIRMATION
|
| 346 |
# =========================
|
| 347 |
if state == WAITING_PLACEMENT_TEST_CONFIRMATION:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 348 |
if contains_any(t, ["تم", "اخترت", "اختارت", "جاهز", "جاهزة"]):
|
| 349 |
return create_sales_handoff_result(
|
| 350 |
flow_data=flow_data,
|
|
@@ -474,7 +553,6 @@ def route_message(state: str, text: str, session: dict):
|
|
| 474 |
"reply": "العفو، تحت أمرك في أي وقت."
|
| 475 |
}
|
| 476 |
|
| 477 |
-
# لو المستخدم عايز يبدأ من جديد
|
| 478 |
if wants_restart(t) or wants_new_topic(t):
|
| 479 |
return {
|
| 480 |
"next_state": WAITING_MAIN_MENU,
|
|
@@ -482,52 +560,44 @@ def route_message(state: str, text: str, session: dict):
|
|
| 482 |
"reply": "تمام، نبدأ من جديد. إنت طالب جديد ولا طالب حالي؟"
|
| 483 |
}
|
| 484 |
|
| 485 |
-
# لو سأل عن كورسات الأطفال
|
| 486 |
if is_children(t):
|
| 487 |
new_flow = {}
|
| 488 |
new_flow["customer_type"] = "new"
|
| 489 |
new_flow["audience"] = "children"
|
| 490 |
return ask_prior_study_reply(new_flow)
|
| 491 |
|
| 492 |
-
# لو سأل عن كورسات الكبار
|
| 493 |
if is_adults(t):
|
| 494 |
new_flow = {}
|
| 495 |
new_flow["customer_type"] = "new"
|
| 496 |
new_flow["audience"] = "adults"
|
| 497 |
return ask_prior_study_reply(new_flow)
|
| 498 |
|
| 499 |
-
# لو قال طالب جديد
|
| 500 |
if is_new_student(t):
|
| 501 |
new_flow = {}
|
| 502 |
new_flow["customer_type"] = "new"
|
| 503 |
return ask_audience_reply(new_flow)
|
| 504 |
|
| 505 |
-
# لو قال طالب حالي
|
| 506 |
if is_current_student(t):
|
| 507 |
new_flow = {}
|
| 508 |
new_flow["customer_type"] = "current"
|
| 509 |
return current_student_menu_reply(new_flow)
|
| 510 |
|
| 511 |
-
|
| 512 |
-
if contains_any(t, ["كورسات", "الكورسات", "ايه الكورسات", "ما هي الكورسات", "الأنواع", "الانواع"]):
|
| 513 |
return {
|
| 514 |
"next_state": WAITING_USER_TYPE,
|
| 515 |
"flow_data": {},
|
| 516 |
"reply": "تمام، أقدر أساعدك في كورسات الطلبة الجدد أو الحاليين. إنت طالب جديد ولا طالب حالي؟"
|
| 517 |
}
|
| 518 |
|
| 519 |
-
# لو عايز خدمة العملاء
|
| 520 |
if is_support_request(t):
|
| 521 |
return create_support_handoff_result(
|
| 522 |
flow_data=flow_data,
|
| 523 |
summary=f"استفسار إضافي بعد handoff: {text}"
|
| 524 |
)
|
| 525 |
|
| 526 |
-
# لو شكوى
|
| 527 |
if is_complaint(t):
|
| 528 |
return create_complaint_flow_result(flow_data)
|
| 529 |
|
| 530 |
-
# default
|
| 531 |
return {
|
| 532 |
"next_state": HANDOFF_DONE,
|
| 533 |
"flow_data": flow_data,
|
|
@@ -535,4 +605,6 @@ def route_message(state: str, text: str, session: dict):
|
|
| 535 |
"تم تسجيل طلبك بالفعل، وفريقنا هيتواصل معاك قريب.\n"
|
| 536 |
"ولو تحب تبدأ استفسار جديد، اكتب: ابدأ من جديد."
|
| 537 |
)
|
| 538 |
-
}
|
|
|
|
|
|
|
|
|
| 85 |
def is_children(text: str) -> bool:
|
| 86 |
t = normalize_text(text)
|
| 87 |
return contains_any(t, [
|
| 88 |
+
"اطفال", "أطفال", "طفل", "children", "kids",
|
| 89 |
+
"كورسات الأطفال", "كورسات الاطفال"
|
| 90 |
])
|
| 91 |
|
| 92 |
|
|
|
|
| 186 |
])
|
| 187 |
|
| 188 |
|
| 189 |
+
def wants_courses_info(text: str) -> bool:
|
| 190 |
+
t = normalize_text(text)
|
| 191 |
+
return contains_any(t, [
|
| 192 |
+
"كورسات",
|
| 193 |
+
"الكورسات",
|
| 194 |
+
"ايه الكورسات",
|
| 195 |
+
"ما هي الكورسات",
|
| 196 |
+
"الأنواع",
|
| 197 |
+
"الانواع",
|
| 198 |
+
"عايز اعرف الكورسات",
|
| 199 |
+
"عايزة اعرف الكورسات",
|
| 200 |
+
"ايه الكورسات المتاحة",
|
| 201 |
+
"الكورسات المتاحة"
|
| 202 |
+
])
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
def asks_about_prior_study_case(text: str) -> bool:
|
| 206 |
+
t = normalize_text(text)
|
| 207 |
+
return contains_any(t, [
|
| 208 |
+
"لو كنت درست",
|
| 209 |
+
"لو كنت دارس",
|
| 210 |
+
"لو درست قبل كده",
|
| 211 |
+
"طب لو درست",
|
| 212 |
+
"ولو درست",
|
| 213 |
+
"اذا كنت درست",
|
| 214 |
+
"إذا كنت درست",
|
| 215 |
+
"اختبار تحديد مستوى",
|
| 216 |
+
"تحديد مستوى"
|
| 217 |
+
])
|
| 218 |
+
|
| 219 |
+
|
| 220 |
+
def asks_about_beginner_case(text: str) -> bool:
|
| 221 |
+
t = normalize_text(text)
|
| 222 |
+
return contains_any(t, [
|
| 223 |
+
"لو مكنتش درست",
|
| 224 |
+
"لو ما درستش",
|
| 225 |
+
"لو مدرستش",
|
| 226 |
+
"لو لسه جديد",
|
| 227 |
+
"لو مبتدئ",
|
| 228 |
+
"لو بادئ",
|
| 229 |
+
"لو اول مرة",
|
| 230 |
+
"لو أول مرة"
|
| 231 |
+
])
|
| 232 |
+
|
| 233 |
+
|
| 234 |
def route_message(state: str, text: str, session: dict):
|
| 235 |
t = normalize_text(text)
|
| 236 |
flow_data = session.get("flow_data", {}) or {}
|
|
|
|
| 290 |
flow_data["customer_type"] = "current"
|
| 291 |
return current_student_menu_reply(flow_data)
|
| 292 |
|
| 293 |
+
if wants_courses_info(t):
|
| 294 |
+
return ask_new_or_current_reply(flow_data)
|
| 295 |
+
|
| 296 |
return ask_new_or_current_reply(flow_data)
|
| 297 |
|
| 298 |
# =========================
|
|
|
|
| 353 |
# WAITING_BEGINNER_SCHEDULE_CHOICE
|
| 354 |
# =========================
|
| 355 |
if state == WAITING_BEGINNER_SCHEDULE_CHOICE:
|
| 356 |
+
if asks_about_prior_study_case(t):
|
| 357 |
+
new_flow = dict(flow_data)
|
| 358 |
+
new_flow["prior_study"] = True
|
| 359 |
+
return placement_test_reply(new_flow)
|
| 360 |
+
|
| 361 |
+
if asks_about_beginner_case(t):
|
| 362 |
+
new_flow = dict(flow_data)
|
| 363 |
+
new_flow["prior_study"] = False
|
| 364 |
+
return beginner_schedule_reply(new_flow)
|
| 365 |
+
|
| 366 |
if contains_any(t, ["تم", "اخترت", "اختارت", "جاهز", "جاهزة"]):
|
| 367 |
return pdf_102_reply(flow_data)
|
| 368 |
|
|
|
|
| 385 |
# WAITING_PDF_102_CONFIRMATION
|
| 386 |
# =========================
|
| 387 |
if state == WAITING_PDF_102_CONFIRMATION:
|
| 388 |
+
if asks_about_prior_study_case(t):
|
| 389 |
+
new_flow = dict(flow_data)
|
| 390 |
+
new_flow["prior_study"] = True
|
| 391 |
+
return placement_test_reply(new_flow)
|
| 392 |
+
|
| 393 |
+
if asks_about_beginner_case(t):
|
| 394 |
+
new_flow = dict(flow_data)
|
| 395 |
+
new_flow["prior_study"] = False
|
| 396 |
+
return beginner_schedule_reply(new_flow)
|
| 397 |
+
|
| 398 |
if contains_any(t, ["تم", "خلصت", "قريت", "اطلعت", "جاهز", "جاهزة"]):
|
| 399 |
return payment_methods_reply(flow_data)
|
| 400 |
|
|
|
|
| 414 |
# WAITING_PLACEMENT_TEST_CONFIRMATION
|
| 415 |
# =========================
|
| 416 |
if state == WAITING_PLACEMENT_TEST_CONFIRMATION:
|
| 417 |
+
if asks_about_beginner_case(t):
|
| 418 |
+
new_flow = dict(flow_data)
|
| 419 |
+
new_flow["prior_study"] = False
|
| 420 |
+
return beginner_schedule_reply(new_flow)
|
| 421 |
+
|
| 422 |
+
if asks_about_prior_study_case(t):
|
| 423 |
+
new_flow = dict(flow_data)
|
| 424 |
+
new_flow["prior_study"] = True
|
| 425 |
+
return placement_test_reply(new_flow)
|
| 426 |
+
|
| 427 |
if contains_any(t, ["تم", "اخترت", "اختارت", "جاهز", "جاهزة"]):
|
| 428 |
return create_sales_handoff_result(
|
| 429 |
flow_data=flow_data,
|
|
|
|
| 553 |
"reply": "العفو، تحت أمرك في أي وقت."
|
| 554 |
}
|
| 555 |
|
|
|
|
| 556 |
if wants_restart(t) or wants_new_topic(t):
|
| 557 |
return {
|
| 558 |
"next_state": WAITING_MAIN_MENU,
|
|
|
|
| 560 |
"reply": "تمام، نبدأ من جديد. إنت طالب جديد ولا طالب حالي؟"
|
| 561 |
}
|
| 562 |
|
|
|
|
| 563 |
if is_children(t):
|
| 564 |
new_flow = {}
|
| 565 |
new_flow["customer_type"] = "new"
|
| 566 |
new_flow["audience"] = "children"
|
| 567 |
return ask_prior_study_reply(new_flow)
|
| 568 |
|
|
|
|
| 569 |
if is_adults(t):
|
| 570 |
new_flow = {}
|
| 571 |
new_flow["customer_type"] = "new"
|
| 572 |
new_flow["audience"] = "adults"
|
| 573 |
return ask_prior_study_reply(new_flow)
|
| 574 |
|
|
|
|
| 575 |
if is_new_student(t):
|
| 576 |
new_flow = {}
|
| 577 |
new_flow["customer_type"] = "new"
|
| 578 |
return ask_audience_reply(new_flow)
|
| 579 |
|
|
|
|
| 580 |
if is_current_student(t):
|
| 581 |
new_flow = {}
|
| 582 |
new_flow["customer_type"] = "current"
|
| 583 |
return current_student_menu_reply(new_flow)
|
| 584 |
|
| 585 |
+
if wants_courses_info(t):
|
|
|
|
| 586 |
return {
|
| 587 |
"next_state": WAITING_USER_TYPE,
|
| 588 |
"flow_data": {},
|
| 589 |
"reply": "تمام، أقدر أساعدك في كورسات الطلبة الجدد أو الحاليين. إنت طالب جديد ولا طالب حالي؟"
|
| 590 |
}
|
| 591 |
|
|
|
|
| 592 |
if is_support_request(t):
|
| 593 |
return create_support_handoff_result(
|
| 594 |
flow_data=flow_data,
|
| 595 |
summary=f"استفسار إضافي بعد handoff: {text}"
|
| 596 |
)
|
| 597 |
|
|
|
|
| 598 |
if is_complaint(t):
|
| 599 |
return create_complaint_flow_result(flow_data)
|
| 600 |
|
|
|
|
| 601 |
return {
|
| 602 |
"next_state": HANDOFF_DONE,
|
| 603 |
"flow_data": flow_data,
|
|
|
|
| 605 |
"تم تسجيل طلبك بالفعل، وفريقنا هيتواصل معاك قريب.\n"
|
| 606 |
"ولو تحب تبدأ استفسار جديد، اكتب: ابدأ من جديد."
|
| 607 |
)
|
| 608 |
+
}
|
| 609 |
+
|
| 610 |
+
return unknown_reply(flow_data)
|