NotificationServices 1.1.0

dotnet add package NotificationServices --version 1.1.0                
NuGet\Install-Package NotificationServices -Version 1.1.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NotificationServices" Version="1.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NotificationServices --version 1.1.0                
#r "nuget: NotificationServices, 1.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install NotificationServices as a Cake Addin
#addin nuget:?package=NotificationServices&version=1.1.0

// Install NotificationServices as a Cake Tool
#tool nuget:?package=NotificationServices&version=1.1.0                

Breaking Changes in 1.1.0 while sending Notification via FCM
The current version supports the following functionalities: AWS: Send Email, SMS & Push Notification using a Basic AWS Authentication method. PLIVO: Send SMS TWILIO: Send SMS FCM: Send Push Notifications using JSON Service Account OneSignal: Send text Push Notifications with segments, filters or player ids
Configuration To start with setting the credentials use the Configuration class:
AWS

NotificationServices.Configuration.Instance.AWSAccessKey = "<your access key>";
NotificationServices.Configuration.Instance.AWSSecretKey = "<your secret key>";
NotificationServices.Configuration.Instance.AWSFCMPNSARN = "<your arn for fcm>";
NotificationServices.Configuration.Instance.AWSIOSPNSARN = "<your arn for ios>";
NotificationServices.Configuration.Instance.AWSRegionEndPoint = "<your region endpoint>";


Firebase Push notifications Set the environment variable GOOGLE_APPLICATION_CREDENTIALS in your system pointing to your service account json file. For more details visit: https://firebase.google.com/docs/admin/setup?authuser=0#add-sdk

TWILIO

NotificationServices.Configuration.Instance.TwilioAccountSID = "<your twilio account sid>";
NotificationServices.Configuration.Instance.TwilioAuthToken = "<your twilio auth token>";
NotificationServices.Configuration.Instance.TwilioFromNumber = "<your twilio number from which to send>";

PLIVO

NotificationServices.Configuration.Instance.PlivoAuthID = "<your plivo auth id>";
NotificationServices.Configuration.Instance.PlivoAuthToken = "<your plivo auth token>";
NotificationServices.Configuration.Instance.PlivoFromPhoneNumber = "<your twilio number from which to send>";

*OneSignal

NotificationServices.Configuration.Instance.OneSignalAppId = "<your OneSignal App Id>";
NotificationServices.Configuration.Instance.OneSignalAPIKey = "<your OneSignal Rest api key>";



Email
To send out emails get an instance of IEmailSender via EmailSenderFactory. You can then send the email by calling SendAWSEmailAsync. It expects 4 parameters.

  • Source: The source/sender of the email. This needs to be verified in the Simple Email Service
  • ToEmail: The recipient of the email
  • TemplateName: The name of the template to use. You can create templates from cli and can learn more from here. https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-personalized-email-api.html
  • TemplateData: The data to substitute in the Template. See the above link to see how to pass the data.
var EmailSender = EmailSenderFactory.GetAWSEmailSender();
EmailSender.SendAWSEmailAsync("noreply@services.com", "recipient@services.com", "ConfirmEmailTemplate", $"{{ \"Link\":\"{EmailCallbackUrl}\", \"Name\": \"{FirstName}\" }}");



SMS
To send out sms get an instance of ISMSSender via SMSSenderFactory. You can then send the email by calling SendSmsAsync. It expects 4 parameters.

  • number: The recipient number to which the sms needs to be sent.
  • message: Text Message to be sent.
  • SenderId: This is an optional parameter whose default value is "Notif". The sender id to be displayed when the sms is received.
  • SMSType: This is an optional parameter whose default value is "Transactional". The type of sms either it is "Promotional" or "Transactional".

AWS

var SMSSender = SMSSenderFactory.GetAWSSMSSender();
SMSSender.SendSmsAsync("<your number with country code", "Hello World");

Twilio

