private async Task SendFcmNotificationToTopic(JunaNotification junaNotification, string targetTopic, string operationType) { // todo: Validate that operationType sent is a valid operation type. // todo: validate junanotification var fcmData = new { to = $"/topics/{targetTopic}", data = junaNotification }; var json = JsonConvert.SerializeObject(fcmData, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, DateFormatHandling = DateFormatHandling.IsoDateFormat, Formatting = Formatting.Indented, ReferenceLoopHandling = ReferenceLoopHandling.Ignore, ContractResolver = new CamelCasePropertyNamesContractResolver() }); var size = json.Length; var content = new StringContent(JsonConvert.SerializeObject(fcmData, defaultSerializerSettings), Encoding.UTF8, "application/json"); var result = await fcmClient.PostAsync("", content); if (result.IsSuccessStatusCode) { logger.TrackTrace($"Successfully sent push notification"); } else { logger.TrackTrace($"Received error code {result.StatusCode} when trying to send push notification"); } logger.TrackTrace($"Received the following response body from FCM"); logger.TrackTrace($"==============================================="); logger.TrackTrace($"Response body { result.Content.ReadAsStringAsync().Result}"); logger.TrackTrace($"==============================================="); }
public async Task SendFcmUserNotification(JunaNotification junaNotification, JunaUser user, string operationType) { await SendFcmNotificationToTopic(junaNotification, $"JunaUser-{user.ObjectId}", operationType); }
public async Task SendFcmBoardNotification(JunaNotification junaNotification, Board board, string operationType) { await SendFcmNotificationToTopic(junaNotification, $"Board-{board.Id}", operationType); }