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:
54
server/api/instances/[id]/connect.post.ts
Normal file
54
server/api/instances/[id]/connect.post.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* POST /api/instances/:id/connect
|
||||
* Connect an instance (generates QR code)
|
||||
*/
|
||||
import { query } from '../../../utils/database'
|
||||
import { baileysManager } from '../../../services/baileys/manager'
|
||||
|
||||
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')
|
||||
|
||||
// Check if instance exists
|
||||
const result = await query<{ id: string; status: string }>(
|
||||
'SELECT id, status FROM instances WHERE id = $1',
|
||||
[id]
|
||||
)
|
||||
|
||||
if (result.rows.length === 0) {
|
||||
throw createError({ statusCode: 404, message: 'Instance not found' })
|
||||
}
|
||||
|
||||
const instance = result.rows[0]
|
||||
|
||||
// Don't connect if already connected
|
||||
if (instance.status === 'connected') {
|
||||
throw createError({ statusCode: 400, message: 'Instance already connected' })
|
||||
}
|
||||
|
||||
// Start connection
|
||||
try {
|
||||
await baileysManager.connect(id!)
|
||||
|
||||
// Wait a bit for QR to generate
|
||||
await new Promise(resolve => setTimeout(resolve, 2000))
|
||||
|
||||
const qrCode = baileysManager.getQRCode(id!)
|
||||
const status = baileysManager.getStatus(id!)
|
||||
|
||||
return {
|
||||
success: true,
|
||||
status: status?.status || 'connecting',
|
||||
qrCode
|
||||
}
|
||||
} catch (error) {
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
message: `Failed to connect: ${(error as Error).message}`
|
||||
})
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user