feat: telegram chat ID en usuarios (UI + notificacion al asignado)

This commit is contained in:
Lizandro Guarnizo
2026-07-07 00:26:31 -05:00
parent 6a3793a63b
commit 62397f2f8c
2 changed files with 47 additions and 7 deletions
+24
View File
@@ -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
}
}