2025-04-23 10:44:43 -04:00
|
|
|
|
using System.Text.Json;
|
2025-05-05 08:04:59 -04:00
|
|
|
|
using System.Text.Json.Nodes;
|
2025-05-27 08:28:50 -04:00
|
|
|
|
using Bit.Core.AdminConsole.Models.Data.Integrations;
|
2025-04-23 10:44:43 -04:00
|
|
|
|
using Bit.Core.Enums;
|
|
|
|
|
|
using Bit.Core.Repositories;
|
|
|
|
|
|
|
2025-05-05 08:04:59 -04:00
|
|
|
|
#nullable enable
|
|
|
|
|
|
|
2025-04-23 10:44:43 -04:00
|
|
|
|
namespace Bit.Core.Services;
|
|
|
|
|
|
|
|
|
|
|
|
public class SlackEventHandler(
|
2025-05-05 08:04:59 -04:00
|
|
|
|
IUserRepository userRepository,
|
|
|
|
|
|
IOrganizationRepository organizationRepository,
|
2025-04-23 10:44:43 -04:00
|
|
|
|
IOrganizationIntegrationConfigurationRepository configurationRepository,
|
|
|
|
|
|
ISlackService slackService)
|
2025-05-05 08:04:59 -04:00
|
|
|
|
: IntegrationEventHandlerBase(userRepository, organizationRepository, configurationRepository)
|
2025-04-23 10:44:43 -04:00
|
|
|
|
{
|
2025-05-05 08:04:59 -04:00
|
|
|
|
protected override IntegrationType GetIntegrationType() => IntegrationType.Slack;
|
2025-04-23 10:44:43 -04:00
|
|
|
|
|
2025-05-05 08:04:59 -04:00
|
|
|
|
protected override async Task ProcessEventIntegrationAsync(JsonObject mergedConfiguration,
|
|
|
|
|
|
string renderedTemplate)
|
2025-04-23 10:44:43 -04:00
|
|
|
|
{
|
2025-05-05 08:04:59 -04:00
|
|
|
|
var config = mergedConfiguration.Deserialize<SlackIntegrationConfigurationDetails>();
|
|
|
|
|
|
if (config is null)
|
2025-04-23 10:44:43 -04:00
|
|
|
|
{
|
2025-05-05 08:04:59 -04:00
|
|
|
|
return;
|
2025-04-23 10:44:43 -04:00
|
|
|
|
}
|
2025-05-05 08:04:59 -04:00
|
|
|
|
|
|
|
|
|
|
await slackService.SendSlackMessageByChannelIdAsync(
|
|
|
|
|
|
config.token,
|
|
|
|
|
|
renderedTemplate,
|
|
|
|
|
|
config.channelId
|
|
|
|
|
|
);
|
2025-04-23 10:44:43 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|