public void SendNotification(IContactNotificationSubscription subscription, INotification notification) { IPushKeySetProvider keyProvider = Factory.KeySetProvider(); var pushSubscription = new PushSubscription(subscription.Endpoint, subscription.P256dh, subscription.AuthorizationToken); var vapidDetails = new VapidDetails(notification.Subject, keyProvider.PublicKey, keyProvider.PrivateKey); var webPushClient = new WebPushClient(); try { string message = string.Format("{{ \"body\":\"{0}\", \"title\":\"{1}\", \"icon\":\"{2}\", \"badge\":\"{3}\" }}", notification.Body, notification.Title, notification.Icon, notification.Badge ); webPushClient.SendNotificationAsync(pushSubscription, message, vapidDetails); //webPushClient.SendNotification(subscription, "payload", gcmAPIKey); } catch (WebPushException exception) { Console.WriteLine("Http STATUS code" + exception.StatusCode); } }
public AutomationActionResult Execute(AutomationActionContext context) { IContactNotificationSubscription profileEntry = Tracker.Current.Contact.GetFacet <IContactNotificationSubscription>("PushNotifications"); Item _notificationOne = Sitecore.Configuration.Factory.GetDatabase("web").GetItem(new ID("{19875827-6AB9-4539-9B90-00FC5475BFAC}")); INotification _notification = new Notification(_notificationOne); new NotificationSender().SendNotification(profileEntry, _notification); return(AutomationActionResult.Continue); }
public ActionResult SendSubscriptionMessage() { if (!Tracker.IsActive) { Tracker.StartTracking(); } IContactNotificationSubscription profileEntry = Tracker.Current.Contact.GetFacet <IContactNotificationSubscription>("PushNotifications"); if (profileEntry == null || string.IsNullOrEmpty(profileEntry.Endpoint)) { return(Content("<!-- No notification recorded on profile -->")); } Item _notificationOne = Sitecore.Context.Database.GetItem(new ID("{19875827-6AB9-4539-9B90-00FC5475BFAC}")); INotification _notification = new Notification(_notificationOne); new NotificationSender().SendNotification(profileEntry, _notification); return(Content("")); }