Ejemplo n.º 1
0
        public static string BuildTrackingLink(BaseUserNotification notification, string emailAddress)
        {
            var trackingUrl  = notification.ComputeTrackSeenUrl(Providers.Email, emailAddress);
            var trackingLink = $"<img height=\"0\" width=\"0\" style=\"width: 0px; height: 0px; position: absolute; visibility: hidden;\" src=\"{trackingUrl}\" />";

            return(trackingLink);
        }
Ejemplo n.º 2
0
        public static Message ToFirebaseMessage(this BaseUserNotification notification, string token, bool wakeup, bool isConfirmed)
        {
            var message = new Message
            {
                Token = token
            };

            if (wakeup)
            {
                message.Data =
                    new Dictionary <string, string>()
                    .WithNonEmpty("id", notification.Id.ToString());

                return(message);
            }

            var formatting = notification.Formatting;

            message.Data =
                new Dictionary <string, string>()
                .WithNonEmpty("id", notification.Id.ToString())
                .WithNonEmpty("confirmText", formatting.ConfirmText)
                .WithNonEmpty("confirmUrl", notification.ComputeConfirmUrl(Providers.MobilePush, token))
                .WithNonEmpty("isConfirmed", isConfirmed.ToString())
                .WithNonEmpty("imageLarge", formatting.ImageLarge)
                .WithNonEmpty("imageSmall", formatting.ImageSmall)
                .WithNonEmpty("linkText", formatting.LinkText)
                .WithNonEmpty("linkUrl", formatting.LinkUrl)
                .WithNonEmpty("silent", notification.Silent.ToString())
                .WithNonEmpty("trackDeliveredUrl", notification.ComputeTrackDeliveredUrl(Providers.MobilePush, token))
                .WithNonEmpty("trackSeenUrl", notification.ComputeTrackSeenUrl(Providers.MobilePush, token))
                .WithNonEmpty("trackingUrl", notification.ComputeTrackSeenUrl(Providers.MobilePush, token))
                .WithNonEmpty("data", notification.Data);

            var androidData =
                new Dictionary <string, string>()
                .WithNonEmpty("subject", formatting.Subject)
                .WithNonEmpty("body", formatting.Body);

            var androidConfig = new AndroidConfig
            {
                Data     = androidData,
                Priority = Priority.High
            };

            var apsAlert = new ApsAlert
            {
                Title = formatting.Subject
            };

            if (!string.IsNullOrWhiteSpace(formatting.Body))
            {
                apsAlert.Body = formatting.Body;
            }

            var apnsHeaders = new Dictionary <string, string>
            {
                ["apns-collapse-id"] = notification.Id.ToString(),
                ["apns-push-type"]   = "alert"
            };

            if (notification.TimeToLiveInSeconds is int timeToLive)
            {
                androidConfig.TimeToLive = TimeSpan.FromSeconds(timeToLive);

                var unixTimeSeconds = DateTimeOffset.UtcNow.AddSeconds(timeToLive).ToUnixTimeSeconds().ToString(CultureInfo.InvariantCulture);

                apnsHeaders["apns-expiration"] = timeToLive == 0 ? "0" : unixTimeSeconds;
            }

            var apnsConfig = new ApnsConfig
            {
                Headers = apnsHeaders,
                Aps     = new Aps
                {
                    Alert          = apsAlert,
                    MutableContent = true
                }
            };

            message.Android = androidConfig;
            message.Apns    = apnsConfig;

            return(message);
        }