ESH.FirebaseNotification 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package ESH.FirebaseNotification --version 1.0.1                
NuGet\Install-Package ESH.FirebaseNotification -Version 1.0.1                
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="ESH.FirebaseNotification" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ESH.FirebaseNotification --version 1.0.1                
#r "nuget: ESH.FirebaseNotification, 1.0.1"                
#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 ESH.FirebaseNotification as a Cake Addin
#addin nuget:?package=ESH.FirebaseNotification&version=1.0.1

// Install ESH.FirebaseNotification as a Cake Tool
#tool nuget:?package=ESH.FirebaseNotification&version=1.0.1                

📚 ESH.FirebaseNotification

این لایبرری برای ارسال نوتیفیکیشن‌ها از طریق Firebase Cloud Messaging (FCM) طراحی شده است. شما می‌توانید به راحتی این لایبرری را در پروژه‌های مختلف خود برای ارسال نوتیفیکیشن‌ها به دستگاه‌های موبایل از طریق Firebase استفاده کنید.


🚀 شروع سریع

برای استفاده از این لایبرری، کافی است که پکیج را به پروژه خود اضافه کرده و تنظیمات اولیه را انجام دهید.

1. نصب پکیج

برای نصب این لایبرری از NuGet استفاده کنید. دستور زیر را در کنسول NuGet وارد کنید:

dotnet add package ESH.FirebaseNotification

2. تنظیمات اولیه

برای راه‌اندازی Firebase، فایل پیکربندی Firebase (firebase-config.json) را از Firebase Console دریافت کرده و آن را در مسیر مشخص قرار دهید. سپس این مسیر را هنگام تنظیم سرویس در پروژه خود وارد کنید.

using Microsoft.Extensions.DependencyInjection;
using ESH.FirebaseNotification.Extensions;

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        // مسیر فایل پیکربندی Firebase
        string firebaseConfigPath = "configs/firebase-config.json";
        
        // افزودن سرویس نوتیفیکیشن
        services.AddNotificationLibrary(firebaseConfigPath);
    }
}

🧑‍💻 ویژگی‌ها

این لایبرری ویژگی‌های زیر را ارائه می‌دهد:

  • ارسال نوتیفیکیشن به یک دستگاه خاص: ارسال نوتیفیکیشن به یک دستگاه مشخص با استفاده از Device Token.
  • پشتیبانی از Firebase Admin SDK: استفاده از Firebase Admin SDK برای ارسال نوتیفیکیشن‌ها به دستگاه‌های موبایل.
  • سفارشی‌سازی پیام نوتیفیکیشن: امکان تعیین عنوان، متن و توکن دستگاه گیرنده.

⚙️ نحوه استفاده

1. ارسال نوتیفیکیشن به یک دستگاه خاص

برای ارسال نوتیفیکیشن به یک دستگاه خاص، باید از متد SendNotificationAsync استفاده کنید و توکن دستگاه را به همراه عنوان و متن پیام ارسال کنید.

public class FirebaseNotificationService : INotificationService
{
    public async Task SendNotificationAsync(Notification notification)
    {
        if (notification == null)
        {
            throw new ArgumentNullException(nameof(notification));
        }

        var message = new Message
        {
            Notification = new FirebaseAdmin.Messaging.Notification
            {
                Title = notification.Title,
                Body = notification.Body
            },
            Token = notification.DeviceToken
        };

        await FirebaseMessaging.DefaultInstance.SendAsync(message);
    }
}

2. افزودن سرویس نوتیفیکیشن به Dependency Injection

برای استفاده از این سرویس در پروژه‌های ASP.NET Core، کافی است سرویس FirebaseNotificationService را به Dependency Injection اضافه کنید.

namespace ESH.FirebaseNotification.Extensions
{
    public static class ServiceCollectionExtensions
    {
        public static IServiceCollection AddNotificationLibrary(
            this IServiceCollection services, string firebaseConfigPath)
        {
            services.AddSingleton<INotificationService>(provider =>
                new FirebaseNotificationService(firebaseConfigPath));
            
            return services;
        }
    }
}

🛠️ تنظیمات پیشرفته

1. پیکربندی مسیر فایل تنظیمات Firebase

در کلاس Startup.cs، مسیر فایل firebase-config.json را به روش زیر وارد کنید:

string firebaseConfigPath = "configs/firebase-config.json";

2. ارسال نوتیفیکیشن به گروهی از دستگاه‌ها

می‌توانید از topics برای ارسال نوتیفیکیشن به گروهی از دستگاه‌ها استفاده کنید. به این ترتیب، نیازی به دانستن توکن هر دستگاه نخواهید داشت:

public async Task SendNotificationToTopicAsync(string topic, string title, string body)
{
    var message = new Message()
    {
        Topic = topic,
        Notification = new FirebaseAdmin.Messaging.Notification
        {
            Title = title,
            Body = body
        }
    };

    await FirebaseMessaging.DefaultInstance.SendAsync(message);
}

🌐 همکاری و مشارکت

اگر تمایل دارید به این پروژه کمک کنید، می‌توانید آن را از طریق GitHub مشاهده کنید و پیشنهادات خود را به اشتراک بگذارید.

🔗 GitHub: github.com/ehsanshahsevani/ESH.FirebaseNotification


📧 ارتباط با ما

برای هر گونه سوال یا پیشنهاد، می‌توانید از طریق ایمیل یا GitHub Issues با ما در ارتباط باشید:

📧 Email: ShahsevaniEhsan@gmail.com


📝 مجوز

این پروژه تحت مجوز MIT منتشر شده است.


نکات مهم:

  • این لایبرری به شما امکان ارسال نوتیفیکیشن‌های شخصی‌سازی شده به دستگاه‌های مختلف از طریق Firebase را می‌دهد.
  • به مستندسازی دقیق کلاس‌ها و متدها توجه کرده‌ایم تا استفاده از لایبرری برای توسعه‌دهندگان ساده باشد.
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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 is compatible.  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.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
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.0.2 102 12/5/2024
1.0.1 95 12/5/2024
1.0.0 91 12/5/2024

### v1.0.0 - Initial Release
- First stable release of the ESH.FirebaseNotification library.
- Integrated Firebase Cloud Messaging (FCM) for sending push notifications.
- Supports sending notifications to individual devices via device tokens.
- Added dependency injection support for seamless integration into .NET projects.
- Provides customizable notification content (title, body, and device token).
- Simple configuration with Firebase credentials file for easy setup.

This initial version provides all the necessary tools to send push notifications in a .NET application using Firebase.