Spaces:
Sleeping
Sleeping
OnlyBiggg
commited on
Commit
·
57d122f
1
Parent(s):
dddff76
fix
Browse files
app/dialogflow/api/v1/dialogflow.py
CHANGED
|
@@ -59,10 +59,19 @@ async def confirm(request: Request):
|
|
| 59 |
origin_office = parameters.get("origin_office")
|
| 60 |
dest_office = parameters.get("dest_office")
|
| 61 |
raw_ticket_number = parameters.get("ticket_number")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
ticket_number = int(raw_ticket_number) if raw_ticket_number else 1
|
| 63 |
date = dialog_service.to_datetime_from_Dialogflow(raw_date)
|
| 64 |
date, week_day = get_weekday_name(date)
|
| 65 |
-
text = [f"""**
|
| 66 |
temp = ""
|
| 67 |
if origin_office and dest_office:
|
| 68 |
temp = f"""**Điểm đi:** {origin_office}\n**Điểm đến:** {dest_office}\n"""
|
|
@@ -387,6 +396,45 @@ async def is_valid_select_trip(request: Request) -> Response:
|
|
| 387 |
}
|
| 388 |
return DialogFlowResponseAPI(parameters=parameters)
|
| 389 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 390 |
@router.post('/trip/time-trip-list')
|
| 391 |
async def time_trip(request: Request) -> Response:
|
| 392 |
try:
|
|
|
|
| 59 |
origin_office = parameters.get("origin_office")
|
| 60 |
dest_office = parameters.get("dest_office")
|
| 61 |
raw_ticket_number = parameters.get("ticket_number")
|
| 62 |
+
time = parameters.get("time-select")
|
| 63 |
+
|
| 64 |
+
time = extra_time_dialogflow(time)
|
| 65 |
+
|
| 66 |
+
if isinstance(time, list):
|
| 67 |
+
|
| 68 |
+
parameters["is_time_ambiguous"] = True
|
| 69 |
+
return DialogFlowResponseAPI(parameters=parameters)
|
| 70 |
+
|
| 71 |
ticket_number = int(raw_ticket_number) if raw_ticket_number else 1
|
| 72 |
date = dialog_service.to_datetime_from_Dialogflow(raw_date)
|
| 73 |
date, week_day = get_weekday_name(date)
|
| 74 |
+
text = [f"""**Thời gian:** {time} - {date} - {week_day}\n**Số vé:** {ticket_number}"""]
|
| 75 |
temp = ""
|
| 76 |
if origin_office and dest_office:
|
| 77 |
temp = f"""**Điểm đi:** {origin_office}\n**Điểm đến:** {dest_office}\n"""
|
|
|
|
| 396 |
}
|
| 397 |
return DialogFlowResponseAPI(parameters=parameters)
|
| 398 |
|
| 399 |
+
@router.post('/trip/select-time-ambiguous')
|
| 400 |
+
async def time_trip(request: Request) -> Response:
|
| 401 |
+
try:
|
| 402 |
+
body = await request.json()
|
| 403 |
+
session_info = body.get("sessionInfo", {})
|
| 404 |
+
parameters = session_info.get("parameters")
|
| 405 |
+
time = parameters.get("time-select")
|
| 406 |
+
|
| 407 |
+
text = []
|
| 408 |
+
payload = {}
|
| 409 |
+
parameters = {}
|
| 410 |
+
|
| 411 |
+
time = extra_time_dialogflow(time)
|
| 412 |
+
|
| 413 |
+
if isinstance(time, list):
|
| 414 |
+
parameters["is_time_ambiguous"] = True
|
| 415 |
+
text = [f"Quý khách dự định đi vào lúc"]
|
| 416 |
+
payload={
|
| 417 |
+
"richContent": [
|
| 418 |
+
[
|
| 419 |
+
{
|
| 420 |
+
"type": "chips",
|
| 421 |
+
"options": [
|
| 422 |
+
{"text": item} for item in (time)
|
| 423 |
+
]
|
| 424 |
+
}
|
| 425 |
+
]
|
| 426 |
+
]
|
| 427 |
+
}
|
| 428 |
+
else:
|
| 429 |
+
parameters["is_time_ambiguous"] = None
|
| 430 |
+
|
| 431 |
+
return DialogFlowResponseAPI(text=text, payload=payload ,parameters=parameters)
|
| 432 |
+
|
| 433 |
+
except Exception as e:
|
| 434 |
+
print(e)
|
| 435 |
+
return DialogFlowResponseAPI(text=["Hệ thống xảy ra lỗi. Quý khách vui lòng thử lại sau hoặc liên hệ Trung tâm tổng đài 1900 6067 để được hỗ trợ."])
|
| 436 |
+
|
| 437 |
+
|
| 438 |
@router.post('/trip/time-trip-list')
|
| 439 |
async def time_trip(request: Request) -> Response:
|
| 440 |
try:
|
utils/format_data_dialog.py
CHANGED
|
@@ -24,9 +24,13 @@ def extra_time_dialogflow(time: dict) -> str | list:
|
|
| 24 |
Nếu time có ambiguous (past, future) => trả về list [past_time_str, future_time_str]
|
| 25 |
Nếu time rõ ràng => trả về string "HH:mm"
|
| 26 |
"""
|
|
|
|
| 27 |
def is_time_ambiguous(time_obj: dict) -> bool:
|
| 28 |
return any(time_obj.get(key) for key in ['past', 'future', 'partial'])
|
| 29 |
|
|
|
|
|
|
|
|
|
|
| 30 |
if is_time_ambiguous(time):
|
| 31 |
past_time = time.get("past", {})
|
| 32 |
future_time = time.get("future", {})
|
|
|
|
| 24 |
Nếu time có ambiguous (past, future) => trả về list [past_time_str, future_time_str]
|
| 25 |
Nếu time rõ ràng => trả về string "HH:mm"
|
| 26 |
"""
|
| 27 |
+
|
| 28 |
def is_time_ambiguous(time_obj: dict) -> bool:
|
| 29 |
return any(time_obj.get(key) for key in ['past', 'future', 'partial'])
|
| 30 |
|
| 31 |
+
if time is None:
|
| 32 |
+
return None
|
| 33 |
+
|
| 34 |
if is_time_ambiguous(time):
|
| 35 |
past_time = time.get("past", {})
|
| 36 |
future_time = time.get("future", {})
|