OnlyBiggg commited on
Commit
1c87f53
·
1 Parent(s): 8e4fa41

feat: /info/cofirm

Browse files
app/dialogflow/api/v1/dialogflow.py CHANGED
@@ -4,7 +4,7 @@ from fastapi.responses import JSONResponse, RedirectResponse, HTMLResponse # typ
4
  from datetime import datetime, timedelta
5
  from fastapi.templating import Jinja2Templates
6
  from app.dialogflow.services.dialog_service import dialog_service
7
- from utils.format_data_dialog import format_time
8
 
9
  from common.external.external_api import api
10
  from app.dialogflow.services.origin_codes import origin_codes
@@ -13,6 +13,62 @@ router = APIRouter()
13
 
14
  templates = Jinja2Templates(directory="templates")
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  @router.post('/routes')
17
  async def route(request: Request):
18
  body = await request.json()
@@ -576,23 +632,22 @@ async def response_ticket_info(request: Request) -> Response:
576
  price = int(price) if price else None
577
 
578
  text = [
579
- f"""
580
- **Thông tin hành khách**
581
-
582
- Họ và tên {user_name}
583
- Số điện thoại {phone_number}
584
- Email {email}
585
- """,
586
- f"""
587
- **Thông tin lượt đi**
588
-
589
- Tuyến xe {route_name}
590
- Thời gian xuất bến {time} {date}
591
- Số ghế {seat}
592
- Điểm lên xe {pickup}
593
- Điểm trả khách {dropoff}
594
- Tổng tiền lượt đi {price} VND
595
- """
596
  ]
597
 
598
  payload={
 
4
  from datetime import datetime, timedelta
5
  from fastapi.templating import Jinja2Templates
6
  from app.dialogflow.services.dialog_service import dialog_service
7
+ from utils.format_data_dialog import format_time, get_weekday_name
8
 
9
  from common.external.external_api import api
10
  from app.dialogflow.services.origin_codes import origin_codes
 
13
 
14
  templates = Jinja2Templates(directory="templates")
15
 
16
+
17
+ @router.get('/info/confirm')
18
+ async def confirm(request: Request):
19
+ body = await request.json()
20
+ session_info = body.get("sessionInfo", {})
21
+ parameters = session_info.get("parameters", {}) if isinstance(session_info.get("parameters"), dict) else {}
22
+ raw_date = parameters.get("date")
23
+ departure_city = parameters.get("departure_city")
24
+ destination_city = parameters.get("destination_city")
25
+ origin_office = parameters.get("origin_office")
26
+ dest_office = parameters.get("dest_office")
27
+ raw_ticket_number = parameters.get("ticket_number")
28
+ ticket_number = int(raw_ticket_number) if raw_ticket_number else 1
29
+
30
+ date, week_day = get_weekday_name(raw_date.strftime("%Y-%m-%d"))
31
+ text = [f"""
32
+ Ngày: {date} {week_day}
33
+ Số vé: {ticket_number}
34
+ """]
35
+ temp = ""
36
+ if origin_office and dest_office:
37
+ temp = f"""
38
+ Điểm đi: {origin_office}
39
+ Điểm đến: {dest_office}
40
+ """
41
+ elif origin_office and departure_city:
42
+ temp = f"""
43
+ Điểm đi: {origin_office}
44
+ Điểm đến: {departure_city
45
+ }
46
+ """
47
+ elif dest_office and departure_city:
48
+ temp = f"""
49
+ Điểm đi: {departure_city}
50
+ Điểm đến: {dest_office}
51
+ """
52
+ elif departure_city and destination_city:
53
+ temp = f"""
54
+ Điểm đi: {departure_city}
55
+ Điểm đến: {destination_city}
56
+ """
57
+ text[0] = temp + text[0]
58
+ payload = {
59
+ "richContent": [
60
+ [
61
+ {
62
+ "type": "chips",
63
+ "options": [
64
+ {"text": "Tìm chuyến xe"},
65
+ {"text": "Không, cảm ơn"}
66
+ ]
67
+ }
68
+ ]
69
+ ]
70
+ }
71
+ return DialogFlowResponseAPI(text=text, payload=payload)
72
  @router.post('/routes')
73
  async def route(request: Request):
74
  body = await request.json()
 
632
  price = int(price) if price else None
633
 
634
  text = [
635
+ f" \
636
+ **Thông tin hành khách**\
637
+ \n\
638
+ Họ và tên {user_name} \
639
+ Số điện thoại {phone_number} \
640
+ Email {email} \
641
+ \n\
642
+ **Thông tin lượt đi** \
643
+ \n\
644
+ Tuyến xe {route_name} \
645
+ Thời gian xuất bến {time} {date} \
646
+ Số ghế {seat} \
647
+ Điểm lên xe {pickup} \
648
+ Điểm trả khách {dropoff} \
649
+ Tổng tiền lượt đi {price} VND \
650
+ "
 
651
  ]
652
 
653
  payload={
utils/format_data_dialog.py CHANGED
@@ -1,4 +1,4 @@
1
-
2
 
3
 
4
  def format_time(time: dict) -> str:
@@ -15,4 +15,26 @@ def format_time(time: dict) -> str:
15
  else:
16
  hours = int(time["hours"])
17
  minutes = int(time["minutes"])
18
- return f"{hours:02d}:{minutes:02d}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datetime import datetime
2
 
3
 
4
  def format_time(time: dict) -> str:
 
15
  else:
16
  hours = int(time["hours"])
17
  minutes = int(time["minutes"])
18
+ return f"{hours:02d}:{minutes:02d}"
19
+
20
+ def get_weekday_name(date: str) -> tuple:
21
+ """
22
+ Get the name of the weekday from its number.
23
+ :param weekday: Weekday number (0-6).
24
+ :return: Name of the weekday.
25
+ """
26
+ vietnam_weekdays = {
27
+ 0: "Thứ hai",
28
+ 1: "Thứ ba",
29
+ 2: "Thứ tư",
30
+ 3: "Thứ năm",
31
+ 4: "Thứ sáu",
32
+ 5: "Thứ bảy",
33
+ 6: "Chủ nhật"
34
+ }
35
+ date = datetime.strptime(date, "%Y-%m-%d")
36
+
37
+ weekday_ids = date.weekday()
38
+ weekday = vietnam_weekdays.get(weekday_ids) if vietnam_weekdays.get(weekday_ids) else ""
39
+
40
+ return weekday, date.strftime("%d-%m-%Y")