var SMSSender = SMSSenderFactory.GetTwilioSMSSender();
SMSSender.SendSmsAsync("<your number with country code", "Hello World");

Plivo

var SMSSender = SMSSenderFactory.GetPlivoSMSSender();
SMSSender.SendSmsAsync("<your number with country code", "Hello World");



Push Notifications
To send out push notifications get an instance of IPushNotificationSender via PushNotificationSenderFactory.
FCM You can then send the push notification by calling SendFirebasePushNotification for Firebase.

  • Token: FCMToken of specific device
  • Title: Title of Notification
  • Body: Message of Notification
  • Data: A dictionary of data to be sent in notification
var Dictionary = new Dictionary<string, string>();
Dictionary.Add("UserId", "32-34-1234");
await PushNotificationSenderFactory.GetFirebasePushNotificationSender().SendFirebasePushNotification(<FCMToken>, "Hello Title", "Hello Text", Dictionary);

You can also send to a specific topic & to multiple tokens using the methods SendFirebasePushNotificationToTopic & SendFirebasePushNotification.
AWS Before sending out a push notification via AWS a topic needs to be created for each user using CreateAWSEndpointAsync. It takes 3 parameters:

  • topic: You can pass your user id here. The function will create a topic with this name in AWS.
  • token: The device token which is retrieved from ios & Android installations. For iOS it will be a hexadecimal string.
  • platform: Either iOS or Android. If 'iOS' an endpoint will be created in AWSIOSPNSARN. For Android an endpoint will be created in AWSFCMPNSARN
var PushNotificationSender = PushNotificationSenderFactory.GetAWSPushNotificationSender();
PushNotificationSender.CreateAWSEndpointAsync("<topic name>","<your device token>", "<platform>");

CreateAWSEndpointAsync will create a Topic with the given 'topic', Create an endpoint in the given 'platform' with the given 'token'. Internally it will also create a subscription in the topic with the newly created endpoint. The reason is explained later on. CreateAWSEndpointAsync returns a PushNotificationResponseDto which return the ARN's for Topic, Subscription & Endpoint.

You will be able to then send a push notification to a particular topic using SendAWSPushNotificationAsync. It takes 2 parameters

  • TopicArn: An array of fcm device tokens to which the notifications need to be sent.
  • Payload: The payload is of type SNS. The payload will be converted to a json format: { "APNS": "{"aps":{"alert": "Check out these awesome deals!","url":"www.amazon.com"} }", "APNS_SANDBOX": "{"aps":{"alert": "Check out these awesome deals!","url":"www.amazon.com"} }", "FCM": "{"data":{"message":"Check out these awesome deals!","url":"www.amazon.com"}}", }
PushNotificationSender.SendAWSPushNotificationAsync("<topic arn>", <payload>);

One Signal Sending out Text Push Notifications can be done via 3 ways. Here is a sample for sending out with Filters. You can similarly send for segments or player ids.

PushNotificationSenderFactory.GetOneSignalPushNotificationSender()
            .SendOneSignalPushNotificationWithFilters(
                new object[]{
                    new {
                        field = "tag",
                        key="email",
                        relation="=",
                        value="hello@hello.com"
                    }
                }, // The filters to which push notifications to be sent out
                new { en = "Hello Title" },  // The title for the push notification
                new { en = "Hello Sub Title" },   // The sub-title for the push notification
                new { en = "Hello Message" },  // The message for the push notification
                new { path = "/login" },  // Any Other data to be passed in
            );
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.0 545 5/21/2020
1.0.9 534 5/15/2020
1.0.8 417 4/23/2020
1.0.7 485 4/23/2020
1.0.6 1,553 3/12/2020
1.0.5 517 3/12/2020
1.0.4 1,533 12/7/2019
1.0.3 649 9/13/2019
1.0.2 461 9/12/2019
1.0.1 459 9/12/2019
1.0.0 480 9/8/2019