Пример #1
0
        private async Task UpsertUserAsync(IUser user)
        {
            if (client == null)
            {
                return;
            }

            try
            {
                var settings = new Dictionary <string, NotificationSettingDto>
                {
                    [Providers.WebPush] = new NotificationSettingDto
                    {
                        Send           = NotificationSend.Send,
                        DelayInSeconds = null
                    },

                    [Providers.Email] = new NotificationSettingDto
                    {
                        Send           = NotificationSend.Send,
                        DelayInSeconds = 5 * 60
                    }
                };

                var userRequest = new UpsertUserDto
                {
                    Id                = user.Id,
                    FullName          = user.Claims.DisplayName(),
                    PreferredLanguage = "en",
                    PreferredTimezone = null,
                    Settings          = settings
                };

                if (user.Email.IsEmail())
                {
                    userRequest.EmailAddress = user.Email;
                }

                var response = await client.Users.PostUsersAsync(options.AppId, new UpsertUsersDto
                {
                    Requests = new List <UpsertUserDto>
                    {
                        userRequest
                    }
                });

                var apiKey = response.First().ApiKey;

                await userResolver.SetClaimAsync(user.Id, SquidexClaimTypes.NotifoKey, response.First().ApiKey, true);
            }
            catch (NotifoException ex)
            {
                log.LogError(ex, "Failed to register user in notifo: {details}.", ex.ToString());
            }
            catch (Exception ex)
            {
                log.LogError(ex, "Failed to register user in notifo.");
            }
        }
Пример #2
0
        private async Task UpsertUserAsync(IUser user)
        {
            if (client == null)
            {
                return;
            }

            var settings = new NotificationSettingsDto
            {
                [Providers.WebPush] = new NotificationSettingDto
                {
                    Send           = NotificationSend.Send,
                    DelayInSeconds = null
                },

                [Providers.Email] = new NotificationSettingDto
                {
                    Send           = NotificationSend.Send,
                    DelayInSeconds = 5 * 60
                }
            };

            var userRequest = new UpsertUserDto
            {
                Id                = user.Id,
                FullName          = user.Claims.DisplayName(),
                PreferredLanguage = "en",
                PreferredTimezone = null,
                Settings          = settings,
            };

            if (user.Email.IsEmail())
            {
                userRequest.EmailAddress = user.Email;
            }

            var response = await client.Users.PostUsersAsync(options.AppId, new UpsertUsersDto
            {
                Requests = new List <UpsertUserDto>
                {
                    userRequest
                }
            });

            await userResolver.SetClaimAsync(user.Id, SquidexClaimTypes.NotifoKey, response.First().ApiKey);
        }
Пример #3
0
        public static async Task Main(string[] args)
        {
            var client =
                NotifoClientBuilder.Create()
                .SetApiKey(ApiKey)
                .SetApiUrl("https://*****:*****@squidex.io", Id = userId
                    };

                    await client.Users.PostUsersAsync(AppId, new UpsertUsersDto
                    {
                        Requests = new List <UpsertUserDto>
                        {
                            request
                        },
                    });
                }

                Console.WriteLine("Generated Users...");
            }

            if (args?.Contains("--subscriptions") == true)
            {
                Console.WriteLine("Generating Subscriptions...");

                foreach (var userId in users)
                {
                    var request = new SubscribeDto {
                        TopicPrefix = TopicPrefix
                    };

                    await client.Users.PostSubscriptionAsync(AppId, userId, request);
                }

                Console.WriteLine("Generated Subscriptions...");
            }

            if (args?.Contains("--no-events") != true)
            {
                Console.WriteLine("Generating Events...");

                for (var i = 0; i < 1; i++)
                {
                    var request = new PublishRequestDto
                    {
                        Topic = Topic
                    };

                    var formatting = new NotificationFormattingDto
                    {
                        Body = new LocalizedText
                        {
                            ["en"] = "Hello Body {{var}}",
                            ["de"] = "Hallo Body {{var}}"
                        },
                        Subject = new LocalizedText
                        {
                            ["en"] = "Hello Title {{var}}",
                            ["de"] = "Hallo Title {{var}}"
                        },
                    };

                    request.Properties = new EventProperties
                    {
                        ["var"] = "123"
                    };

                    request.Preformatted = formatting;

                    await client.Events.PostEventsAsync(AppId, new PublishManyRequestDto
                    {
                        Requests = new List <PublishRequestDto>
                        {
                            request
                        }
                    });
                }

                Console.WriteLine("Generated Events...");
            }
        }