Пример #1
0
 public Task SendSmsAsync(string number, string message)
 {
     // Plug in your SMS service here to send a text message.
     _logger.LogDebug($"sending sms to: {number}, message:{ message}");
     BackgroundJob.Enqueue(() => _smsProvider.SendSmsAsync(number, message));
     return(Task.FromResult(0));
 }
Пример #2
0
        public async Task GenerateNotificationsAsync(IEnumerable <Appointment> newAppointments)
        {
            var emailsToNotify = new Dictionary <string, List <Appointment> >();
            var phonesToNotify = new Dictionary <string, List <Appointment> >();

            foreach (var appointment in newAppointments)
            {
                Console.WriteLine($"Processing notifications for new appointment {appointment.Id}");

                string eventKey    = $"{appointment.Source}";
                var    subscribers = await _subscriptionStore.GetSubscribersAsync(eventKey);

                foreach (var subscriber in subscribers)
                {
                    Collect(subscriber.Email, emailsToNotify, appointment);
                    Collect(subscriber.Phone, phonesToNotify, appointment);
                }
            }

            // Send emails
            foreach (var email in emailsToNotify)
            {
                string reason = string.Join(" ", email.Value.GroupBy(x => x.Source).Select(x => $"Found {x.Count()} appointment{(x.Count() != 1 ? "s" : "")} for {x.Key}."));
                await _notificationStore.LogNotificationAsync(new Subscriber { Email = email.Key }, reason);
            }

            foreach (var phoneToNotify in phonesToNotify)
            {
                // var phoneNumberUtil = PhoneNumbers.PhoneNumberUtil.GetInstance();
                // var number = phoneNumberUtil.Parse(phoneToNotify.Key, "US");
                // if (!phoneNumberUtil.IsValidNumberForRegion(number, "US"))
                // {
                //     Console.WriteLine($"Number {number} is not a valid phone number");
                //     continue;
                // }

                var sb = new StringBuilder();
                sb.Append("VaxAlert found possible appointments!\n\n");
                foreach (var appointment in phoneToNotify.Value)
                {
                    sb.Append($"{appointment.Source}: {appointment.Title}\n");
                }

                sb.Append("\nLink: https://volunteer.covidvaccineseattle.org/VolunteerDashboard.aspx\n");

                sb.Append("\nText STOP to unsubscribe");

                Console.WriteLine($"Sending SMS to {phoneToNotify.Key}");
                await _smsProvider.SendSmsAsync(phoneToNotify.Key, sb.ToString());

                string reason = string.Join(" ", phoneToNotify.Value.GroupBy(x => x.Source).Select(x => $"Found {x.Count()} appointment{(x.Count() != 1 ? "s" : "")} for {x.Key}."));
                await _notificationStore.LogNotificationAsync(new Subscriber { Phone = phoneToNotify.Key }, reason);
            }
        }
Пример #3
0
 public async Task <SMSSendResult> SendSmsAsync(string number, string message)
 {
     return(await _smsProvider.SendSmsAsync(number, message));
 }