mirror of
https://github.com/bitwarden/server.git
synced 2026-02-07 17:33:11 +08:00
47 lines
1.4 KiB
C#
47 lines
1.4 KiB
C#
|
|
using System.Text.Json;
|
|||
|
|
using Bit.Core.AdminConsole.Utilities;
|
|||
|
|
using Bit.Core.Enums;
|
|||
|
|
using Bit.Core.Models.Data;
|
|||
|
|
using Bit.Core.Models.Data.Integrations;
|
|||
|
|
using Bit.Core.Repositories;
|
|||
|
|
|
|||
|
|
namespace Bit.Core.Services;
|
|||
|
|
|
|||
|
|
public class SlackEventHandler(
|
|||
|
|
IOrganizationIntegrationConfigurationRepository configurationRepository,
|
|||
|
|
ISlackService slackService)
|
|||
|
|
: IEventMessageHandler
|
|||
|
|
{
|
|||
|
|
public async Task HandleEventAsync(EventMessage eventMessage)
|
|||
|
|
{
|
|||
|
|
var organizationId = eventMessage.OrganizationId ?? Guid.Empty;
|
|||
|
|
var configurations = await configurationRepository.GetConfigurationDetailsAsync(
|
|||
|
|
organizationId,
|
|||
|
|
IntegrationType.Slack,
|
|||
|
|
eventMessage.Type);
|
|||
|
|
|
|||
|
|
foreach (var configuration in configurations)
|
|||
|
|
{
|
|||
|
|
var config = configuration.MergedConfiguration.Deserialize<SlackIntegrationConfigurationDetails>();
|
|||
|
|
if (config is null)
|
|||
|
|
{
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
await slackService.SendSlackMessageByChannelIdAsync(
|
|||
|
|
config.token,
|
|||
|
|
IntegrationTemplateProcessor.ReplaceTokens(configuration.Template, eventMessage),
|
|||
|
|
config.channelId
|
|||
|
|
);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public async Task HandleManyEventsAsync(IEnumerable<EventMessage> eventMessages)
|
|||
|
|
{
|
|||
|
|
foreach (var eventMessage in eventMessages)
|
|||
|
|
{
|
|||
|
|
await HandleEventAsync(eventMessage);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|