Fix: Agregar soporte para recepción de Polls y Events
All checks were successful
build-and-deploy / build-and-deploy (push) Successful in 1m8s

- manager.ts: Detectar pollCreationMessage y eventMessage en getMessageType
- manager.ts: Extraer y guardar datos de poll/event como JSON en content
- index.get.ts: Parsear poll/event desde raw_message y content
- index.get.ts: Incluir poll y event en respuesta de la API
This commit is contained in:
2025-12-04 12:14:45 -06:00
parent cb846d0c56
commit b0101c791a
2 changed files with 93 additions and 9 deletions

View File

@@ -116,6 +116,38 @@ function parseRawMessage(raw: any, messageType: string) {
}
}
// Poll message
if (messageType === 'poll') {
const pollMsg = msg.pollCreationMessage || msg.pollCreationMessageV3
if (pollMsg) {
result.poll = {
name: pollMsg.name,
options: pollMsg.options?.map((o: any) => o.optionName) || [],
selectableCount: pollMsg.selectableOptionsCount || 1
}
}
}
// Event message
if (messageType === 'event' && msg.eventMessage) {
result.event = {
name: msg.eventMessage.name,
startDate: msg.eventMessage.startTime
? new Date(msg.eventMessage.startTime * 1000).toISOString()
: null,
endDate: msg.eventMessage.endTime
? new Date(msg.eventMessage.endTime * 1000).toISOString()
: null,
description: msg.eventMessage.description,
location: msg.eventMessage.location ? {
name: msg.eventMessage.location.name,
address: msg.eventMessage.location.address,
latitude: msg.eventMessage.location.degreesLatitude,
longitude: msg.eventMessage.location.degreesLongitude
} : undefined
}
}
// Extract quoted message if exists
const contextInfo = getContextInfo(msg)
if (contextInfo?.quotedMessage) {
@@ -183,8 +215,10 @@ function getMessageType(msg: any): string {
if (msg.audioMessage) return 'audio'
if (msg.documentMessage) return 'document'
if (msg.stickerMessage) return 'sticker'
if (msg.contactMessage) return 'contact'
if (msg.contactMessage || msg.contactsArrayMessage) return 'contact'
if (msg.locationMessage) return 'location'
if (msg.pollCreationMessage || msg.pollCreationMessageV3) return 'poll'
if (msg.eventMessage) return 'event'
return 'unknown'
}
@@ -268,6 +302,20 @@ export default defineEventHandler(async (event) => {
return result.rows.map(row => {
const parsedData = parseRawMessage(row.raw_message, row.message_type)
// For poll/event, try to parse content as JSON if it's stored that way
let poll = parsedData.poll
let event = parsedData.event
if (row.message_type === 'poll' && row.content && !poll) {
try {
poll = JSON.parse(row.content)
} catch {}
}
if (row.message_type === 'event' && row.content && !event) {
try {
event = JSON.parse(row.content)
} catch {}
}
return {
id: row.id,
messageId: row.message_id,
@@ -280,6 +328,8 @@ export default defineEventHandler(async (event) => {
media: parsedData.media || (row.media_url ? { url: row.media_url } : undefined),
location: parsedData.location,
contact: parsedData.contact,
poll: poll,
event: event,
quoted: parsedData.quoted,
timestamp: row.timestamp,
status: row.status || 'sent',