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:
@@ -12,6 +12,7 @@ interface ChatRow {
|
||||
unread_count: number
|
||||
last_message_at: Date | null
|
||||
last_message: string | null
|
||||
last_message_type: string | null
|
||||
}
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
|
||||
62
server/api/messages/[instanceId]/react.post.ts
Normal file
62
server/api/messages/[instanceId]/react.post.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* POST /api/messages/:instanceId/react
|
||||
* Send a reaction to a message
|
||||
*/
|
||||
import { baileysManager } from '../../../services/baileys/manager'
|
||||
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')
|
||||
if (!instanceId) {
|
||||
throw createError({ statusCode: 400, message: 'Missing instanceId' })
|
||||
}
|
||||
|
||||
const body = await readBody<{ messageId: string; emoji: string }>(event)
|
||||
if (!body?.messageId) {
|
||||
throw createError({ statusCode: 400, message: 'Missing messageId in request body' })
|
||||
}
|
||||
|
||||
// emoji can be empty string to remove reaction
|
||||
if (body.emoji === undefined) {
|
||||
throw createError({ statusCode: 400, message: 'Missing emoji in request body' })
|
||||
}
|
||||
|
||||
try {
|
||||
// Get the message to find its JID
|
||||
const msgResult = await query<{ raw_message: any }>(
|
||||
`SELECT raw_message FROM messages WHERE instance_id = $1 AND message_id = $2`,
|
||||
[instanceId, body.messageId]
|
||||
)
|
||||
|
||||
if (msgResult.rows.length === 0) {
|
||||
throw createError({ statusCode: 404, message: 'Message not found' })
|
||||
}
|
||||
|
||||
const rawMessage = msgResult.rows[0].raw_message
|
||||
const jid = rawMessage?.key?.remoteJid
|
||||
|
||||
if (!jid) {
|
||||
throw createError({ statusCode: 400, message: 'Could not determine message JID' })
|
||||
}
|
||||
|
||||
await baileysManager.sendReaction(instanceId, jid, body.messageId, body.emoji)
|
||||
|
||||
return { success: true, messageId: body.messageId, emoji: body.emoji }
|
||||
} catch (error: any) {
|
||||
console.error('[React API] Error sending reaction:', error)
|
||||
|
||||
if (error.statusCode) {
|
||||
throw error
|
||||
}
|
||||
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
message: error.message || 'Error sending reaction'
|
||||
})
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user