Document DB v12 - Improved Interceptors with Soft Delete Integration, AI protections, & Admin UI with Aspire Integration!How!?
Sending Notifications
Overview
Section titled “Overview”The INotificationManager provides methods to send, query, and cancel notifications.
Sending a Notification
Section titled “Sending a Notification”INotificationManager notifications; // injected
// Simple notificationawait notifications.Send( title: "Hello", message: "This is a notification");
// Full notification with all optionsawait notifications.Send(new Notification{ Id = 1, Title = "Order Shipped", Message = "Your order #12345 has shipped!", Channel = "Orders", BadgeCount = 3, Thread = "order-updates", Payload = new Dictionary<string, string> { { "orderId", "12345" }, { "action", "shipped" } }});Notification Properties
Section titled “Notification Properties”| Property | Type | Description |
|---|---|---|
Id |
int |
Unique notification ID |
Title |
string? |
Notification title |
Message |
string? |
Notification body (required) |
Channel |
string? |
Channel identifier |
Payload |
IDictionary<string, string> |
Custom key/value data |
BadgeCount |
int? |
App icon badge number |
Thread |
string? |
Thread ID for grouping |
ScheduleDate |
DateTimeOffset? |
When to display |
RepeatInterval |
IntervalTrigger? |
Repeating schedule |
Geofence |
GeofenceTrigger? |
Location-based trigger |
Getting Pending Notifications
Section titled “Getting Pending Notifications”var pending = await notifications.GetPendingNotifications();foreach (var notification in pending){ Console.WriteLine($"{notification.Id}: {notification.Title}");}
// Get a specific notificationvar notification = await notifications.GetNotification(1);Cancelling Notifications
Section titled “Cancelling Notifications”// Cancel a specific notificationawait notifications.Cancel(1);
// Cancel by scopeawait notifications.Cancel(CancelScope.All); // Everythingawait notifications.Cancel(CancelScope.DisplayedOnly); // Only displayed notificationsawait notifications.Cancel(CancelScope.Pending); // Only pending (scheduled/triggered)Badge Management
Section titled “Badge Management”Badge count management is platform-dependent.
// Check if badges are supported and setvar success = await notifications.TrySetBadge(5);
// Get current badge countvar (supported, count) = await notifications.TryGetBadge();if (supported) Console.WriteLine($"Badge: {count}");

