update messenger

This commit is contained in:
2025-06-09 22:32:36 +07:00
parent 3bcf3a2775
commit 9c9957a6f1
3 changed files with 93 additions and 3 deletions

View File

@@ -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");
}
}
}