/** * POST /api/debug/groups/participants * Update group participants (add, remove, promote, demote) */ import { baileysManager } from '../../../services/baileys/manager' type ParticipantAction = 'add' | 'remove' | 'promote' | 'demote' export default defineEventHandler(async (event) => { const username = getHeader(event, 'x-authentik-username') if (!username) { throw createError({ statusCode: 401, message: 'Unauthorized' }) } const body = await readBody(event) const { instanceId, jid, participants, action } = body as { instanceId: string jid: string participants: string[] action: ParticipantAction } if (!instanceId) { throw createError({ statusCode: 400, message: 'instanceId is required' }) } if (!jid) { throw createError({ statusCode: 400, message: 'jid is required' }) } if (!participants || !Array.isArray(participants) || participants.length === 0) { throw createError({ statusCode: 400, message: 'participants array is required' }) } const validActions: ParticipantAction[] = ['add', 'remove', 'promote', 'demote'] if (!action || !validActions.includes(action)) { throw createError({ statusCode: 400, message: `action must be one of: ${validActions.join(', ')}` }) } const socket = baileysManager.getSocket(instanceId) if (!socket) { throw createError({ statusCode: 400, message: 'Instance not connected' }) } try { const result = await socket.groupParticipantsUpdate(jid, participants, action) return { success: true, data: result } } catch (error) { throw createError({ statusCode: 500, message: `Failed to update participants: ${(error as Error).message}` }) } })