Tag Telegram notifications with the current environment
Deploy Staging / deploy (push) Successful in 1m12s
Deploy Staging / deploy (push) Successful in 1m12s
This commit is contained in:
@@ -12,6 +12,7 @@ public class ContactMessageNotificationService : BackgroundService
|
|||||||
private readonly IHttpClientFactory _httpClientFactory;
|
private readonly IHttpClientFactory _httpClientFactory;
|
||||||
private readonly IConfiguration _configuration;
|
private readonly IConfiguration _configuration;
|
||||||
private readonly IContactMessageNotificationQueue _queue;
|
private readonly IContactMessageNotificationQueue _queue;
|
||||||
|
private readonly IHostEnvironment _hostEnvironment;
|
||||||
private readonly ILogger<ContactMessageNotificationService> _logger;
|
private readonly ILogger<ContactMessageNotificationService> _logger;
|
||||||
|
|
||||||
public ContactMessageNotificationService(
|
public ContactMessageNotificationService(
|
||||||
@@ -19,12 +20,14 @@ public class ContactMessageNotificationService : BackgroundService
|
|||||||
IHttpClientFactory httpClientFactory,
|
IHttpClientFactory httpClientFactory,
|
||||||
IConfiguration configuration,
|
IConfiguration configuration,
|
||||||
IContactMessageNotificationQueue queue,
|
IContactMessageNotificationQueue queue,
|
||||||
|
IHostEnvironment hostEnvironment,
|
||||||
ILogger<ContactMessageNotificationService> logger)
|
ILogger<ContactMessageNotificationService> logger)
|
||||||
{
|
{
|
||||||
_scopeFactory = scopeFactory;
|
_scopeFactory = scopeFactory;
|
||||||
_httpClientFactory = httpClientFactory;
|
_httpClientFactory = httpClientFactory;
|
||||||
_configuration = configuration;
|
_configuration = configuration;
|
||||||
_queue = queue;
|
_queue = queue;
|
||||||
|
_hostEnvironment = hostEnvironment;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,7 +108,7 @@ public class ContactMessageNotificationService : BackgroundService
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var text = $"Neue Kontaktanfrage von {eintrag.Name}\n"
|
var text = $"[{GetEnvironmentTag()}] Neue Kontaktanfrage von {eintrag.Name}\n"
|
||||||
+ $"E-Mail: {eintrag.Email}\n"
|
+ $"E-Mail: {eintrag.Email}\n"
|
||||||
+ (string.IsNullOrWhiteSpace(eintrag.Phone) ? "" : $"Telefon: {eintrag.Phone}\n")
|
+ (string.IsNullOrWhiteSpace(eintrag.Phone) ? "" : $"Telefon: {eintrag.Phone}\n")
|
||||||
+ (string.IsNullOrWhiteSpace(eintrag.Subject) ? "" : $"Betreff: {eintrag.Subject}\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);
|
_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()
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user