diff --git a/backend/src/support-chat/support-chat.service.ts b/backend/src/support-chat/support-chat.service.ts index c3ce7693..f89ee9e9 100644 --- a/backend/src/support-chat/support-chat.service.ts +++ b/backend/src/support-chat/support-chat.service.ts @@ -64,7 +64,7 @@ export class SupportChatService { let intent: 'public' | 'orders' | 'wallet'; try { if (!url || !key || !url.endsWith('/ask')) throw new Error('disabled'); - const response = await fetch(url.replace(/\/ask$/, '/classify'), { method: 'POST', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${key}` }, signal: AbortSignal.timeout(45000), body: JSON.stringify({ message: input.message, conversation_history: conversationHistory, page_context: pageContext, selection }) }); + const response = await fetch(url.replace(/\/ask$/, '/classify'), { method: 'POST', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${key}` }, signal: AbortSignal.timeout(45000), body: JSON.stringify({ message: input.message, conversation_history: conversationHistory, selection }) }); if (response.status === 400) return { answer: 'فقط درباره محصولات و سلامت حیوانات خانگی و خدمات کنینا پاسخ می‌دهم.' }; if (!response.ok) throw new Error('upstream'); const data = await response.json(); if (!data || Object.keys(data).length !== 1 || !['public','orders','wallet'].includes(data.intent)) throw new Error('intent'); intent = data.intent;