mirror of
https://github.com/Stone-Red-Software/StoneRed.NetificationApi.git
synced 2026-09-04 08:46:05 +02:00
Add RequestUnreadCount and ClearUnread methods to client
This commit is contained in:
@@ -4,18 +4,26 @@ using StoneRed.NetificationApi.Server;
|
||||
using StoneRed.NetificationApi.Server.IdentifyUser;
|
||||
using StoneRed.NetificationApi.Server.Send;
|
||||
|
||||
const string userId = "<UserId>";
|
||||
const string notificationId = "<NotifcationId>";
|
||||
const string clientId = "<ClientId>";
|
||||
const string clientSecret = "<ClientSecret>";
|
||||
// The ID of the user to send the notification to
|
||||
string userId = "test";
|
||||
|
||||
// The ID of the notification to send
|
||||
string notificationId = "test";
|
||||
|
||||
// The client ID and secret to use for the API
|
||||
string clientId = Environment.GetEnvironmentVariable("NOTIFICATION_API_CLIENT_ID", EnvironmentVariableTarget.User) ?? "<ClientId>";
|
||||
string clientSecret = Environment.GetEnvironmentVariable("NOTIFICATION_API_SECRET", EnvironmentVariableTarget.User) ?? "<ClientSecret>";
|
||||
|
||||
// The client is used to receive notifications
|
||||
NotificationApiClient notificationApiClient = new NotificationApiClient(userId, clientId);
|
||||
|
||||
// The server is used to send notifications
|
||||
NotificationApiServer notificationApiServer = new NotificationApiServer(clientId, clientSecret, false);
|
||||
|
||||
Console.WriteLine("Start client");
|
||||
NotificationApiClient notificationApiClient = new NotificationApiClient("test", clientId, clientSecret, false);
|
||||
await notificationApiClient.Start();
|
||||
Console.WriteLine("Client started");
|
||||
|
||||
notificationApiClient.RequestNotifications();
|
||||
|
||||
notificationApiClient.RequestedNotificationsReceived += (sender, args) =>
|
||||
{
|
||||
Console.WriteLine("Requested notifications received");
|
||||
@@ -34,13 +42,23 @@ notificationApiClient.NewNotificationsReceived += (sender, args) =>
|
||||
}
|
||||
};
|
||||
|
||||
NotificationApiServer notificationApiServer = new NotificationApiServer(clientId, clientSecret, false);
|
||||
notificationApiClient.UnreadCountReceived += (sender, args) =>
|
||||
{
|
||||
Console.WriteLine($"Unread count received: {args.Count}");
|
||||
};
|
||||
|
||||
Console.WriteLine("Request unread count");
|
||||
notificationApiClient.RequestUnreadCount();
|
||||
Console.WriteLine("Unread count requested");
|
||||
|
||||
Console.WriteLine("Request notifications");
|
||||
notificationApiClient.RequestNotifications(5);
|
||||
Console.WriteLine("Notifications requested");
|
||||
|
||||
Console.WriteLine("Identify user");
|
||||
await notificationApiServer.Identify(new IdentifyUserData
|
||||
{
|
||||
UserId = userId,
|
||||
Email = "[email protected]"
|
||||
UserId = userId
|
||||
});
|
||||
Console.WriteLine("User identified");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user