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.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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user