Fix: Usar URL interna para debug webhook receiver (bypass authentik)
All checks were successful
build-and-deploy / build-and-deploy (push) Successful in 1m4s

This commit is contained in:
2025-12-02 21:27:45 -06:00
parent 80d0042c7e
commit 8f44826e64
14 changed files with 642 additions and 21 deletions

View File

@@ -0,0 +1,42 @@
/**
* GET /api/presence/:instanceId/:jid
* Get cached presence for a contact
*/
import { query } from '../../../utils/database'
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 jid = getRouterParam(event, 'jid')
if (!instanceId || !jid) {
throw createError({ statusCode: 400, message: 'Missing instanceId or jid' })
}
try {
const result = await query<{ presence: string; last_seen: Date }>(
`SELECT presence, last_seen FROM presence_cache
WHERE instance_id = $1 AND jid = $2`,
[instanceId, jid]
)
if (result.rows.length === 0) {
return { presence: null, lastSeen: null }
}
return {
presence: result.rows[0].presence,
lastSeen: result.rows[0].last_seen
}
} catch (error: any) {
console.error('[Presence API] Error getting presence:', error)
throw createError({
statusCode: 500,
message: 'Error getting presence'
})
}
})

View File

@@ -0,0 +1,44 @@
/**
* POST /api/presence/:instanceId/send
* Send presence update (composing, recording, available, unavailable, paused)
*/
import { baileysManager } from '../../../services/baileys/manager'
type PresenceType = 'composing' | 'recording' | 'available' | 'unavailable' | 'paused'
const VALID_PRESENCES: PresenceType[] = ['composing', 'recording', 'available', 'unavailable', 'paused']
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')
if (!instanceId) {
throw createError({ statusCode: 400, message: 'Missing instanceId' })
}
const body = await readBody<{ jid: string; presence: PresenceType }>(event)
if (!body?.jid) {
throw createError({ statusCode: 400, message: 'Missing jid in request body' })
}
if (!body?.presence || !VALID_PRESENCES.includes(body.presence)) {
throw createError({
statusCode: 400,
message: `Invalid presence. Must be one of: ${VALID_PRESENCES.join(', ')}`
})
}
try {
await baileysManager.sendPresence(instanceId, body.jid, body.presence)
return { success: true, jid: body.jid, presence: body.presence }
} catch (error: any) {
console.error('[Presence API] Error sending presence:', error)
throw createError({
statusCode: 500,
message: error.message || 'Error sending presence'
})
}
})

View File

@@ -0,0 +1,33 @@
/**
* POST /api/presence/:instanceId/subscribe
* Subscribe to presence updates for a contact
*/
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 instanceId = getRouterParam(event, 'instanceId')
if (!instanceId) {
throw createError({ statusCode: 400, message: 'Missing instanceId' })
}
const body = await readBody<{ jid: string }>(event)
if (!body?.jid) {
throw createError({ statusCode: 400, message: 'Missing jid in request body' })
}
try {
await baileysManager.subscribeToPresence(instanceId, body.jid)
return { success: true, jid: body.jid }
} catch (error: any) {
console.error('[Presence API] Error subscribing:', error)
throw createError({
statusCode: 500,
message: error.message || 'Error subscribing to presence'
})
}
})