Files
whatsappNucleo/server/api/instances/index.post.ts
josedario87 faedec47d7
Some checks failed
Build and Deploy / build-and-deploy (push) Failing after 6m46s
feat: WhatsApp Nucleo con Nuxt 4 + Baileys v7
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
2025-12-02 17:54:31 -06:00

49 lines
1.0 KiB
TypeScript

/**
* POST /api/instances
* Create a new instance
*/
import { query } from '../../utils/database'
interface CreateInstanceBody {
name: string
}
interface InstanceRow {
id: string
name: string
phone_number: string | null
status: string
created_at: Date
}
export default defineEventHandler(async (event) => {
// Check auth
const username = getHeader(event, 'x-authentik-username')
if (!username) {
throw createError({ statusCode: 401, message: 'Unauthorized' })
}
const body = await readBody<CreateInstanceBody>(event)
if (!body.name?.trim()) {
throw createError({ statusCode: 400, message: 'Name is required' })
}
const result = await query<InstanceRow>(
`INSERT INTO instances (name, created_by)
VALUES ($1, $2)
RETURNING id, name, phone_number, status, created_at`,
[body.name.trim(), username]
)
const instance = result.rows[0]
return {
id: instance.id,
name: instance.name,
phoneNumber: instance.phone_number,
status: instance.status,
createdAt: instance.created_at
}
})