Skip to content

A .NET client library to interact with a ntfy server

Notifications You must be signed in to change notification settings

murthysuresh/ntfy-dotnet

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ntfy-dotnet


A .NET library for ntfy, allowing sending and receiving messages.

Useful for:

  • Xamarin (mobile) apps
  • .NET apps
  • C# scripts

Installation

Download the latest release from the releases page or from NuGet.

Usage

Sending a message

using ntfy;

// Create a new client
var client = new Client("https://ntfy.sh");

// Publish a message to the "test" topic
var message = new SendingMessage
        {
            Title = "This is a demo.",
            Actions = new Actions.Action[]
            {
                new Broadcast("label")
                {
                },
                new View("label2", new Uri("https://google.com"))
                {
                }
            }
        };

await client.Publish("test", message);

Receiving a message

using ntfy;

// Create a new client
var client = new Client("https://ntfy.sh");

// Fiter messages by priority
var filter = new Filter
{
    Priorities = new PriorityLevel[] { Priority.High },
};

// Filter messages since 1 hour ago
var since = new Since(new DelayDuration(1, DelayUnit.Hours));

// Subscribe to the "test" topic
var subscription = client.Subscribe(new string[] { "test" }, since: since, filters: filter);

// Process a new message when it arrives
await foreach (var message in subscription.WithCancellation(default))
{
    // Do something with the message
}

Users

You can specify a specific user for sending and receiving messages on private topics.

using ntfy;

// Create a new user
var user = new User("username", "password");

// Pass this user into the Subscribe, Publish, Poll methods

// Verify that the user has access to the "test" topic
var client = new Client("https://ntfy.sh");
bool allowed = await client.CheckAuthentication("test", user);

// You can also call this method without a user to see if the topic is anonymously accessible

Documentation

See the documentation for more information.

Dependencies

  • Microsoft.Bcl.AsyncInterfaces
  • N8.NetTools.HTTP

Supported Frameworks

  • .NET Core 3.1
  • .NET 5.0
  • .NET 6.0
  • .NET 7.0

About

A .NET client library to interact with a ntfy server

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 96.8%
  • Makefile 3.2%