Some checks failed
Build and Deploy / build-and-deploy (push) Failing after 6m46s
Reemplazo completo de Evolution API por implementación directa con Baileys. Características: - Dashboard completo con Nuxt UI v4 - Soporte para múltiples instancias de WhatsApp - Conexión via QR code o pairing code - Persistencia de mensajes en PostgreSQL - API REST para integraciones externas - Webhooks con firma HMAC - SSE para actualizaciones en tiempo real - Autenticación con Authentik
48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
/**
|
|
* GET /api/messages/:instanceId/chats
|
|
* Get all chats for an instance
|
|
*/
|
|
import { query } from '../../../utils/database'
|
|
|
|
interface ChatRow {
|
|
id: string
|
|
jid: string
|
|
name: string | null
|
|
is_group: boolean
|
|
unread_count: number
|
|
last_message_at: Date | null
|
|
}
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const username = getHeader(event, 'x-authentik-username')
|
|
if (!username) {
|
|
throw createError({ statusCode: 401, message: 'Unauthorized' })
|
|
}
|
|
|
|
const instanceId = getRouterParam(event, 'instanceId')
|
|
|
|
// Verify instance exists
|
|
const instanceCheck = await query('SELECT id FROM instances WHERE id = $1', [instanceId])
|
|
if (instanceCheck.rows.length === 0) {
|
|
throw createError({ statusCode: 404, message: 'Instance not found' })
|
|
}
|
|
|
|
// Get chats with last message
|
|
const result = await query<ChatRow>(
|
|
`SELECT c.id, c.jid, c.name, c.is_group, c.unread_count, c.last_message_at
|
|
FROM chats c
|
|
WHERE c.instance_id = $1
|
|
ORDER BY c.last_message_at DESC NULLS LAST`,
|
|
[instanceId]
|
|
)
|
|
|
|
return result.rows.map(row => ({
|
|
id: row.id,
|
|
jid: row.jid,
|
|
name: row.name || row.jid.split('@')[0],
|
|
isGroup: row.is_group,
|
|
unreadCount: row.unread_count,
|
|
lastMessageAt: row.last_message_at
|
|
}))
|
|
})
|