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:
68
server/api/messages/[instanceId]/[chatId]/alias.put.ts
Normal file
68
server/api/messages/[instanceId]/[chatId]/alias.put.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* PUT /api/messages/:instanceId/:chatId/alias
|
||||
* Update the alias of a chat
|
||||
*/
|
||||
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')
|
||||
const chatId = getRouterParam(event, 'chatId')
|
||||
|
||||
if (!instanceId) {
|
||||
throw createError({ statusCode: 400, message: 'Missing instanceId' })
|
||||
}
|
||||
|
||||
if (!chatId) {
|
||||
throw createError({ statusCode: 400, message: 'Missing chatId' })
|
||||
}
|
||||
|
||||
const body = await readBody<{ alias: string | null }>(event)
|
||||
|
||||
// alias can be null to remove it, or a string to set it
|
||||
if (body?.alias === undefined) {
|
||||
throw createError({ statusCode: 400, message: 'Missing alias in request body' })
|
||||
}
|
||||
|
||||
try {
|
||||
// Update the alias
|
||||
const result = await query(
|
||||
`UPDATE chats
|
||||
SET alias = $1, updated_at = NOW()
|
||||
WHERE id = $2 AND instance_id = $3
|
||||
RETURNING id, jid, name, alias, is_group`,
|
||||
[body.alias || null, chatId, instanceId]
|
||||
)
|
||||
|
||||
if (result.rows.length === 0) {
|
||||
throw createError({ statusCode: 404, message: 'Chat not found' })
|
||||
}
|
||||
|
||||
const chat = result.rows[0]
|
||||
return {
|
||||
success: true,
|
||||
chat: {
|
||||
id: chat.id,
|
||||
jid: chat.jid,
|
||||
name: chat.name,
|
||||
alias: chat.alias,
|
||||
isGroup: chat.is_group
|
||||
}
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('[Alias API] Error updating alias:', error)
|
||||
|
||||
if (error.statusCode) {
|
||||
throw error
|
||||
}
|
||||
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
message: error.message || 'Error updating alias'
|
||||
})
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user