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:
53
server/api/messages/[instanceId]/[chatId]/send.post.ts
Normal file
53
server/api/messages/[instanceId]/[chatId]/send.post.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* POST /api/messages/:instanceId/:chatId/send
|
||||
* Send a message to a chat (from UI)
|
||||
*/
|
||||
import { query } from '../../../../utils/database'
|
||||
import { baileysManager } from '../../../../services/baileys/manager'
|
||||
|
||||
interface SendMessageBody {
|
||||
message: string
|
||||
}
|
||||
|
||||
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')
|
||||
const chatId = getRouterParam(event, 'chatId')
|
||||
const body = await readBody<SendMessageBody>(event)
|
||||
|
||||
if (!body.message?.trim()) {
|
||||
throw createError({ statusCode: 400, message: 'Message is required' })
|
||||
}
|
||||
|
||||
// Get chat JID
|
||||
const chatResult = await query<{ jid: string }>(
|
||||
'SELECT jid FROM chats WHERE id = $1 AND instance_id = $2',
|
||||
[chatId, instanceId]
|
||||
)
|
||||
|
||||
if (chatResult.rows.length === 0) {
|
||||
throw createError({ statusCode: 404, message: 'Chat not found' })
|
||||
}
|
||||
|
||||
const jid = chatResult.rows[0].jid
|
||||
|
||||
try {
|
||||
const result = await baileysManager.sendMessage(instanceId!, jid, {
|
||||
text: body.message
|
||||
})
|
||||
|
||||
return {
|
||||
success: true,
|
||||
messageId: result.key.id
|
||||
}
|
||||
} catch (error) {
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
message: `Failed to send message: ${(error as Error).message}`
|
||||
})
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user