27 lines
817 B
TypeScript
27 lines
817 B
TypeScript
// app/api/ai/extract/route.ts
|
|
import { NextRequest, NextResponse } from 'next/server';
|
|
import { extractLeadInsightsFromNotes } from '@/lib/ai';
|
|
|
|
export async function POST(req: NextRequest) {
|
|
try {
|
|
const body = await req.json();
|
|
const { text, leadName, ownerName } = body;
|
|
|
|
if (!text || typeof text !== 'string') {
|
|
return NextResponse.json({ success: false, error: 'متن یادداشت الزامی است.' }, { status: 400 });
|
|
}
|
|
|
|
const insights = await extractLeadInsightsFromNotes(text, {
|
|
name: leadName,
|
|
ownerName,
|
|
});
|
|
|
|
return NextResponse.json({
|
|
success: true,
|
|
insights,
|
|
});
|
|
} catch (error: any) {
|
|
console.error('AI Extraction Error:', error);
|
|
return NextResponse.json({ success: false, error: error.message }, { status: 500 });
|
|
}
|
|
}
|