Skip to content

Stone-Red-Software/StoneRed.NetificationApi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

StoneRed.NetificationApi

A .NET library for NotificationAPI

Note

An official NotifcationAPI .NET server SDK is now available at notificationapi-com/notificationapi-dotnet-server-sdk
Client-side functionality is currently not available in the official library, this is why this repository will still be maintained.

This is an unofficial library for NotificationAPI and attempts to replicate the functionality of the official Server SDK and JS Client SDK as closely as possible.
(A prebuilt notification widget is not included in this library.)

Supported Features

Server:

  • Send all types of notifications
  • Retract notifications
  • Identify user
  • Set user preferences

Client:

  • Receive In-App notification
  • Get old notifications
  • Get unread notification count
  • Clear unread notifications
  • Get user preferences
  • Update user preferences

Installation

Package Manager

Install-Package StoneRed.NetificationApi

.NET CLI

dotnet add package StoneRed.NetificationApi

Usage

Server

using StoneRed.NetificationApi.Server;
using StoneRed.NetificationApi.Server.Send;

// Initialize NotificationApiServer
NotificationApiServer notificationApiServer = new NotificationApiServer("<ClientId>", "<ClientSecret>", secureMode: false);

// Construct notification
SendNotificationData sendNotificationData = new SendNotificationData
{
    NotificationId = "<NotificationId>",
    User = new NotificationUser
    {
        Id = "<UserId>",
    }
};

// Send notification
await notificationApiServer.Send(sendNotificationData);

Client

using StoneRed.NetificationApi.Client;
using StoneRed.NetificationApi.Client.Models;

// The client is used to receive notifications
NotificationApiClient notificationApiClient = new NotificationApiClient("<UserId>", "<ClientId>");

// Listen for new notifications
notificationApiClient.NewNotificationsReceived += (sender, args) =>
{
    Console.WriteLine("New notifications received");
    foreach (NotificationReceivedData notificationReceiveData in args.Notifications)
    {
        Console.WriteLine($"New notification received: {notificationReceiveData.Id}");
    }
};

// Listen for unread count
notificationApiClient.UnreadCountReceived += (sender, args) =>
{
    Console.WriteLine($"Unread count received: {args.Count}");
};

// Request unread count
notificationApiClient.RequestUnreadCount();

For a more sophisticated example, please check out this example.

Third party licenses