mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-11 19:09:39 -06:00
- Dashboard completo com métricas em tempo real - Chat interativo com IA para consultas em linguagem natural - Análise de sentimento das mensagens - Gráficos interativos (mensagens por dia, sentimentos) - Filtros avançados por instância e data - Top contatos e timeline de mensagens - API routes para stats, mensagens, sentimento e chat - Integração com PostgreSQL via Prisma - Interface moderna com Next.js 14, TypeScript e Tailwind CSS - Documentação completa com README e QUICKSTART
63 lines
1.6 KiB
TypeScript
63 lines
1.6 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import prisma from '@/lib/prisma';
|
|
|
|
export async function GET(request: NextRequest) {
|
|
try {
|
|
const searchParams = request.nextUrl.searchParams;
|
|
const instanceId = searchParams.get('instanceId');
|
|
const limit = parseInt(searchParams.get('limit') || '100');
|
|
const offset = parseInt(searchParams.get('offset') || '0');
|
|
const startDate = searchParams.get('startDate');
|
|
const endDate = searchParams.get('endDate');
|
|
const fromMe = searchParams.get('fromMe');
|
|
|
|
// Construir where clause
|
|
const where: any = {};
|
|
if (instanceId) {
|
|
where.instanceId = instanceId;
|
|
}
|
|
if (startDate && endDate) {
|
|
const startTimestamp = new Date(startDate).getTime();
|
|
const endTimestamp = new Date(endDate).getTime();
|
|
where.messageTimestamp = {
|
|
gte: startTimestamp,
|
|
lte: endTimestamp,
|
|
};
|
|
}
|
|
if (fromMe !== null && fromMe !== undefined) {
|
|
where.fromMe = fromMe === 'true';
|
|
}
|
|
|
|
// Buscar mensagens
|
|
const [messages, total] = await Promise.all([
|
|
prisma.message.findMany({
|
|
where,
|
|
take: limit,
|
|
skip: offset,
|
|
orderBy: { messageTimestamp: 'desc' },
|
|
include: {
|
|
Instance: {
|
|
select: {
|
|
name: true,
|
|
},
|
|
},
|
|
},
|
|
}),
|
|
prisma.message.count({ where }),
|
|
]);
|
|
|
|
return NextResponse.json({
|
|
messages,
|
|
total,
|
|
limit,
|
|
offset,
|
|
});
|
|
} catch (error) {
|
|
console.error('Erro ao buscar mensagens:', error);
|
|
return NextResponse.json(
|
|
{ error: 'Erro ao buscar mensagens' },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|