private async Task SendMessage(NotifyMessage content, CommunicationType communicationType)
        {
            var notificationsClient = new NotificationClient(_configuration.NotificationServiceApiKey);

            // Needs to be a dictionary<string,dynamic> for the client.....
            var personalisationDictionary = content.Personalisation.ToDictionary(x => x.Key, x => x.Value as dynamic);

            try
            {
                Logger.Info($"Sending communication request to Gov Notify");
                if (communicationType == CommunicationType.Email)
                {
                    var response = await notificationsClient.SendEmailAsync(content.To, content.Template, personalisationDictionary, content.Reference);
                }
                else if (communicationType == CommunicationType.Sms)
                {
                    var response = await notificationsClient.SendSmsAsync(content.To, content.Template, personalisationDictionary, content.Reference);
                }
            }
            catch (NotifyClientException notifyClientException)
            {
                Logger.Error(notifyClientException, $"Error sending communication {communicationType.ToString()} to Gov Notify with Gov.Notify Client");

                if (communicationType != CommunicationType.Sms || !SuppressSmsError(notifyClientException.Message))
                {
                    throw;
                }
            }
            catch (Exception exception)
            {
                Logger.Error(exception, $"Generic Error sending communication {communicationType.ToString()} to Gov Notify");
                throw;
            }
        }
Beispiel #2
0
        public Task SendAsync(SmsMessage message)
        {
            var notifyMessage = new NotifyMessage
            {
                To              = message.RecipientsNumber,
                Template        = message.TemplateId,
                Personalisation = (message.Tokens ?? new Dictionary <string, string>()).ToDictionary(item => item.Key.ToLower(), item => item.Value)
            };

            return(_executionPolicy.ExecuteAsync(() => _httpClientWrapper.SendSms(notifyMessage)));
        }
Beispiel #3
0
        public Task SendAsync(EmailMessage message)
        {
            Logger.Info($"Sending email to {message.RecipientsAddress}");

            var notifyMessage = new NotifyMessage
            {
                To              = message.RecipientsAddress,
                Template        = message.TemplateId,
                Personalisation = (message.Tokens ?? new Dictionary <string, string>()).ToDictionary(item => item.Key.ToLower(), item => item.Value),
                Reference       = message.Reference
            };

            return(_executionPolicy.ExecuteAsync(() => _clientWrapper.SendEmail(notifyMessage)));
        }
 public Task SendSms(NotifyMessage content)
 {
     return(SendMessage(content, CommunicationType.Sms));
 }
 public Task SendEmail(NotifyMessage content)
 {
     return(SendMessage(content, CommunicationType.Email));
 }