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 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() { { "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; } } } }