mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-18 19:32:21 -06:00
feat: adiciona painel interativo com chat e IA para análise de mensagens
- 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
This commit is contained in:
62
dashboard/app/api/messages/route.ts
Normal file
62
dashboard/app/api/messages/route.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
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 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user