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
54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
/**
|
|
* GET /api/instances/:id
|
|
* Get instance details
|
|
*/
|
|
import { query } from '../../../utils/database'
|
|
import { baileysManager } from '../../../services/baileys/manager'
|
|
|
|
interface InstanceRow {
|
|
id: string
|
|
name: string
|
|
phone_number: string | null
|
|
status: string
|
|
qr_code: string | null
|
|
pairing_code: string | null
|
|
last_connected_at: Date | null
|
|
created_by: string
|
|
created_at: Date
|
|
}
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const username = getHeader(event, 'x-authentik-username')
|
|
if (!username) {
|
|
throw createError({ statusCode: 401, message: 'Unauthorized' })
|
|
}
|
|
|
|
const id = getRouterParam(event, 'id')
|
|
|
|
const result = await query<InstanceRow>(
|
|
`SELECT id, name, phone_number, status, qr_code, pairing_code,
|
|
last_connected_at, created_by, created_at
|
|
FROM instances WHERE id = $1`,
|
|
[id]
|
|
)
|
|
|
|
if (result.rows.length === 0) {
|
|
throw createError({ statusCode: 404, message: 'Instance not found' })
|
|
}
|
|
|
|
const instance = result.rows[0]
|
|
const liveStatus = baileysManager.getStatus(instance.id)
|
|
|
|
return {
|
|
id: instance.id,
|
|
name: instance.name,
|
|
phoneNumber: instance.phone_number,
|
|
status: liveStatus?.status || instance.status,
|
|
qrCode: liveStatus?.qrCode || instance.qr_code,
|
|
pairingCode: liveStatus?.pairingCode || instance.pairing_code,
|
|
lastConnectedAt: instance.last_connected_at,
|
|
createdBy: instance.created_by,
|
|
createdAt: instance.created_at
|
|
}
|
|
})
|