diff --git a/src/openai-service.ts b/src/openai-service.ts index 99bd617..1559ffa 100644 --- a/src/openai-service.ts +++ b/src/openai-service.ts @@ -8,6 +8,7 @@ import { getOpenAIUrl } from './utils/api-urls'; import { ERROR_MESSAGES } from './constants/messages'; import { getServerSession, processServerConsultation } from './agents/server-agent'; import { getTroubleshootSession, processTroubleshoot } from './agents/troubleshoot-agent'; +import { processDomainConsultation, hasDomainSession } from './agents/domain-agent'; import { sendMessage } from './telegram'; const logger = createLogger('openai'); @@ -263,6 +264,29 @@ export async function generateOpenAIResponse( logger.error('Troubleshoot session check failed, continuing with normal flow', error as Error); // Continue with normal flow if session check fails } + + // Check if domain consultation session is active + try { + const hasDomainSess = await hasDomainSession(env.DB, telegramUserId); + + if (hasDomainSess) { + logger.info('도메인 세션 감지, 도메인 에이전트로 라우팅', { + userId: telegramUserId + }); + const domainResponse = await processDomainConsultation(env.DB, telegramUserId, userMessage, env); + + // PASSTHROUGH: 무관한 메시지는 일반 처리로 전환 + if (domainResponse !== '__PASSTHROUGH__') { + return domainResponse; + } + // Continue to normal flow below + } + } catch (error) { + logger.error('Domain session check failed, continuing with normal flow', error as Error, { + telegramUserId + }); + // Continue with normal flow if session check fails + } } if (!env.OPENAI_API_KEY) {