Feat: Agregar soporte para envío de Contacts, Polls y Events
All checks were successful
build-and-deploy / build-and-deploy (push) Successful in 1m8s

- Backend: Nuevo soporte en endpoint /send para tipos contact, poll, event
- UI: Modales para crear y enviar contactos, encuestas y eventos
- Visualización: Componentes MessagePoll y MessageEvent para mostrar mensajes recibidos
- Tipos: Agregar PollInfo, EventInfo y tipo 'event' a MessageType
This commit is contained in:
2025-12-04 12:06:35 -06:00
parent 48f23c512b
commit cb846d0c56
10 changed files with 1443 additions and 46 deletions

View File

@@ -231,6 +231,9 @@
:replying-to="replyingTo"
@send="handleSendMessage"
@send-voice="handleSendVoice"
@send-contact="handleSendContact"
@send-poll="handleSendPoll"
@send-event="handleSendEvent"
@cancel-reply="replyingTo = null"
@typing="handleTyping"
@recording="handleRecordingPresence"
@@ -647,6 +650,121 @@ const handleRecordingPresence = (isRecording: boolean) => {
}
}
// Handle contact send
interface ContactInfo {
displayName: string
phoneNumber: string
organization?: string
}
const handleSendContact = async (contacts: ContactInfo[], quotedId?: string) => {
if (!selectedInstance.value?.value || !selectedChat.value) return
try {
const instanceId = selectedInstance.value.value
const chatId = selectedChat.value.id
await $fetch(`/api/messages/${instanceId}/${chatId}/send`, {
method: 'POST',
body: {
type: 'contact',
contacts,
quotedMessageId: quotedId || replyingTo.value?.messageId
}
})
replyingTo.value = null
messages.value = await $fetch(`/api/messages/${instanceId}/${chatId}`)
} catch (e: any) {
console.error('Error sending contact:', e)
toast.add({
title: 'Error de envío',
description: e?.data?.message || e?.message || 'Error al enviar el contacto',
color: 'error',
duration: 5000
})
}
}
// Handle poll send
interface PollData {
name: string
options: string[]
selectableCount: number
}
const handleSendPoll = async (poll: PollData, quotedId?: string) => {
if (!selectedInstance.value?.value || !selectedChat.value) return
try {
const instanceId = selectedInstance.value.value
const chatId = selectedChat.value.id
await $fetch(`/api/messages/${instanceId}/${chatId}/send`, {
method: 'POST',
body: {
type: 'poll',
...poll,
quotedMessageId: quotedId || replyingTo.value?.messageId
}
})
replyingTo.value = null
messages.value = await $fetch(`/api/messages/${instanceId}/${chatId}`)
} catch (e: any) {
console.error('Error sending poll:', e)
toast.add({
title: 'Error de envío',
description: e?.data?.message || e?.message || 'Error al enviar la encuesta',
color: 'error',
duration: 5000
})
}
}
// Handle event send
interface EventData {
name: string
startDate: string
endDate?: string
description?: string
location?: {
name?: string
address?: string
latitude?: number
longitude?: number
}
}
const handleSendEvent = async (eventData: EventData, quotedId?: string) => {
if (!selectedInstance.value?.value || !selectedChat.value) return
try {
const instanceId = selectedInstance.value.value
const chatId = selectedChat.value.id
await $fetch(`/api/messages/${instanceId}/${chatId}/send`, {
method: 'POST',
body: {
type: 'event',
...eventData,
quotedMessageId: quotedId || replyingTo.value?.messageId
}
})
replyingTo.value = null
messages.value = await $fetch(`/api/messages/${instanceId}/${chatId}`)
} catch (e: any) {
console.error('Error sending event:', e)
toast.add({
title: 'Error de envío',
description: e?.data?.message || e?.message || 'Error al enviar el evento',
color: 'error',
duration: 5000
})
}
}
// Reload chats for current instance
const reloadChats = async () => {
if (!selectedInstance.value?.value) return