1. 패턴 클래스
public class RegexPattern {
public static final Pattern EMAIL_PATTERN = Pattern.compile(
"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-z]{2,}", Pattern.CASE_INSENSITIVE );
// 최신 전화 번호 패턴 적용
public static final Pattern PHONE_PATTERN = Pattern.compile(
"^(010|02|0[3-9][1-9]|050[2-9]|070|080)[- ]?\\d{3,4}[- ]?\\d{4}$"
);
}
2. 정보 추출 메소드
public static CustomerInfo extractUserInformationFromChatHistory(List<ChatEntry> history) {
if (history == null || history.isEmpty()) {
return new CustomerInfo(null, null);
}
Optional<String> emailAddress = history.stream()
.filter(entry -> "user".equalsIgnoreCase(entry.getRole()))
.map(ChatEntry::getContent)
.filter(content -> content != null && !content.isBlank())
.map(CustomerInfoHelper::extractEmailAddress)
.filter(Optional::isPresent)
.map(Optional::get)
.findFirst();
Optional<String> phoneNumber = history.stream()
.filter(entry -> "user".equalsIgnoreCase(entry.getRole()))
.map(ChatEntry::getContent)
.filter(content -> content != null && !content.isBlank())
.map(CustomerInfoHelper::extractPhoneNumber)
.filter(Optional::isPresent)
.map(Optional::get)
.findFirst();
return new CustomerInfo(emailAddress.orElse(null), phoneNumber.orElse(null));
}