feat: WhatsApp Nucleo con Nuxt 4 + Baileys v7
Some checks failed
Build and Deploy / build-and-deploy (push) Failing after 6m46s
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
This commit is contained in:
48
server/api/instances/index.post.ts
Normal file
48
server/api/instances/index.post.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* 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
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user