From 859f9a23236cce5ae172350c1d0372e81281b57f Mon Sep 17 00:00:00 2001 From: Francesco Lorenzo D'Amico Date: Mon, 24 Aug 2026 14:56:53 +0200 Subject: [PATCH] Tag Telegram notifications with the current environment --- .../Services/ContactMessageNotificationService.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/RazorPagesMovie/Services/ContactMessageNotificationService.cs b/RazorPagesMovie/Services/ContactMessageNotificationService.cs index de1d6d3..ba9250e 100644 --- a/RazorPagesMovie/Services/ContactMessageNotificationService.cs +++ b/RazorPagesMovie/Services/ContactMessageNotificationService.cs @@ -12,6 +12,7 @@ public class ContactMessageNotificationService : BackgroundService private readonly IHttpClientFactory _httpClientFactory; private readonly IConfiguration _configuration; private readonly IContactMessageNotificationQueue _queue; + private readonly IHostEnvironment _hostEnvironment; private readonly ILogger _logger; public ContactMessageNotificationService( @@ -19,12 +20,14 @@ public class ContactMessageNotificationService : BackgroundService IHttpClientFactory httpClientFactory, IConfiguration configuration, IContactMessageNotificationQueue queue, + IHostEnvironment hostEnvironment, ILogger logger) { _scopeFactory = scopeFactory; _httpClientFactory = httpClientFactory; _configuration = configuration; _queue = queue; + _hostEnvironment = hostEnvironment; _logger = logger; } @@ -105,7 +108,7 @@ public class ContactMessageNotificationService : BackgroundService return; } - var text = $"Neue Kontaktanfrage von {eintrag.Name}\n" + var text = $"[{GetEnvironmentTag()}] Neue Kontaktanfrage von {eintrag.Name}\n" + $"E-Mail: {eintrag.Email}\n" + (string.IsNullOrWhiteSpace(eintrag.Phone) ? "" : $"Telefon: {eintrag.Phone}\n") + (string.IsNullOrWhiteSpace(eintrag.Subject) ? "" : $"Betreff: {eintrag.Subject}\n") @@ -136,4 +139,12 @@ public class ContactMessageNotificationService : BackgroundService _logger.LogError(ex, "Telegram-Versand fehlgeschlagen für ContactMessage {Id}", eintrag.Id); } } + + private string GetEnvironmentTag() => _hostEnvironment.EnvironmentName switch + { + "Development" => "DEV", + "Staging" => "TEST", + "Production" => "PROD", + var other => other.ToUpperInvariant() + }; }