diff --git a/backend/gestion/db/db_notifications.go b/backend/gestion/db/db_notifications.go index 8bd09d3c..148aff17 100644 --- a/backend/gestion/db/db_notifications.go +++ b/backend/gestion/db/db_notifications.go @@ -38,7 +38,12 @@ func (d *Database) NotifyClient(username string, commandID int, notifType, messa if services.TelegramBot != nil && services.TelegramBot.IsNotificationsEnabled() { if chatID, ok, err := d.GetClientTelegramChatID(username); err == nil && ok { - go sendTelegramNotif(chatID, fmt.Sprintf("🔔 Notification\n\n%s", message)) + dedupKey := fmt.Sprintf("notif:dedup:%d:%s", commandID, notifType) + if set, _ := Redis.SetNX(RedisCtx, dedupKey, "1", 5*time.Minute).Result(); set { + go sendTelegramNotif(chatID, fmt.Sprintf("🔔 Notification\n\n%s", message)) + } else { + log.Printf("⚠️ [NOTIF] Doublon détecté (cmd=%d, type=%s) — Telegram ignoré", commandID, notifType) + } } } @@ -64,7 +69,12 @@ func (d *Database) NotifyLivreur(username string, commandID int, notifType, mess if services.TelegramBot != nil && services.TelegramBot.IsNotificationsEnabled() { if chatID, ok, err := d.GetUserTelegramChatID(username); err == nil && ok { - go sendTelegramNotif(chatID, fmt.Sprintf("🔔 Notification\n\n%s", message)) + dedupKey := fmt.Sprintf("notif:dedup:livreur:%d:%s", commandID, notifType) + if set, _ := Redis.SetNX(RedisCtx, dedupKey, "1", 5*time.Minute).Result(); set { + go sendTelegramNotif(chatID, fmt.Sprintf("🔔 Notification\n\n%s", message)) + } else { + log.Printf("⚠️ [NOTIF] Doublon livreur détecté (cmd=%d, type=%s) — Telegram ignoré", commandID, notifType) + } } }