diff --git a/src/openai-service.ts b/src/openai-service.ts index 4d2f109..42cd858 100644 --- a/src/openai-service.ts +++ b/src/openai-service.ts @@ -6,10 +6,10 @@ import { createLogger } from './utils/logger'; import { metrics } from './utils/metrics'; import { getOpenAIUrl } from './utils/api-urls'; import { ERROR_MESSAGES } from './constants/messages'; -import { hasServerSession, processServerConsultation } from './agents/server-agent'; import { processTroubleshootConsultation, hasTroubleshootSession } from './agents/troubleshoot-agent'; import { processDomainConsultation, hasDomainSession } from './agents/domain-agent'; import { processDepositConsultation, hasDepositSession } from './agents/deposit-agent'; +import { processDdosConsultation, hasDdosSession } from './agents/ddos-agent'; import { sendMessage } from './telegram'; const logger = createLogger('openai'); @@ -207,48 +207,8 @@ export async function generateOpenAIResponse( db?: D1Database, chatIdStr?: string ): Promise { - // Check if server consultation session is active + // Check if troubleshoot session is active if (telegramUserId && env.DB) { - try { - const hasSession = await hasServerSession(env.DB, telegramUserId); - - if (hasSession) { - logger.info('Active server session detected, routing to consultation', { - userId: telegramUserId - }); - - // Create callback for intermediate messages - let sendIntermediateMessage: ((message: string) => Promise) | undefined; - if (chatIdStr) { - sendIntermediateMessage = async (message: string) => { - logger.info('Sending intermediate message', { chatId: chatIdStr, messagePreview: message.substring(0, 50) }); - await sendMessage(env.BOT_TOKEN, parseInt(chatIdStr), message); - logger.info('Intermediate message sent successfully', { chatId: chatIdStr }); - }; - } - - const result = await processServerConsultation( - env.DB, - telegramUserId, - userMessage, - env, - { sendIntermediateMessage } - ); - - // PASSTHROUGH: 무관한 메시지는 일반 처리로 전환 - if (result !== '__PASSTHROUGH__') { - return result; - } - // Continue to normal flow below - } - } catch (error) { - logger.error('Session check failed, continuing with normal flow', error as Error, { - telegramUserId - }); - // Continue with normal flow if session check fails - } - - // Check if troubleshoot session is active try { const hasTroubleshootSess = await hasTroubleshootSession(env.DB, telegramUserId); @@ -314,6 +274,29 @@ export async function generateOpenAIResponse( }); // Continue with normal flow if session check fails } + + // Check for active DDoS defense session + try { + const hasDdosSess = await hasDdosSession(env.DB, telegramUserId); + + if (hasDdosSess) { + logger.info('DDoS 방어 세션 감지, DDoS 에이전트로 라우팅', { + userId: telegramUserId + }); + const ddosResponse = await processDdosConsultation(env.DB, telegramUserId, userMessage, env); + + // PASSTHROUGH: 무관한 메시지는 일반 처리로 전환 + if (ddosResponse !== '__PASSTHROUGH__') { + return ddosResponse; + } + // Continue to normal flow below + } + } catch (error) { + logger.error('DDoS session check failed, continuing with normal flow', error as Error, { + telegramUserId + }); + // Continue with normal flow if session check fails + } } if (!env.OPENAI_API_KEY) {