public static async Task <NotificationOutcome> SendDirectAsync(NotificationHubClient _hub, string notice, string token) { var notification = new FcmNotification(notice); var ret = await _hub.SendDirectNotificationAsync(notification, token); await LogFeedback(_hub, ret.NotificationId); return(ret); }
public async Task SendNotificationUser(string msg, string destUser) { var hub = NotificationHubClient.CreateClientFromConnectionString(Constants.NewsFullAccessConnectionString, Constants.NewsNotificationHubName); Notification notification = new FcmNotification("{\"data\":{\"message\":\"" + msg + "\"}}"); await hub.SendNotificationAsync(notification, destUser); }
public void FcmNotification_Priority_Should_Serialize_As_String_Normal() { var n = new FcmNotification(); n.Priority = FcmNotificationPriority.Normal; var str = n.ToString(); Assert.IsTrue(str.Contains("normal")); }
public void FcmNotification_Priority_Should_Serialize_As_String_High() { var n = new FcmNotification(); n.Priority = FcmNotificationPriority.High; var str = n.ToString(); Assert.IsTrue(str.Contains("high")); }
private async Task SendDirectNotificationAsync_SendDirectFcmBatchNotification_GetSuccessfulResultBack() { LoadMockData(); var notification = new FcmNotification("{\"data\":{\"message\":\"Message\"}}"); var notificationResult = await _hubClient.SendDirectNotificationAsync(notification, new[] { _configuration["FcmDeviceToken"] }); Assert.Equal(NotificationOutcomeState.Enqueued, notificationResult.State); RecordTestResults(); }
private async Task SendNotificationAsync_SendGcmNativeNotification_GetSuccessfulResultBack() { LoadMockData(); var notification = new FcmNotification("{\"data\":{\"message\":\"Message\"}}"); var notificationResult = await _hubClient.SendNotificationAsync(notification, "someRandomTag1 && someRandomTag2"); Assert.Equal(NotificationOutcomeState.Enqueued, notificationResult.State); RecordTestResults(); }
public void GetGetFcmPayloadConentToTopicOk() { var notification = new FcmNotification("testBodyKey", "testBodyValue"); var fcmPayload = notification.GetPayload("testTarget", true, true); var expectedPayload = "{" + "\"message\":{" + "\"notification\":{" + "\"body\":\"{\\\"testBodyKey\\\":\\\"testBodyValue\\\"}\"" + "}," + "\"topic\":\"testTarget\"" + "}," + "\"validate_only\":true" + "}"; Assert.Equal(expectedPayload, fcmPayload); }
/// <summary> /// Creates a <see cref="Notification"/> from a <see cref="IPushMessage"/>. /// </summary> /// <param name="message">The <see cref="IPushMessage"/> to create the <see cref="Notification"/> from.</param> /// <returns>The resulting <see cref="Notification"/>.</returns> protected virtual Notification CreateNotification(IPushMessage message) { if (message == null) { throw new ArgumentNullException("message"); } Notification notification = null; ApplePushMessage apnsPush; WindowsPushMessage wnsPush; MpnsPushMessage mpnsPush; TemplatePushMessage templatePush; if ((wnsPush = message as WindowsPushMessage) != null) { notification = new WindowsNotification(wnsPush.ToString(), wnsPush.Headers); } else if ((mpnsPush = message as MpnsPushMessage) != null) { notification = new MpnsNotification(mpnsPush.ToString(), mpnsPush.Headers); } else if ((apnsPush = message as ApplePushMessage) != null) { DateTime?expiration = null; if (apnsPush.Expiration.HasValue) { expiration = apnsPush.Expiration.Value.DateTime; } notification = new AppleNotification(message.ToString(), expiration); } else if (message is GooglePushMessage) { notification = new FcmNotification(message.ToString()); } else if ((templatePush = message as TemplatePushMessage) != null) { notification = new TemplateNotification(templatePush); } else { throw new InvalidOperationException(GetUnknownPayloadError(message)); } return(notification); }
public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "notify")] HttpRequest req, ILogger log) { string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); SendAlertModel sam = JsonConvert.DeserializeObject <SendAlertModel>(requestBody); List <string> watches = new List <string>(); AlarmSystem.Core.Entity.DB.AlarmLog alarmLog; try { watches = GetWatchesToNotify(sam); alarmLog = CreateAlarmLog(sam); } catch (InvalidDataException e) { return(new BadRequestObjectResult(e.Message)); } catch (EntityNotFoundException e) { return(new NotFoundObjectResult(e.Message)); } string accessSignature = Environment.GetEnvironmentVariable("DefaultFullSharedAccessSignature"); string hubName = Environment.GetEnvironmentVariable("NotificationHubName"); Microsoft.Azure.NotificationHubs.Notification nof = new FcmNotification(MakeJsonPayload(alarmLog)); if (watches.Count == 0) { return(new NoContentResult()); } foreach (string watch in watches) { await _hub.SendDirectNotificationAsync(nof, watch); } return(new OkResult()); }
public static async Task Run([CosmosDBTrigger( databaseName: "iqanscosmosdb1", collectionName: "promo", ConnectionStringSetting = "CosmosDB.ConnectionString", LeaseCollectionName = "leases")] IReadOnlyList <Document> input, ILogger log) { if (input != null && input.Count > 0) { log.LogInformation("Documents modified " + input.Count); var promoText = input[0].GetPropertyValue <string>("text"); log.LogInformation("Promo Id " + input[0].Id); log.LogInformation("Promo Text " + promoText); var connectionString = "REPLACE WITH YOUR NOTIFICATION HUB CONNECTION STRING"; var hubName = "REPLACE WITH YOUR NOTIFICATION HUB NAME"; var nhClient = NotificationHubClient.CreateClientFromConnectionString(connectionString, hubName); var notificationPayload = "{\"data\":{\"body\":\"" + promoText + "\",\"title\":\"" + input[0].Id + "\"}}"; var notification = new FcmNotification(notificationPayload); var outcomeFcmByTag = await nhClient.SendFcmNativeNotificationAsync(notificationPayload); } }
private async Task CleanupInstallations() { var emptyNotif = new FcmNotification("{\"data\":{\"message\":\"ola\"}}"); await _hub.SendNotificationAsync(emptyNotif, "default"); var allRegistrations = await _hub.GetAllRegistrationsAsync(0); foreach (var registration in allRegistrations) { var installationId = string.Empty; var tags = registration.Tags; foreach (var tag in tags) { if (tag.Contains("InstallationId:")) { installationId = tag.Substring(tag.IndexOf('{') + 1, 32); } } if (installationId == String.Empty) { return; } else { Trace.TraceError(installationId); } var receivedInstallation = await _hub.GetInstallationAsync(installationId); if (receivedInstallation.PushChannelExpired == true) { await _hub.DeleteInstallationAsync(receivedInstallation.InstallationId); } } }
public async Task SendAsync(TrackingUpdate trackingUpdate) { FcmNotification notification = new FcmNotification(JsonConvert.SerializeObject(trackingUpdate)); await _hub.SendNotificationAsync(notification, new List <string>() { trackingUpdate.trackingNumber }); }
private void SendNotification(NotificationMessage notificationMessage) { CloudNotification cloudNotification = new FcmNotification(); cloudNotification.sendNotification(notificationMessage); }
/// <inheritdoc/> public async Task <NotificationResult> SendToTopic(FcmNotification notification, string topic) { string requestBody = notification.GetPayload(topic, true, isTestingMode); return(await SendViaHttpV1(requestBody)); }
/// <inheritdoc/> public async Task <NotificationResult> Send(FcmNotification notification, string deviceToken) { string requestBody = notification.GetPayload(deviceToken, false, isTestingMode); return(await SendViaHttpV1(requestBody)); }
public FcmMessageBuilder SetNotification(FcmNotification notification) { _msg.FcmNotification = notification; return(this); }