Sprint.Shared.Notification 1.1.3

dotnet add package Sprint.Shared.Notification --version 1.1.3
                    
NuGet\Install-Package Sprint.Shared.Notification -Version 1.1.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Sprint.Shared.Notification" Version="1.1.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Sprint.Shared.Notification" Version="1.1.3" />
                    
Directory.Packages.props
<PackageReference Include="Sprint.Shared.Notification" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Sprint.Shared.Notification --version 1.1.3
                    
#r "nuget: Sprint.Shared.Notification, 1.1.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Sprint.Shared.Notification@1.1.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Sprint.Shared.Notification&version=1.1.3
                    
Install as a Cake Addin
#tool nuget:?package=Sprint.Shared.Notification&version=1.1.3
                    
Install as a Cake Tool

🚀 Shared.Notification (Microsoft Teams)

High-performance Microsoft Teams notification library designed for the Sprint ecosystem. This library delivers rapid, resilient, and non-blocking notifications, ensuring that critical alerts do not interfere with your application's core business logic performance.


🏗️ Key Features

  • ⚡ Non-blocking Architecture: Leverages System.Threading.Channels (Producer-Consumer) to move message delivery to background threads 100% asynchronously.
  • 🛡️ Multi-Framework Support: Full compatibility with .NET 6.0, 8.0 (LTS), and 10.0.
  • 🔒 RAM Protection (Bounded Channels): Memory-safe design with a capacity of 1,000 notifications. Implements DropWrite mode when the queue is full to prevent memory leaks and protect application uptime.
  • 🔄 Smart Retry & Reliability: Built-in Exponential Backoff for handling Rate Limits (HTTP 429) and Service Unavailable (HTTP 503) automatically.
  • 📦 Automatic Content Truncation: Smartly adjusts Title and Message length if they exceed Teams' payload limits (prevents HTTP 400 Bad Request errors).
  • 🎨 Adaptive Cards (v1.5): Modern, beautiful notification layout featuring a "View Full Stack Trace" toggle (via ShowCard) for error details.

⚙️ Installation & Setup

1. Register Services in Program.cs

Flexible registration options (Configuration-based, Action-based, or Options-based):

using Shared.Notification.Teams;

// Option 1: Automatic from Configuration (Section "Notifications:...")
builder.Services.AddTeamsNotification(builder.Configuration);

// Option 2: Manual Setup via Action
builder.Services.AddTeamsNotification(options => {
    options.TeamsWebhookUrl = "https://your-webhook-url...";
    options.ApplicationName = "Order-Core-API";
    options.EnableNotification = true;
});

// Option 3: Manual Setup via Options Object
var teamsOptions = new TeamsNotificationOptions {
    TeamsWebhookUrl = "https://your-webhook-url...",
    ApplicationName = "Order-Core-API"
};
builder.Services.AddTeamsNotification(teamsOptions);

2. Global Exception Monitoring (Middleware)

To automatically catch and send all unhandled exceptions from your API to MS Teams, add the middleware in Program.cs (after app.Run() or after your routing configuration):

var app = builder.Build();

// ... other middlewares ...

// 🚨 Enable Global Teams Alert Middleware
app.UseTeamsAlert();

app.Run();

3. Configuration Template (appsettings.json)

{
  "Notifications": {
    "TeamsWebhookUrl": "https://m365.webhook...",
    "ApplicationName": "Sprint-OMS-Order-API",
    "EnableNotification": true
  }
}

💡 Usage Examples

1. Sending Regular Messages (SendMessageAsync)

Important: Execution returns immediately (non-blocking). The main thread continues while the message is sent in the background.

public class OrderEndpoint : Endpoint<OrderRequest>
{
    private readonly INotificationService _notificationService;

    public OrderEndpoint(INotificationService notificationService)
    {
        _notificationService = notificationService;
    }

    public override async Task HandleAsync(OrderRequest req, CancellationToken ct)
    {
        // ... Business Logic ...

        // Send notification (Fire-and-forget to background queue)
        await _notificationService.SendMessageAsync(
            title: "📦 New Order Received", 
            message: $"Order ID: {req.OrderId} processed successfully."
        );
        
        // Main thread continues immediately!
        await SendOkAsync(ct);
    }
}

2. Creative Custom Message Formatting

Unlock the full power of notifications by customizing the message body. You can inject HTTP context details, environment information, or even data from other services:

builder.Services.AddTeamsNotification(options => {
    options.ApplicationName = "Sprint";
    
    // 🎨 Powerful Custom Formatter
    options.CustomMessageFormatter = (httpContext, exception) => {
        var request = httpContext?.Request;
        return $"🌐 Request: {request?.Method} {request?.Path}\n" +
               $"❌ Error: {exception?.Message}";
    };
});

🛡️ Resilience & Reliability Design

This library is engineered for mission-critical stability:

  1. Bounded Channel Queue: Limits memory usage to 1,000 pending notifications. If the system is overwhelmed, new notifications are safely dropped to ensure application stability.
  2. Retry Mechanism: Implements 3 retry cycles for HTTP 429/503 errors, with increasing delays (2s, 4s, 6s).
  3. Payload Safety: If the first attempt fails due to size limits (HTTP 400), the library automatically truncates the content (Title < 500 characters, Message < 15,000 characters) and retries once more.

© 2026 Sprint-OMS Development Team

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.3 180 4/15/2026
1.1.2 263 3/27/2026
1.1.1 105 3/26/2026
1.1.0 104 3/26/2026