All checks were successful
build-and-deploy / build-and-deploy (push) Successful in 1m4s
34 lines
1022 B
TypeScript
34 lines
1022 B
TypeScript
/**
|
|
* 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'
|
|
})
|
|
}
|
|
})
|