mirror of
https://bitbucket.org/myhomie/mycorerepository.git
synced 2025-12-06 09:41:19 +00:00
46 lines
1.6 KiB
C#
46 lines
1.6 KiB
C#
using FirebaseAdmin.Messaging;
|
|
using MyCore.Interfaces.DTO;
|
|
using MyCore.Interfaces.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MyCore.Framework.Business
|
|
{
|
|
public class NotificationLogic
|
|
{
|
|
public static async Task<bool> PushFCMNotification(NotificationDTO notificationDTO, Home home)
|
|
{
|
|
try
|
|
{
|
|
// Push FCM notif to phones
|
|
var message = new FirebaseAdmin.Messaging.Message()
|
|
{
|
|
Topic = home == null ? "main" : home.Id,
|
|
Notification = new Notification()
|
|
{
|
|
Title = home == null ? notificationDTO.notificationTitle : $"{home.Name} - {notificationDTO.notificationTitle}",
|
|
Body = notificationDTO.notificationMessage
|
|
},
|
|
Data = new Dictionary<string, string>()
|
|
{
|
|
{ "labelButton", notificationDTO.notificationLabelButton },
|
|
{ "type", notificationDTO.type },
|
|
},
|
|
};
|
|
|
|
// Send a message to the device corresponding to the provided
|
|
string response = await FirebaseMessaging.DefaultInstance.SendAsync(message);
|
|
// Response is a message ID string.
|
|
Console.WriteLine("Successfully sent message: " + response);
|
|
return true;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|