Add channel test providers for Email, Slack, Teams, and Webhook
Some checks failed
Docs CI / lint-and-preview (push) Has been cancelled

- Implemented EmailChannelTestProvider to generate email preview payloads.
- Implemented SlackChannelTestProvider to create Slack message previews.
- Implemented TeamsChannelTestProvider for generating Teams Adaptive Card previews.
- Implemented WebhookChannelTestProvider to create webhook payloads.
- Added INotifyChannelTestProvider interface for channel-specific preview generation.
- Created ChannelTestPreviewContracts for request and response models.
- Developed NotifyChannelTestService to handle test send requests and generate previews.
- Added rate limit policies for test sends and delivery history.
- Implemented unit tests for service registration and binding.
- Updated project files to include necessary dependencies and configurations.
This commit is contained in:
2025-10-19 23:29:34 +03:00
parent 8e7ce55542
commit 5fd4032c7c
239 changed files with 17245 additions and 3155 deletions

View File

@@ -0,0 +1,84 @@
using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using StellaOps.Notify.Models;
namespace StellaOps.Notify.Engine;
/// <summary>
/// Contract implemented by Notify channel plug-ins to generate channel-specific test preview payloads.
/// </summary>
public interface INotifyChannelTestProvider
{
/// <summary>
/// Channel type supported by the provider.
/// </summary>
NotifyChannelType ChannelType { get; }
/// <summary>
/// Builds a channel-specific preview for a test-send request.
/// </summary>
Task<ChannelTestPreviewResult> BuildPreviewAsync(ChannelTestPreviewContext context, CancellationToken cancellationToken);
}
/// <summary>
/// Sanitised request payload passed to channel plug-ins when building a preview.
/// </summary>
public sealed record ChannelTestPreviewRequest(
string? TargetOverride,
string? TemplateId,
string? Title,
string? Summary,
string? Body,
string? TextBody,
string? Locale,
IReadOnlyDictionary<string, string> Metadata,
IReadOnlyList<string> Attachments);
/// <summary>
/// Immutable context describing the channel and request for a test preview.
/// </summary>
public sealed record ChannelTestPreviewContext(
string TenantId,
NotifyChannel Channel,
string Target,
ChannelTestPreviewRequest Request,
DateTimeOffset Timestamp,
string TraceId);
/// <summary>
/// Result returned by channel plug-ins for test preview generation.
/// </summary>
public sealed record ChannelTestPreviewResult(
NotifyDeliveryRendered Preview,
IReadOnlyDictionary<string, string>? Metadata);
/// <summary>
/// Exception thrown by plug-ins when preview input is invalid.
/// </summary>
public sealed class ChannelTestPreviewException : Exception
{
public ChannelTestPreviewException(string message)
: base(message)
{
}
}
/// <summary>
/// Shared helpers for channel preview generation.
/// </summary>
public static class ChannelTestPreviewUtilities
{
/// <summary>
/// Computes a lowercase hex SHA-256 body hash for preview payloads.
/// </summary>
public static string ComputeBodyHash(string body)
{
var bytes = Encoding.UTF8.GetBytes(body);
var hash = SHA256.HashData(bytes);
return Convert.ToHexString(hash).ToLowerInvariant();
}
}

View File

@@ -4,4 +4,8 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\StellaOps.Notify.Models\StellaOps.Notify.Models.csproj" />
</ItemGroup>
</Project>