Spaces:
Sleeping
Sleeping
OnlyBiggg
commited on
Commit
·
0461c2d
1
Parent(s):
c403e5c
add
Browse files
app/dialogflow/api/v1/dialogflow.py
CHANGED
@@ -14,6 +14,40 @@ router = APIRouter()
|
|
14 |
templates = Jinja2Templates(directory="templates")
|
15 |
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
@router.post('/info/confirm')
|
18 |
async def confirm(request: Request):
|
19 |
body = await request.json()
|
|
|
14 |
templates = Jinja2Templates(directory="templates")
|
15 |
|
16 |
|
17 |
+
@router.post('/search/origin-city/from/office')
|
18 |
+
async def search_origin_office(request: Request):
|
19 |
+
body = await request.json()
|
20 |
+
|
21 |
+
session_info = body.get("sessionInfo", {})
|
22 |
+
parameters = session_info.get("parameters")
|
23 |
+
|
24 |
+
raw_departure_city = session_info.get("departure_city")
|
25 |
+
origin_office = parameters.get("origin_office")
|
26 |
+
|
27 |
+
if origin_office and raw_departure_city is None:
|
28 |
+
departure_city = dialog_service.get_origin_city_from_office(origin_office)
|
29 |
+
|
30 |
+
parameters = {
|
31 |
+
"departure_city": departure_city
|
32 |
+
}
|
33 |
+
return DialogFlowResponseAPI(parameters=parameters)
|
34 |
+
|
35 |
+
@router.post('/search/destination-city/from/office')
|
36 |
+
async def search_destination_office(request: Request):
|
37 |
+
body = await request.json()
|
38 |
+
session_info = body.get("sessionInfo", {})
|
39 |
+
parameters = session_info.get("parameters")
|
40 |
+
|
41 |
+
raw_destination_city = session_info.get("destination_city")
|
42 |
+
dest_office = parameters.get("dest_office")
|
43 |
+
|
44 |
+
if dest_office and raw_destination_city is None:
|
45 |
+
destination_city = dialog_service.get_destination_city_from_office(dest_office)
|
46 |
+
|
47 |
+
parameters = {
|
48 |
+
"destination_city": destination_city
|
49 |
+
}
|
50 |
+
return DialogFlowResponseAPI(parameters=parameters)
|
51 |
@router.post('/info/confirm')
|
52 |
async def confirm(request: Request):
|
53 |
body = await request.json()
|
app/dialogflow/services/dialog_service.py
CHANGED
@@ -155,7 +155,47 @@ class DialogService:
|
|
155 |
if dropoff_data['name'] == dropoff:
|
156 |
return True
|
157 |
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
|
160 |
dialog_service: DialogService = DialogService()
|
161 |
|
|
|
155 |
if dropoff_data['name'] == dropoff:
|
156 |
return True
|
157 |
return False
|
158 |
+
async def search_pickup_points(origin: str = None, dest: str = None):
|
159 |
+
session_id = str(int(datetime.now().timestamp()))
|
160 |
+
params = {
|
161 |
+
"origin": origin,
|
162 |
+
"dest": dest,
|
163 |
+
"session_id": session_id,
|
164 |
+
}
|
165 |
+
response = await api.get('search/metadata/pickup-points', params=params)
|
166 |
+
if response.get("status") == 200:
|
167 |
+
data = response.get("data")
|
168 |
+
return data
|
169 |
+
return None
|
170 |
+
|
171 |
+
|
172 |
+
async def get_origin_city_from_office(self, origin_office: str):
|
173 |
+
data = self.search_pickup_points(origin=origin_office)
|
174 |
+
if data.get["origin"]:
|
175 |
+
origins = data["origin"]
|
176 |
+
for origin in origins:
|
177 |
+
if origin.get("group"):
|
178 |
+
groups = origin["group"]
|
179 |
+
for group in groups:
|
180 |
+
if group.get("name"):
|
181 |
+
name = group["name"]
|
182 |
+
if name == origin_office:
|
183 |
+
return group["provinceName"]
|
184 |
+
return None
|
185 |
|
186 |
+
async def get_destination_city_from_office(self, dest_office: str):
|
187 |
+
data = self.search_pickup_points(dest=dest_office)
|
188 |
+
if data.get("dest"):
|
189 |
+
dests = data["dest"]
|
190 |
+
for dest in dests:
|
191 |
+
if dest.get("group"):
|
192 |
+
groups = dest["group"]
|
193 |
+
for group in groups:
|
194 |
+
if group.get("name"):
|
195 |
+
name = group["name"]
|
196 |
+
if name == dest_office:
|
197 |
+
return group["provinceName"]
|
198 |
+
return None
|
199 |
|
200 |
dialog_service: DialogService = DialogService()
|
201 |
|
static/files/code_province.json
CHANGED
@@ -52,6 +52,7 @@
|
|
52 |
"Bà Rịa - Vũng Tàu": "VUNGTAU",
|
53 |
"Hồ Chí Minh": "TPHCM",
|
54 |
"Thành phố Hồ Chí Minh": "TPHCM",
|
|
|
55 |
"Long An": "LONGAN",
|
56 |
"Tiền Giang": "TIENGIANG",
|
57 |
"Bến Tre": "BENTRE",
|
|
|
52 |
"Bà Rịa - Vũng Tàu": "VUNGTAU",
|
53 |
"Hồ Chí Minh": "TPHCM",
|
54 |
"Thành phố Hồ Chí Minh": "TPHCM",
|
55 |
+
"TP. Hồ Chí Minh": "TPHCM",
|
56 |
"Long An": "LONGAN",
|
57 |
"Tiền Giang": "TIENGIANG",
|
58 |
"Bến Tre": "BENTRE",
|