To bridge the gap between a .NET 10 backend and a chat interface (like Microsoft Teams or Slack), the most robust architectural approach is to use an asynchronous, event-driven pattern. This ensures that your API remains responsive while the "Heavy Lifting" of message formatting and delivery happens in the background.

1. The Architecture

Rather than sending the card directly within the request pipeline, use an Internal Domain Event.

  • Trigger: A POST request hits your FastAPI or .NET endpoint.

  • Process: Save to the DB, then publish a message to a service bus (Azure Service Bus, RabbitMQ, or MediatR).

  • Consumer: A background worker picks up the event, constructs the Adaptive Card JSON, and posts it to the Chat Webhook.

2. Implementation (C# 14 / .NET 10)

Using the new Primary Constructors and Raw String Literals makes the JSON construction significantly cleaner.

Code
using System.Text.Json;

// Define your request record
public record RequestCreatedEvent(Guid Id, string Title, string CreatedBy);

// The Service to handle Chat Notifications
public class ChatNotificationService(IHttpClientFactory factory) 
{
    public async Task SendAdaptiveCardAsync(RequestCreatedEvent @event)
    {
        var client = factory.CreateClient("ChatWebhook");

        // C# Raw String Literals make Adaptive Card JSON easy to maintain
        string cardJson = $$"""
        {
            "type": "AdaptiveCard",
            "version": "1.5",
            "body": [
                {
                    "type": "TextBlock",
                    "text": "New Request Created",
                    "weight": "Bolder",
                    "size": "Medium"
                },
                {
                    "type": "FactSet",
                    "facts": [
                        { "title": "ID:", "value": "{{@event.Id}}" },
                        { "title": "Title:", "value": "{{@event.Title}}" },
                        { "title": "By:", "value": "{{@event.CreatedBy}}" }
                    ]
                }
            ],
            "actions": [
                {
                    "type": "Action.OpenUrl",
                    "title": "View Request",
                    "url": "https://yourportal.com/requests/{{@event.Id}}"
                }
            ]
        }
        """;

        var payload = new { type = "message", attachments = new[] { 
            new { contentType = "application/vnd.microsoft.card.adaptive", content = JsonSerializer.Deserialize(cardJson) } 
        }};

        await client.PostAsJsonAsync("", payload);
    }
}

3. Key Considerations for Production

  • Resilience: Wrap your webhook call in a Polly retry policy. Chat platforms often rate-limit incoming webhooks if your system spikes in traffic.

  • Security: Never hardcode the Webhook URL. Use Azure Key Vault or User Secrets to manage the endpoint URI.

  • Schema Validation: For complex cards, use the AdaptiveCards NuGet package to build the card object graph instead of raw JSON. This provides compile-time safety for your UI layout.

4. Alternative: The Logic App / Power Automate Route

If you want to keep your microservice "lean," you can simply push a message to an Azure Service Bus queue. You then set up a Logic App with a "When a message is received" trigger that uses the built-in "Post an Adaptive Card" connector. This decouples your C# code entirely from the Chat UI logic.