feat: save messages to new conversation storage
Integrate new conversation-storage.ts system while maintaining backward compatibility with existing message_buffer system: - Import saveConversationMessage from conversation-storage.ts - Save user messages to both new system (role: 'user') and old buffer - Save assistant responses to both new system (role: 'assistant') and old buffer - Preserve existing functionality during migration period Changes: - Add saveConversationMessage import - Call saveConversationMessage before addToBuffer for user messages - Call saveConversationMessage before addToBuffer for bot responses - Updated step numbering in comments (1-7) Note: Old buffer system will be removed after migration is complete. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
} from '../summary-service';
|
||||
import { sendChatAction } from '../telegram';
|
||||
import { createLogger } from '../utils/logger';
|
||||
import { saveConversationMessage } from './conversation-storage';
|
||||
|
||||
const logger = createLogger('conversation');
|
||||
|
||||
@@ -33,10 +34,16 @@ export class ConversationService {
|
||||
logger.error('타이핑 액션 전송 실패', err as Error)
|
||||
);
|
||||
|
||||
// 2. 사용자 메시지 버퍼에 추가
|
||||
// 2. 새 시스템에 사용자 메시지 저장
|
||||
await saveConversationMessage(this.env.DB, telegramUserId, {
|
||||
role: 'user',
|
||||
content: text,
|
||||
});
|
||||
|
||||
// 3. 기존 버퍼에도 저장 (호환성 - 나중에 제거)
|
||||
await addToBuffer(this.env.DB, userId, chatId, 'user', text);
|
||||
|
||||
// 3. AI 응답 생성
|
||||
// 4. AI 응답 생성
|
||||
let responseText = await generateAIResponse(
|
||||
this.env,
|
||||
userId,
|
||||
@@ -51,12 +58,19 @@ export class ConversationService {
|
||||
responseText = responseText.slice(directIndex + '__DIRECT__'.length).trim();
|
||||
}
|
||||
|
||||
// 4. 봇 응답 버퍼에 추가 (키보드 데이터 마커 등은 그대로 저장)
|
||||
// 5. 새 시스템에 봇 응답 저장
|
||||
await saveConversationMessage(this.env.DB, telegramUserId, {
|
||||
role: 'assistant',
|
||||
content: responseText,
|
||||
});
|
||||
|
||||
// 6. 기존 버퍼에도 저장 (호환성 - 나중에 제거)
|
||||
// 봇 응답 버퍼에 추가 (키보드 데이터 마커 등은 그대로 저장)
|
||||
// 실제 사용자에게 보여질 텍스트만 저장하는 것이 좋으나,
|
||||
// 현재 구조상 전체를 저장하고 나중에 컨텍스트로 활용 시 정제될 수 있음
|
||||
await addToBuffer(this.env.DB, userId, chatId, 'bot', responseText);
|
||||
|
||||
// 5. 임계값 도달 시 프로필 업데이트 (요약)
|
||||
// 7. 임계값 도달 시 프로필 업데이트 (요약)
|
||||
const { summarized } = await processAndSummarize(
|
||||
this.env,
|
||||
userId,
|
||||
|
||||
Reference in New Issue
Block a user