Fix: Usar URL interna para debug webhook receiver (bypass authentik)
All checks were successful
build-and-deploy / build-and-deploy (push) Successful in 1m4s
All checks were successful
build-and-deploy / build-and-deploy (push) Successful in 1m4s
This commit is contained in:
44
server/api/presence/[instanceId]/send.post.ts
Normal file
44
server/api/presence/[instanceId]/send.post.ts
Normal 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'
|
||||
})
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user