@@ -45,8 +45,17 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
4545 private async void OnTeamsMessageReceived ( TeamsMessageEventArgs e )
4646 {
4747 string teamsMessage = e . TeamsMessage ;
48+ string url ;
4849
49- string url = GetWebhookURL ( _configuration , "TeamsSystemStatusNotification" ) ;
50+ try
51+ {
52+ url = GetWebhookURL ( _configuration ) ;
53+ }
54+ catch ( KeyNotFoundException ex )
55+ {
56+ _logger . LogError ( ex , "Failed to get webhook URL from configuration" ) ;
57+ return ;
58+ }
5059 var client = new HttpClient ( ) ;
5160 client . DefaultRequestHeaders . Accept . Add (
5261 new MediaTypeWithQualityHeaderValue ( "application/json" )
@@ -92,20 +101,14 @@ private StringContent CreateTeamsMessageCard(string message)
92101 return content ;
93102 }
94103
95- private static string GetWebhookURL ( IConfiguration configuration , string secretName )
104+ private static string GetWebhookURL ( IConfiguration configuration )
96105 {
97- string ? keyVaultUri =
98- configuration . GetSection ( "KeyVault" ) [ "VaultUri" ]
99- ?? throw new KeyNotFoundException ( "No key vault in config" ) ;
100-
101- var keyVault = new SecretClient (
102- new Uri ( keyVaultUri ) ,
103- new DefaultAzureCredential ( new DefaultAzureCredentialOptions ( ) )
104- ) ;
105-
106- string webhookURL = keyVault . GetSecret ( secretName ) . Value . Value ;
106+ string ? webhookUrlFromConfig = configuration . GetSection ( "TeamsNotification" ) [
107+ "WebhookUrl"
108+ ] ;
107109
108- return webhookURL ;
110+ return webhookUrlFromConfig
111+ ?? throw new KeyNotFoundException ( "No webhook URL in config" ) ;
109112 }
110113 }
111114}
0 commit comments