update messenger
This commit is contained in:
@@ -55,8 +55,46 @@ public class WebhookService : IWebhookService
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, $"Error sending webhook notification for user {user.Name}: {ex.Message}");
|
||||
// Don't throw - webhook failures shouldn't break the main flow
|
||||
_logger.LogError(ex, "Error sending webhook notification");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SendMessage(string message, string? telegramChannel = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Get the n8n webhook URL from configuration
|
||||
var webhookUrl = _configuration["N8n:WebhookUrl"];
|
||||
if (string.IsNullOrEmpty(webhookUrl))
|
||||
{
|
||||
_logger.LogWarning("N8n webhook URL not configured, skipping webhook message");
|
||||
return;
|
||||
}
|
||||
|
||||
// Prepare the payload for n8n webhook
|
||||
var payload = new
|
||||
{
|
||||
message = message,
|
||||
timestamp = DateTime.UtcNow,
|
||||
type = "general_message",
|
||||
telegramChannel = telegramChannel
|
||||
};
|
||||
|
||||
// Send the webhook notification
|
||||
var response = await _httpClient.PostAsJsonAsync(webhookUrl, payload);
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
_logger.LogInformation("Successfully sent webhook message");
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning($"Failed to send webhook message. Status: {response.StatusCode}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error sending webhook message");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user