Exemplo n.º 1
0
        public Task AddTargetsAsync(MessagingJob job, User user)
        {
            var chatId = GetChatId(user);

            if (!string.IsNullOrWhiteSpace(chatId))
            {
                job.Targets[TelegramChatId] = chatId;
            }

            return(Task.CompletedTask);
        }
Exemplo n.º 2
0
        public async Task <bool> SendAsync(MessagingJob job, string text,
                                           CancellationToken ct)
        {
            if (!job.Targets.TryGetValue(TelegramChatId, out var chatId))
            {
                return(false);
            }

            await SendMessageAsync(text, chatId, ct);

            return(true);
        }
Exemplo n.º 3
0
        public async Task <bool> SendAsync(MessagingJob job, string text,
                                           CancellationToken ct)
        {
            using (var httpClient = httpClientFactory.CreateClient())
            {
                Exception?exception = null;

                if (job.Targets.TryGetValue(ThreemaPhoneNumber, out var phoneNumber))
                {
                    try
                    {
                        if (await SendAsync(httpClient, "phone", phoneNumber, text, ct))
                        {
                            return(true);
                        }
                    }
                    catch (Exception ex)
                    {
                        exception = ex;
                    }
                }

                if (job.Targets.TryGetValue(ThreemaEmail, out var email))
                {
                    try
                    {
                        if (await SendAsync(httpClient, "email", email, text, ct))
                        {
                            return(true);
                        }
                    }
                    catch (Exception ex)
                    {
                        exception = ex;
                    }
                }

                if (exception != null)
                {
                    throw exception;
                }
            }

            return(false);
        }
Exemplo n.º 4
0
        public Task AddTargetsAsync(MessagingJob job, User user)
        {
            var phoneNumber = user.PhoneNumber;

            if (!string.IsNullOrWhiteSpace(phoneNumber))
            {
                job.Targets[ThreemaPhoneNumber] = phoneNumber;
            }

            var email = user.EmailAddress;

            if (!string.IsNullOrWhiteSpace(email))
            {
                job.Targets[ThreemaEmail] = email;
            }

            return(Task.CompletedTask);
        }