feat: telegram chat ID en usuarios (UI + notificacion al asignado)
This commit is contained in:
@@ -297,6 +297,11 @@ func NotificarTareaAsignada(t *models.Tarea) {
|
|||||||
escapeTelegramHTML(t.Prioridad),
|
escapeTelegramHTML(t.Prioridad),
|
||||||
escapeTelegramHTML(t.Descripcion))
|
escapeTelegramHTML(t.Descripcion))
|
||||||
sendTelegramAdmin(msg)
|
sendTelegramAdmin(msg)
|
||||||
|
|
||||||
|
// También enviar al chat del usuario asignado si tiene TelegramChatID
|
||||||
|
if t.Asignado != nil && t.Asignado.TelegramChatID != "" {
|
||||||
|
go sendTelegramToUser(t.Asignado.TelegramChatID, msg)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -412,3 +417,22 @@ func sendTelegramAdmin(mensaje string) {
|
|||||||
_ = models.CreateTelegramLog(logEntry)
|
_ = models.CreateTelegramLog(logEntry)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sendTelegramToUser envía un mensaje al chat de un usuario usando el primer bot config activo.
|
||||||
|
func sendTelegramToUser(chatID string, mensaje string) {
|
||||||
|
configs, err := models.GetAllTelegramConfigs()
|
||||||
|
if err != nil || len(configs) == 0 {
|
||||||
|
log.Printf("[Notif] No hay configs telegram para enviar a usuario %s", chatID)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, cfg := range configs {
|
||||||
|
if !cfg.Activo {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
ts := &TelegramService{BotToken: cfg.BotToken}
|
||||||
|
if err := ts.SendMessage(chatID, mensaje); err != nil {
|
||||||
|
log.Printf("[Notif] Error enviando telegram a %s: %v", chatID, err)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -120,6 +120,7 @@
|
|||||||
Estado = user.estado;
|
Estado = user.estado;
|
||||||
Email = user.email;
|
Email = user.email;
|
||||||
roleName = user.Role.ID;
|
roleName = user.Role.ID;
|
||||||
|
TelegramChatID = user.telegram_chat_id || '';
|
||||||
" title="Editar">
|
" title="Editar">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
|
||||||
stroke-width="1.5" stroke="currentColor" class="w-5">
|
stroke-width="1.5" stroke="currentColor" class="w-5">
|
||||||
@@ -218,12 +219,18 @@
|
|||||||
<!-- Rol -->
|
<!-- Rol -->
|
||||||
<label class="block mt-4 mb-2" for="editRole">Rol</label>
|
<label class="block mt-4 mb-2" for="editRole">Rol</label>
|
||||||
<select id="editRole" x-model="roleName" class="border border-gray-300 rounded w-full p-2" required>
|
<select id="editRole" x-model="roleName" class="border border-gray-300 rounded w-full p-2" required>
|
||||||
<option value="" disabled selected>Selecciona un rol</option> <!-- Opción predeterminada -->
|
<option value="" disabled selected>Selecciona un rol</option>
|
||||||
<template x-for="role in roles" :key="role.ID">
|
<template x-for="role in roles" :key="role.ID">
|
||||||
<option :value="role.ID" x-text="role.name"></option>
|
<option :value="role.ID" x-text="role.name"></option>
|
||||||
</template>
|
</template>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<!-- Telegram -->
|
||||||
|
<label class="block mt-4 mb-2" for="editTelegram">Chat ID de Telegram</label>
|
||||||
|
<input id="editTelegram" x-model="TelegramChatID" placeholder="Ej: 123456789"
|
||||||
|
class="border border-gray-300 rounded w-full p-2 font-mono">
|
||||||
|
<p class="text-[10px] text-slate-400 mt-0.5">Para recibir notificaciones de tareas por Telegram.</p>
|
||||||
|
|
||||||
<div class="mt-4 flex justify-between">
|
<div class="mt-4 flex justify-between">
|
||||||
<button type="submit" class="bg-[#8eb02f] text-white px-4 py-2 rounded">Guardar Cambios</button>
|
<button type="submit" class="bg-[#8eb02f] text-white px-4 py-2 rounded">Guardar Cambios</button>
|
||||||
<button type="button" class="bg-gray-600 text-white px-4 py-2 rounded"
|
<button type="button" class="bg-gray-600 text-white px-4 py-2 rounded"
|
||||||
@@ -257,6 +264,10 @@
|
|||||||
<option :value="role.ID" x-text="role.name"></option>
|
<option :value="role.ID" x-text="role.name"></option>
|
||||||
</template>
|
</template>
|
||||||
</select>
|
</select>
|
||||||
|
<label class="block mt-4 mb-2" for="addTelegram">Chat ID de Telegram</label>
|
||||||
|
<input id="addTelegram" x-model="newTelegramChatID" placeholder="Ej: 123456789"
|
||||||
|
class="border border-gray-300 rounded w-full p-2 font-mono">
|
||||||
|
<p class="text-[10px] text-slate-400 mt-0.5">Para recibir notificaciones de tareas por Telegram.</p>
|
||||||
<div class="mt-4 flex justify-between">
|
<div class="mt-4 flex justify-between">
|
||||||
<button type="submit" class="bg-[#8eb02f] text-white px-4 py-2 rounded">Guardar </button>
|
<button type="submit" class="bg-[#8eb02f] text-white px-4 py-2 rounded">Guardar </button>
|
||||||
<button type="button" class="bg-gray-600 text-white px-4 py-2 rounded"
|
<button type="button" class="bg-gray-600 text-white px-4 py-2 rounded"
|
||||||
@@ -310,6 +321,7 @@
|
|||||||
newEmail: '',
|
newEmail: '',
|
||||||
newRole: '',
|
newRole: '',
|
||||||
newNombreUsuario: '',
|
newNombreUsuario: '',
|
||||||
|
newTelegramChatID: '',
|
||||||
|
|
||||||
Name: '',
|
Name: '',
|
||||||
NombreUsuario: '',
|
NombreUsuario: '',
|
||||||
@@ -317,6 +329,7 @@
|
|||||||
NewEstado: '',
|
NewEstado: '',
|
||||||
Email: '',
|
Email: '',
|
||||||
roleName: '',
|
roleName: '',
|
||||||
|
TelegramChatID: '',
|
||||||
|
|
||||||
password: '',
|
password: '',
|
||||||
userId: '',
|
userId: '',
|
||||||
@@ -433,7 +446,8 @@
|
|||||||
email: this.newEmail,
|
email: this.newEmail,
|
||||||
role_id: parseInt(this.newRole),
|
role_id: parseInt(this.newRole),
|
||||||
estado: true,
|
estado: true,
|
||||||
tipo: 'sistema'
|
tipo: 'sistema',
|
||||||
|
telegram_chat_id: this.newTelegramChatID
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
@@ -442,6 +456,7 @@
|
|||||||
this.newNombreUsuario = '';
|
this.newNombreUsuario = '';
|
||||||
this.newEmail = '';
|
this.newEmail = '';
|
||||||
this.newRole = '';
|
this.newRole = '';
|
||||||
|
this.newTelegramChatID = '';
|
||||||
this.closeModal();
|
this.closeModal();
|
||||||
this.loadRegister();
|
this.loadRegister();
|
||||||
})
|
})
|
||||||
@@ -457,19 +472,20 @@
|
|||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
name: this.Name, // Usar 'Name' en lugar de 'First_name'
|
name: this.Name,
|
||||||
nombre_usuario: this.NombreUsuario, // Usar 'Nombre_usuario' en lugar de 'Last_name'
|
nombre_usuario: this.NombreUsuario,
|
||||||
email: this.Email, // Usar 'Email'
|
email: this.Email,
|
||||||
role_id: parseInt(this.roleName) // Usar 'roleName'
|
role_id: parseInt(this.roleName),
|
||||||
|
telegram_chat_id: this.TelegramChatID
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// Limpiar campos después de la actualización
|
|
||||||
this.Name = '';
|
this.Name = '';
|
||||||
this.NombreUsuario = '';
|
this.NombreUsuario = '';
|
||||||
this.Email = '';
|
this.Email = '';
|
||||||
this.roleName = '';
|
this.roleName = '';
|
||||||
|
this.TelegramChatID = '';
|
||||||
this.closeModal();
|
this.closeModal();
|
||||||
this.loadRegister();
|
this.loadRegister();
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user