Fix: Envío de eventos usando proto directo (bypass sendMessage)
All checks were successful
build-and-deploy / build-and-deploy (push) Successful in 1m12s

Baileys no maneja 'event' en generateWAMessageContent, causando
"Invalid media type" error. Se usa generateWAMessageFromContent
con proto.Message.IEventMessage y relayMessage directamente.
This commit is contained in:
2025-12-04 12:28:17 -06:00
parent b0101c791a
commit a9e786a8bd

View File

@@ -6,6 +6,7 @@
* - Stickers: image converted to WebP (FormData with asSticker flag) * - Stickers: image converted to WebP (FormData with asSticker flag)
*/ */
import type { AnyMediaMessageContent } from '@whiskeysockets/baileys' import type { AnyMediaMessageContent } from '@whiskeysockets/baileys'
import { generateWAMessageFromContent, proto } from '@whiskeysockets/baileys'
import { query } from '../../../../utils/database' import { query } from '../../../../utils/database'
import { baileysManager } from '../../../../services/baileys/manager' import { baileysManager } from '../../../../services/baileys/manager'
import { convertToSticker, canConvertToSticker } from '../../../../services/media/sticker-processor' import { convertToSticker, canConvertToSticker } from '../../../../services/media/sticker-processor'
@@ -358,6 +359,8 @@ async function handlePollMessage(
/** /**
* Handle event message sending * Handle event message sending
* Note: Baileys' sendMessage doesn't handle 'event' type directly,
* so we build the proto message manually and use relayMessage
*/ */
async function handleEventMessage( async function handleEventMessage(
body: EventMessageBody, body: EventMessageBody,
@@ -375,33 +378,48 @@ async function handleEventMessage(
throw createError({ statusCode: 400, message: 'Event start date is required' }) throw createError({ statusCode: 400, message: 'Event start date is required' })
} }
const eventContent: any = { // Build the eventMessage proto directly
const eventMessage: proto.Message.IEventMessage = {
name: body.name, name: body.name,
startDate: new Date(body.startDate) startTime: Math.floor(new Date(body.startDate).getTime() / 1000),
description: body.description || undefined,
extraGuestsAllowed: true
} }
if (body.endDate) { if (body.endDate) {
eventContent.endDate = new Date(body.endDate) eventMessage.endTime = Math.floor(new Date(body.endDate).getTime() / 1000)
} }
if (body.description) { if (body.location && body.location.latitude && body.location.longitude) {
eventContent.description = body.description eventMessage.location = {
}
if (body.location) {
if (body.location.latitude && body.location.longitude) {
eventContent.location = {
degreesLatitude: body.location.latitude, degreesLatitude: body.location.latitude,
degreesLongitude: body.location.longitude, degreesLongitude: body.location.longitude,
name: body.location.name, name: body.location.name || undefined,
address: body.location.address address: body.location.address || undefined
}
} }
} }
const content = { event: eventContent } // Create the message content with eventMessage
const messageContent: proto.IMessage = {
eventMessage
}
const result = await socket.sendMessage(jid, content, options) // Generate the full WAMessage using generateWAMessageFromContent
const userJid = socket.user?.id
const generatedMessage = generateWAMessageFromContent(
jid,
messageContent,
{
userJid,
quoted: options.quoted,
timestamp: new Date()
}
)
// Use relayMessage to send the pre-built message
await socket.relayMessage(jid, generatedMessage.message!, {
messageId: generatedMessage.key.id
})
// Save to database // Save to database
await query( await query(
@@ -413,7 +431,7 @@ async function handleEventMessage(
[ [
instanceId, instanceId,
chatId, chatId,
result.key.id, generatedMessage.key.id,
'me', 'me',
true, true,
'event', 'event',
@@ -425,7 +443,7 @@ async function handleEventMessage(
location: body.location location: body.location
}), }),
'sent', 'sent',
JSON.stringify(result), JSON.stringify(generatedMessage),
body.quotedMessageId || null body.quotedMessageId || null
] ]
) )
@@ -437,7 +455,7 @@ async function handleEventMessage(
return { return {
success: true, success: true,
messages: [{ messageId: result.key.id, type: 'event' }] messages: [{ messageId: generatedMessage.key.id, type: 'event' }]
} }
} }