Feat: Agregar sistema de alias para chats
All checks were successful
build-and-deploy / build-and-deploy (push) Successful in 1m10s
All checks were successful
build-and-deploy / build-and-deploy (push) Successful in 1m10s
- Agregar campo alias a tabla chats con migración 003 - Crear endpoint PUT /api/messages/:instanceId/:chatId/alias - Modificar MCP para priorizar alias sobre nombres automáticos - Crear modal ChatAliasModal para editar alias desde UI - Agregar botón de editar alias en ChatItem - Integrar modal en página de mensajes El alias permite asignar nombres personalizados a chats que tienen prioridad sobre los nombres de WhatsApp tanto en la interfaz como en el MCP para agentes IA.
This commit is contained in:
126
app/components/messages/ChatAliasModal.vue
Normal file
126
app/components/messages/ChatAliasModal.vue
Normal file
@@ -0,0 +1,126 @@
|
||||
<template>
|
||||
<UModal v-model:open="isOpen">
|
||||
<template #content>
|
||||
<UCard>
|
||||
<template #header>
|
||||
<div class="flex items-center justify-between">
|
||||
<h3 class="text-lg font-semibold text-white">Editar Alias</h3>
|
||||
<UButton
|
||||
variant="ghost"
|
||||
icon="i-lucide-x"
|
||||
size="sm"
|
||||
@click="isOpen = false"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div class="space-y-4">
|
||||
<p class="text-sm text-[var(--wa-text-muted)]">
|
||||
Asigna un nombre personalizado a este chat. El alias tiene prioridad sobre el nombre de WhatsApp.
|
||||
</p>
|
||||
|
||||
<UFormField label="Alias">
|
||||
<UInput
|
||||
v-model="aliasValue"
|
||||
placeholder="Nombre personalizado (dejar vacio para usar nombre original)"
|
||||
icon="i-lucide-pencil"
|
||||
size="lg"
|
||||
/>
|
||||
</UFormField>
|
||||
|
||||
<div v-if="chat" class="p-3 rounded-lg bg-[var(--wa-bg-light)]">
|
||||
<p class="text-xs text-[var(--wa-text-muted)] mb-1">Nombre original:</p>
|
||||
<p class="text-sm text-white">{{ chat.originalName || chat.jid }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
<div class="flex justify-between gap-2">
|
||||
<UButton
|
||||
v-if="aliasValue"
|
||||
variant="ghost"
|
||||
color="error"
|
||||
icon="i-lucide-trash-2"
|
||||
@click="clearAlias"
|
||||
>
|
||||
Quitar alias
|
||||
</UButton>
|
||||
<div class="flex-1" />
|
||||
<UButton variant="ghost" @click="isOpen = false">
|
||||
Cancelar
|
||||
</UButton>
|
||||
<UButton
|
||||
:loading="isSaving"
|
||||
@click="handleSave"
|
||||
>
|
||||
Guardar
|
||||
</UButton>
|
||||
</div>
|
||||
</template>
|
||||
</UCard>
|
||||
</template>
|
||||
</UModal>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
interface Chat {
|
||||
id: string
|
||||
jid: string
|
||||
name: string
|
||||
alias?: string | null
|
||||
originalName?: string
|
||||
isGroup?: boolean
|
||||
}
|
||||
|
||||
const props = defineProps<{
|
||||
chat: Chat | null
|
||||
instanceId: string
|
||||
}>()
|
||||
|
||||
const isOpen = defineModel<boolean>('open', { default: false })
|
||||
|
||||
const emit = defineEmits<{
|
||||
saved: [chat: Chat]
|
||||
}>()
|
||||
|
||||
const isSaving = ref(false)
|
||||
const aliasValue = ref('')
|
||||
|
||||
const clearAlias = () => {
|
||||
aliasValue.value = ''
|
||||
}
|
||||
|
||||
const handleSave = async () => {
|
||||
if (!props.chat || !props.instanceId) return
|
||||
|
||||
isSaving.value = true
|
||||
try {
|
||||
const response = await $fetch(`/api/messages/${props.instanceId}/${props.chat.id}/alias`, {
|
||||
method: 'PUT',
|
||||
body: {
|
||||
alias: aliasValue.value.trim() || null
|
||||
}
|
||||
})
|
||||
|
||||
if (response.success) {
|
||||
emit('saved', {
|
||||
...props.chat,
|
||||
alias: response.chat.alias,
|
||||
name: response.chat.alias || props.chat.originalName || props.chat.name
|
||||
})
|
||||
isOpen.value = false
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error saving alias:', error)
|
||||
} finally {
|
||||
isSaving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize alias when modal opens or chat changes
|
||||
watch([isOpen, () => props.chat], ([open, chat]) => {
|
||||
if (open && chat) {
|
||||
aliasValue.value = chat.alias || ''
|
||||
}
|
||||
}, { immediate: true })
|
||||
</script>
|
||||
@@ -13,9 +13,25 @@
|
||||
|
||||
<div class="flex-1 min-w-0">
|
||||
<div class="flex items-center justify-between">
|
||||
<p class="font-medium text-[var(--wa-text)] truncate">{{ chat.name }}</p>
|
||||
<div class="flex items-center gap-1 min-w-0">
|
||||
<p class="font-medium text-[var(--wa-text)] truncate">{{ chat.name }}</p>
|
||||
<UIcon
|
||||
v-if="chat.alias"
|
||||
name="i-lucide-pencil"
|
||||
class="w-3 h-3 text-[var(--wa-blue)] flex-shrink-0"
|
||||
title="Tiene alias personalizado"
|
||||
/>
|
||||
</div>
|
||||
<div class="flex items-center gap-1">
|
||||
<span class="text-xs text-[var(--wa-text-muted)]">{{ formatTime(chat.lastMessageAt) }}</span>
|
||||
<!-- Edit alias button -->
|
||||
<button
|
||||
@click.stop="$emit('editAlias', chat)"
|
||||
class="text-xs text-[var(--wa-text-muted)] hover:text-[var(--wa-blue)] opacity-50 hover:opacity-100"
|
||||
title="Editar alias"
|
||||
>
|
||||
<UIcon name="i-lucide-user-pen" class="w-3 h-3" />
|
||||
</button>
|
||||
<!-- Debug button -->
|
||||
<button
|
||||
@click.stop="showDebug = !showDebug"
|
||||
@@ -72,6 +88,8 @@ interface Chat {
|
||||
lastMessageType?: string
|
||||
unreadCount: number
|
||||
isGroup?: boolean
|
||||
alias?: string | null
|
||||
originalName?: string
|
||||
}
|
||||
|
||||
interface Props {
|
||||
@@ -82,6 +100,7 @@ interface Props {
|
||||
const props = defineProps<Props>()
|
||||
defineEmits<{
|
||||
click: []
|
||||
editAlias: [chat: Chat]
|
||||
}>()
|
||||
|
||||
const showDebug = ref(false)
|
||||
|
||||
Reference in New Issue
Block a user