- /api/messages 삭제, /api/history 추가 - Frontend 수정 불필요 (이미 구현됨) - main.py만 수정하면 완료
3.5 KiB
3.5 KiB
rb8001 카톡 스타일 대화 히스토리 구현 계획
작성일: 2025-09-01
대상: rb8001 (프로덕션 로빙)
참조: rb10508_micro 구현 코드
수정: PostgreSQL 전용 히스토리 구현으로 변경
현재 상태 분석
- rb10508_micro: /api/config 엔드포인트 구현됨 (endpoints.py:407)
- rb8001:
- database.py: ConversationLog 모델 있음 (line 52)
- get_recent_conversations() 함수 있음 (line 81)
- get_paginated_conversations() 함수 없음 (추가 필요)
- main.py: @app.get() 직접 사용, router 분리 없음
UUID 및 인증 체계
- 내부 처리: 모든 user_id는 UUID 형식으로 통일
- JWT 토큰: X-User-Id 헤더로 UUID 전달
- Slack 사용자: slack_user_mapping 테이블로 UUID 매핑
- Frontend: JWT에서 user_id(UUID) 추출하여 API 호출
수정 필요 파일
백엔드 (rb8001)
- ✅
app/core/config.py- 환경변수 추가 완료 - ✅
app/state/database.py- get_paginated_conversations() 추가 완료 main.py- 엔드포인트 수정 필요- ✅
/api/config이미 추가됨 - ❌
/api/messages삭제 필요 (잘못 추가함) - ⚠️
/api/history추가 필요 (이것만!)
- ✅
- ✅
.env파일 - 환경변수 설정 완료
프론트엔드 (frontend-customer)
- ✅ 이미 완료됨 (250818 rb10508_micro에서 구현)
- ✅
/api/history호출 중 (수정 불필요)
API 스펙
// GET /api/config
{ message_batch_size: 30, max_messages_in_dom: 200 }
// GET /api/history?before={timestamp}&limit=30
{
messages: [...], // PostgreSQL conversation_logs에서 조회
has_more: true
}
PostgreSQL 쿼리 예시
-- user_id는 항상 UUID 형식
SELECT id, message, response, timestamp, user_id
FROM conversation_logs
WHERE user_id = $1::uuid -- UUID 타입 캐스팅
AND robeing_id = 'rb8001'
AND timestamp < $2
ORDER BY timestamp DESC
LIMIT 30;
API 호출 예시
// Frontend에서 JWT의 user_id 사용
const token = localStorage.getItem('token');
const decoded = jwt_decode(token);
const userId = decoded.user_id; // UUID 형식
// API 호출 (Frontend가 이미 호출 중)
await fetch(`/api/history?before=${timestamp}&limit=30`);
데이터베이스 스키마
-- conversation_logs 테이블 (실제)
CREATE TABLE conversation_logs (
id INTEGER PRIMARY KEY (auto-increment),
robeing_id VARCHAR,
channel_id VARCHAR,
message VARCHAR,
response VARCHAR,
intent VARCHAR,
confidence DOUBLE PRECISION,
timestamp TIMESTAMP,
user_id UUID (FK → users),
slack_user_id VARCHAR(100),
thread_ts VARCHAR(128),
channel_type VARCHAR(32)
);
주의사항
API 경로
# main.py에 직접 추가 (rb8001은 router 분리 없음)
@app.get("/api/config")
@app.get("/api/messages")
rb10508_micro 참조 코드
# rb10508_micro/app/config.py:101-103
MESSAGE_BATCH_SIZE: int = int(os.getenv("MESSAGE_BATCH_SIZE", 30))
SCROLL_THRESHOLD: int = int(os.getenv("SCROLL_THRESHOLD", 100))
MAX_MESSAGES_IN_DOM: int = int(os.getenv("MAX_MESSAGES_IN_DOM", 200))
실제 필요 작업 (간단!)
- ✅ 백엔드 대부분 완료 (bbf9c50 커밋)
- ⚠️ rb8001 main.py 수정만 필요:
/api/messages엔드포인트 삭제/api/history엔드포인트 추가 (get_paginated_conversations 사용)
- ✅ Frontend 수정 불필요 (이미 /api/history 호출 중)
- ✅ 배포는 Gitea Actions 자동 처리