버그 수정중 .
This commit is contained in:
1 parent
088c57f415
commit
cb3adf6d2e
5 files changed
+41
-11
No files matched your search
@@ -6,6 +6,7 @@ Chat_server 의 step 체계(서비스안내→담당자확인→협상품목안
|
||||
DB/정책(카드선택·학습)은 여기 두지 않는다 — ChatService(async)가 StepView 의 신호를 보고 처리한다.
|
||||
"""
|
||||
|
||||
import re
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
@@ -15,6 +16,22 @@ MAX_ROUNDS = 3
|
||||
_PRICE_MODES = ("price",)
|
||||
_CHOICE_MODES = ("yes_no", "confirm", "delivery_type")
|
||||
|
||||
# 프론트는 표시용 문자열로 가격을 보낸다(예: "530,000원"). 천단위 콤마·통화기호("원")·공백 등
|
||||
# 숫자 외 문자를 제거하고 파싱한다. (콤마만 지우면 "원" 때문에 float() 가 실패해 가격 입력이
|
||||
# 영영 저장되지 않고 같은 step 에 머무는 버그가 났었다.)
|
||||
_PRICE_CLEAN_RE = re.compile(r"[^\d.]")
|
||||
|
||||
|
||||
def _parse_price(user_input: Any) -> Optional[float]:
|
||||
cleaned = _PRICE_CLEAN_RE.sub("", str(user_input if user_input is not None else ""))
|
||||
if not cleaned or cleaned == ".":
|
||||
return None
|
||||
try:
|
||||
price = float(cleaned)
|
||||
except ValueError:
|
||||
return None
|
||||
return price if price > 0 else None
|
||||
|
||||
|
||||
@dataclass
|
||||
class ChatSession:
|
||||
@@ -62,9 +79,8 @@ class ChatEngine:
|
||||
mode = node.get("next_input_mode", "null")
|
||||
|
||||
if mode in _PRICE_MODES:
|
||||
try:
|
||||
price = float(str(user_input).replace(",", ""))
|
||||
except (TypeError, ValueError):
|
||||
price = _parse_price(user_input)
|
||||
if price is None:
|
||||
return self._error(session, "가격을 숫자로 입력해 주세요.")
|
||||
session.context["input_price"] = price
|
||||
session.context["round"] = session.context.get("round", 0) + 1
|
||||
|
||||
Reference in new issue
Block a user