.NET SDK for Novu - The open-source notification infrastructure for engineers. ๐
novu-dotnet targets .NET Standard 2.0 and is compatible with .NET Core 2.0+ and .NET Framework 4.6.1+.
dotnet add package Novu
using Novu.DTO;
using Novu.Models;
using Novu;
...
var novuConfiguration = new NovuClientConfiguration
{
// Defaults to https://api.novu.co/v1
Url = "https://novu-api.my-domain.com/v1",
ApiKey = "12345",
};
var novu = new NovuClient(novuConfiguration);
var subscribers = await novu.Subscribers.GetSubscribers();
using Novu.DTO;
using Novu.Models;
using Novu;
...
var config = new NovuClientConfiguration
{
ApiKey = "my-key",
};
var client = new NovuClient(config);
using Novu.DTO;
using Novu.Models;
using Novu;
...
var subscribers = await client.Subscriber.GetSubscribers()
using Novu.DTO;
using Novu.Models;
using Novu;
...
var subscriber = await client.Subscriber.GetSubscriber("subscriberId");
using Novu.DTO;
using Novu.Models;
using Novu;
...
var additionalData = new List<AdditionalDataDto>
{
new AdditionalDataDto
{
Key = "External ID",
Value = "1122334455"
},
{
Key = "SMS_PREFERENCE",
Value = "EMERGENT_ONLY"
}
};
var newSubscriberDto = new CreateSubscriberDto
{
SubscriberId = Guid.NewGuid().ToString(),
FirstName = "John",
LastName = "Doe",
Avatar = "https://unslpash.com/random",
Email = "[email protected]",
Locale = "en-US",
Phone = "+11112223333",
Data = additionalData
};
var subscriber = await client.Subcriber.CreateSubscriber()
using Novu.DTO;
using Novu.Models;
using Novu;
...
var subscriber = client.Subscriber.GetSubscriber("subscriberId");
subscriber.FirstName = "Updated";
subscriber.LastName = "Subscriber";
var updatedSubscriber = await client.Subscriber.UpdateSubscriber(subscriber);
using Novu.DTO;
using Novu.Models;
using Novu;
...
var deleted = await client.Subscriber.DeleteSubscriber("subscriberId");
using Novu.DTO;
using Novu.Models;
using Novu;
...
var onlineDto = new SubscriberOnlineDto
{
IsOnline = true
};
var online = await client.Subscriber.UpdateOnlineStatus("subscriberId", onlineDto);
using Novu.DTO; using Novu.Models; using Novu; ...
// OnboardEventPayload.cs
public class OnboardEventPayload
{
[JsonProperty("username")]
public string Username { get; set; }
[JsonProperty("welcomeMessage")]
public string WelcomeMessage { get; set; }
}
// MyFile.cs
var onboardingMessage = new OnboardEventPayload
{
Username = "jdoe",
WelcomeMessage = "Welcome to novu-dotnet"
};
var payload = new EventTriggerDataDto()
{
EventName = "onboarding",
To = { SubscriberId = "subscriberId" },
Payload = onboardingMessage
};
var trigger = await client.Event.Trigger(payload);
if (trigger.TriggerResponsePayloadDto.Acknowledged)
{
Console.WriteLine("Trigger has been created.");
}
using Novu.DTO;
using Novu.Models;
using Novu;
...
var payload = new List<EventTriggerDataDto>()
{
new()
{
EventName = "test",
To = { SubscriberId = subscriber.SubscriberId},
Payload = new TestRecord(){ Message = "Hello"}
},
new()
{
EventName = "test",
To = { SubscriberId = subscriber.SubscriberId},
Payload = new TestRecord(){ Message = "World"}
},
};
var trigger = await client.Event.TriggerBulkAsync(payload);
using Novu.DTO;
using Novu.Models;
using Novu;
...
var testRecord = new TestRecord
{
Message = "This is a test message"
};
var dto = new EventTriggerDataDto()
{
EventName = "test",
To =
{
SubscriberId = subscriber.SubscriberId
},
Payload = testRecord
};
var trigger = await client.Event.TriggerBroadcastAsync(dto);
using Novu.DTO;
using Novu.Models;
using Novu;
...
var cancelled = await client.Event.TriggerCancelAsync("triggerTransactionId");
// Get Topic
var result = await client.Topic.GetTopicAsync("my-topic");
// Get Topics
var results = await client.Topic.GetTopicsAsync();
// Create Topic
var topicRequest = new TopicCreateDto
{
Key = $"test:topic:{Guid.NewGuid().ToString()}",
Name = "Test Topic",
};
var topic = await client.Topic.CreateTopicAsync(topicRequest);
// Add Subscriber to Topic
var subscriberList = new TopicSubscriberUpdateDto
{
Keys = new List<string>
{
"test:subscriber:1",
}
};
var result = await client.Topic.AddSubscriberAsync(topic.Data.Key, subscriberList);
// Remove Subscriber from Topic
var subscriberList = new TopicSubscriberUpdateDto
{
Keys = new List<string>
{
"test:subscriber:1",
}
};
var result = await client.Topic.RemoveSubscriberAsync(topic.Data.Key, subscriberList);
// Delete Topic
await client.Topic.DeleteTopicAsync("my-topic");
// Rename Topic
var topicRequest = new TopicRenameDto
{
Name = "New Name"
};
var result = await client.Topic.RenameTopicAsync("my-topic", topicRequest);
All code is located under the src
directory and this will service as the project root.
Novu
is the main SDK with Novu.Tests
housing all unit tests.
Clients
directory holds all clients that house the actual implementation of the various API calls.DTO
directory holds all Data Transfer ObjectsExceptions
directory holds the custom exception creationsInterfaces
directory holds all interfaces that are inteded to outline how a class should be structured.Models
directory holds various modelsUtilities
directory holds various utility functions used around the project.