Sprint.Shared.Notification 1.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Sprint.Shared.Notification --version 1.1.0
                    
NuGet\Install-Package Sprint.Shared.Notification -Version 1.1.0
                    
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.0" />
                    
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.0" />
                    
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.0
                    
#r "nuget: Sprint.Shared.Notification, 1.1.0"
                    
#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.0
                    
#: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.0
                    
Install as a Cake Addin
#tool nuget:?package=Sprint.Shared.Notification&version=1.1.0
                    
Install as a Cake Tool

🚀 Sprint Shared Notification

A highly extensible and centralized Microsoft Teams Notification Service for .NET applications. It supports Multi-Targeting (.NET 6, 8, 10) and provides seamless integration with Power Automate Adaptive Cards.


✨ Features

  • Multi-Target Support: Compatible with .NET 6, 8 (LTS), and 10.
  • Adaptive Cards Integration: Richly formatted message payloads for better visibility in Teams.
  • Global Error Handling: Automated TeamsAlertMiddleware to catch and report unhandled exceptions.
  • Flexible Customization: Powerful CustomMessageFormatter to inject request context and external service data.
  • Clean API: Minimal setup with extension methods for both IServiceCollection and IApplicationBuilder.


🛠️ Configuration & Setup

There are three ways to register the notification service, depending on your preferred style.

This approach automatically binds values from the Notifications section in your appsettings.json.

appsettings.json Template:

{
  "Notifications": {
    "TeamsWebhookUrl": "https://m365x.webhook.office.com/...",
    "ApplicationName": "SPRINT-ORDER-API",
    "EnableNotification": true
  }
}

Program.cs Setup:

// Simplest way: Reads from IConfiguration automatically
builder.Services.AddTeamsNotification(builder.Configuration);

// Or with additional overrides:
builder.Services.AddTeamsNotification(builder.Configuration, options => 
{
    options.ApplicationName = "OVERRIDDEN-NAME"; // Further customization if needed
});

Option 2: Using Action Delegate

Fully manual setup without relying on appsettings.json sections.

builder.Services.AddTeamsNotification(options => 
{
    options.TeamsWebhookUrl = "https://your-webhook-url";
    options.ApplicationName = "MANUAL-SETUP-API";
    options.EnableNotification = true;
});

Option 3: Using Pre-configured Object

Useful when you already have an options object or values from other sources.

var teamsOptions = new TeamsNotificationOptions 
{
    TeamsWebhookUrl = "https://your-webhook-url",
    ApplicationName = "OBJECT-BASED-SETUP",
    EnableNotification = true
};

builder.Services.AddTeamsNotification(teamsOptions);

4. Configure Middleware

Place UseTeamsAlert as early as possible (before standard error handling) to capture all unhandled exceptions.

app.UseTeamsAlert();

🎨 Creative Custom Message Formatting

The CustomMessageFormatter allows you to customize the message sent to Teams when an exception occurs.

Example 1: Extracting Detailed Request Info

You can extract headers, query strings, and body information from the HttpContext.

options.CustomMessageFormatter = (ctx, ex) => 
{
    var method = ctx.Request.Method;
    var path = ctx.Request.Path;
    var userAgent = ctx.Request.Headers["User-Agent"];
    var traceId = ctx.TraceIdentifier;

    return $"**Method:** {method}\n" +
           $"**Path:** {path}\n" +
           $"**Agent:** {userAgent}\n" +
           $"**Trace ID:** `{traceId}`";
};

Example 2: Accessing External Services via DI

Use ctx.RequestServices to access your registered services (e.g., IUserContext, ICurrentUser) to identify the user who encountered the error.

options.CustomMessageFormatter = (ctx, ex) => 
{
    // Access registered services from the DI container
    var userService = ctx.RequestServices.GetRequiredService<ICurrentUserService>();
    var userName = userService.UserName ?? "Anonymous";
    var userIp = ctx.Connection.RemoteIpAddress?.ToString() ?? "Unknown";

    return $"**User:** {userName}\n" +
           $"**IP Address:** {userIp}";
};

Example 3: Full Context (Request + User + Response)

options.CustomMessageFormatter = (ctx, ex) => 
{
    var sb = new StringBuilder();
    sb.AppendLine($"🆘 **Endpoint:** {ctx.Request.Method} {ctx.Request.Path}");
    
    // Auth Information
    if (ctx.User.Identity?.IsAuthenticated == true)
    {
        sb.AppendLine($"👤 **User:** {ctx.User.Identity.Name}");
    }

    // Query String
    if (ctx.Request.QueryString.HasValue)
    {
        sb.AppendLine($"❓ **Query:** {ctx.Request.QueryString.Value}");
    }

    // Trace ID for correlation with logs
    sb.AppendLine($"🆔 **Trace ID:** `{ctx.TraceIdentifier}`");

    return sb.ToString();
};

📤 Manual Notification Usage

Inject INotificationService into your handlers or controllers.

public class OrderService
{
    private readonly INotificationService _notifier;

    public OrderService(INotificationService notifier) => _notifier = notifier;

    public async Task ProcessOrderAsync(Order order)
    {
        try 
        {
            // Do something...
            await _notifier.SendMessageAsync("📦 Order Status", $"Order #{order.Id} has been processed.");
        }
        catch (Exception ex)
        {
            await _notifier.SendErrorAsync(ex, $"Failed to process Order #{order.Id}");
            throw;
        }
    }
}

📄 License

Released under the MIT License.

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 (1)

Showing the top 1 NuGet packages that depend on Sprint.Shared.Notification:

Package Downloads
Sprint.Shared.Infrastructure

Shared infrastructure library for Sprint OMS services (.NET 10+): base handlers/entities, repositories and unit of work, FastEndpoints/OpenAPI helpers, caching (Redis + output cache), gRPC interceptors, observability (OpenTelemetry), Hangfire scheduling, adaptive concurrency, column encryption and HTTP client helpers.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.6 1,004 9/14/2026
1.1.5 112 9/14/2026
1.1.4 780 6/10/2026
1.1.3 269 4/15/2026
1.1.2 656 3/27/2026
1.1.1 138 3/26/2026
1.1.0 136 3/26/2026