diff --git a/pkg/services/notif_dispatch.go b/pkg/services/notif_dispatch.go index d834543..74da1da 100644 --- a/pkg/services/notif_dispatch.go +++ b/pkg/services/notif_dispatch.go @@ -297,6 +297,11 @@ func NotificarTareaAsignada(t *models.Tarea) { escapeTelegramHTML(t.Prioridad), escapeTelegramHTML(t.Descripcion)) 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) } } + +// 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 + } +} diff --git a/resources/views/users.html b/resources/views/users.html index ff79bdf..c8499b0 100755 --- a/resources/views/users.html +++ b/resources/views/users.html @@ -120,6 +120,7 @@ Estado = user.estado; Email = user.email; roleName = user.Role.ID; + TelegramChatID = user.telegram_chat_id || ''; " title="Editar"> @@ -218,12 +219,18 @@ + + +

Para recibir notificaciones de tareas por Telegram.

+