- Build complete Next.js CRM for commercial real estate - Add authentication with JWT sessions and role-based access - Add GoHighLevel API integration for contacts, conversations, opportunities - Add AI-powered Control Center with tool calling - Add Setup page with onboarding checklist (/setup) - Add sidebar navigation with Setup menu item - Fix type errors in onboarding API, GHL services, and control center tools - Add Prisma schema with SQLite for local development - Add UI components with clay morphism design system Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import { getSession } from '@/lib/auth';
|
|
import { getGHLClientForUser } from '@/lib/ghl/helpers';
|
|
|
|
export async function GET(request: NextRequest) {
|
|
const session = await getSession();
|
|
if (!session) {
|
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
|
}
|
|
|
|
const ghl = await getGHLClientForUser(session.user.id);
|
|
if (!ghl) {
|
|
return NextResponse.json({ error: 'GHL not configured' }, { status: 400 });
|
|
}
|
|
|
|
const { searchParams } = new URL(request.url);
|
|
const limit = parseInt(searchParams.get('limit') || '20');
|
|
const status = searchParams.get('status') as 'all' | 'read' | 'unread' | 'starred' || 'all';
|
|
const contactId = searchParams.get('contactId') || undefined;
|
|
|
|
try {
|
|
const conversations = await ghl.conversations.getAll({
|
|
limit,
|
|
status,
|
|
contactId,
|
|
});
|
|
return NextResponse.json(conversations);
|
|
} catch (error) {
|
|
console.error('Failed to get conversations:', error);
|
|
return NextResponse.json({ error: 'Failed to fetch conversations' }, { status: 500 });
|
|
}
|
|
}
|