Spaces:
Sleeping
Sleeping
OnlyBiggg
commited on
Commit
·
9484a7b
1
Parent(s):
e443ec3
fix
Browse files- app/api/routes.py +4 -1
- app/types/Respone.py +9 -2
app/api/routes.py
CHANGED
@@ -224,7 +224,10 @@ async def booking_trip(request: Request) -> Response:
|
|
224 |
if trip["route"] and trip["route"]["name"] not in routes_name:
|
225 |
routes_name.append(trip["route"]["name"])
|
226 |
text = [" | ".join(map(str, routes_name))]
|
227 |
-
|
|
|
|
|
|
|
228 |
|
229 |
text = [f"Hệ thống không tìm thấy tuyến xe **{raw_departure_city}** - **{raw_destination_city}**.\n Quý khách vui lòng thử lại với lộ trình khác hoặc liên hệ Trung tâm tổng đài 1900 6067 để được hỗ trợ."]
|
230 |
payload={
|
|
|
224 |
if trip["route"] and trip["route"]["name"] not in routes_name:
|
225 |
routes_name.append(trip["route"]["name"])
|
226 |
text = [" | ".join(map(str, routes_name))]
|
227 |
+
parameters = {
|
228 |
+
"trip_list": routes_name
|
229 |
+
}
|
230 |
+
return DialogFlowResponseAPI(text=text, parameters=parameters)
|
231 |
|
232 |
text = [f"Hệ thống không tìm thấy tuyến xe **{raw_departure_city}** - **{raw_destination_city}**.\n Quý khách vui lòng thử lại với lộ trình khác hoặc liên hệ Trung tâm tổng đài 1900 6067 để được hỗ trợ."]
|
233 |
payload={
|
app/types/Respone.py
CHANGED
@@ -14,10 +14,16 @@ class Message(BaseModel):
|
|
14 |
class FulfillmentResponse(BaseModel):
|
15 |
messages: List[Message]
|
16 |
|
|
|
|
|
|
|
|
|
|
|
17 |
class DialogflowResponse(BaseModel):
|
18 |
fulfillment_response: FulfillmentResponse
|
|
|
19 |
|
20 |
-
def DialogFlowResponseAPI(text: List[str], payload: Optional[Dict[str, Any]] = None):
|
21 |
"""
|
22 |
Hàm tạo JSON response cho Dialogflow CX, hỗ trợ payload tùy chỉnh.
|
23 |
"""
|
@@ -29,7 +35,8 @@ def DialogFlowResponseAPI(text: List[str], payload: Optional[Dict[str, Any]] = N
|
|
29 |
messages.append(Message(payload=payload))
|
30 |
|
31 |
response_data = DialogflowResponse(
|
32 |
-
fulfillment_response=FulfillmentResponse(messages=messages)
|
|
|
33 |
)
|
34 |
|
35 |
return JSONResponse(content=response_data.model_dump())
|
|
|
14 |
class FulfillmentResponse(BaseModel):
|
15 |
messages: List[Message]
|
16 |
|
17 |
+
|
18 |
+
class SessionInfo(BaseModel):
|
19 |
+
parameters: Dict[str, Any]
|
20 |
+
|
21 |
+
|
22 |
class DialogflowResponse(BaseModel):
|
23 |
fulfillment_response: FulfillmentResponse
|
24 |
+
sessionInfo: Optional[SessionInfo] = None
|
25 |
|
26 |
+
def DialogFlowResponseAPI(text: List[str], payload: Optional[Dict[str, Any]] = None, parameters: Optional[Dict[str, Any]] = None):
|
27 |
"""
|
28 |
Hàm tạo JSON response cho Dialogflow CX, hỗ trợ payload tùy chỉnh.
|
29 |
"""
|
|
|
35 |
messages.append(Message(payload=payload))
|
36 |
|
37 |
response_data = DialogflowResponse(
|
38 |
+
fulfillment_response=FulfillmentResponse(messages=messages),
|
39 |
+
sessionInfo=SessionInfo(parameters=parameters)
|
40 |
)
|
41 |
|
42 |
return JSONResponse(content=response_data.model_dump())
|