Spaces:
Sleeping
Sleeping
File size: 2,219 Bytes
7c26280 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
"""Validation utilities for the barber booking system."""
import re
from typing import Tuple, Dict, Optional
def validate_email(email: str) -> bool:
"""Validate email format."""
pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
return bool(re.match(pattern, email))
def validate_phone(phone: str) -> bool:
"""Validate phone number format."""
pattern = r'^\+?[1-9]\d{1,14}$'
return bool(re.match(pattern, phone))
def validate_name(name: str) -> bool:
"""Validate customer name."""
words = name.strip().split()
return len(words) >= 1 and all(len(word) >= 2 for word in words)
def format_phone(phone: str) -> str:
"""Format phone number to international format."""
if not phone.startswith('+'):
return f"+{phone.lstrip('0')}"
return phone
def validate_booking_info(current_node: str, booking_info: Dict) -> Tuple[bool, str]:
"""Validate required booking information for the current node."""
if current_node == "ShowTopSlots" and not booking_info.get("name"):
return False, "I need your name first. What's your name?"
elif current_node == "CollectEmail" and not booking_info.get("service"):
return False, "Please select a service first."
elif current_node == "CollectPhone" and not booking_info.get("email"):
return False, "I need your email for the confirmation. What's your email address?"
elif current_node == "Confirmation" and not booking_info.get("phone"):
return False, "What's your phone number for appointment reminders?"
return True, ""
def get_closest_service(query: str) -> Optional[str]:
"""Find the closest matching service based on the user's input."""
query = query.lower().strip()
# Direct matches
if query in ["haircut", "beard trim", "full service"]:
return query
# Handle variations and partial matches
if any(word in query for word in ["hair", "cut", "haircut"]):
return "haircut"
elif any(word in query for word in ["beard", "trim", "beardtrim"]):
return "beard trim"
elif any(word in query for word in ["full", "complete", "both", "all"]):
return "full service"
return None
|