public async Task SendAsync(Message message) { ILogger logger = _loggerFactory.Create(nameof(Messenger)); logger.Info("Sending message", message); MessageTemplate messageTemplate = _repository .GetAll(mt => mt.Kind == message.MessageTemplateKind && mt.Culture == message.Culture) .SingleOrDefault() ?? throw new AdminException( message: $"No available message template with id {message.MessageTemplateKind} in culture {message.Culture}", reason: AdminExceptionReason.Messaging ) ; string instantiatedBody = _substitutor.Substitute(messageTemplate, message.Parameters); InstantiatedMessage instance = new InstantiatedMessage( messageTemplate.Subject, instantiatedBody ); await _strategy.TransmitAsync(message.Recipient, instance); logger.Info("Message instance successfully sent", instance); }
public Task TransmitAsync(User recipient, InstantiatedMessage instance) { User redirectedRecipient = new User( name: recipient.Name, email: _configuration.Email ?? recipient.Email, phone: _configuration.Phone ?? recipient.Phone, preferredCulture: recipient.PreferredCulture ); return(_proxee.TransmitAsync(redirectedRecipient, instance)); }
public void TestInitialize() { _user = new User( name: "Jesper Gulmann Henriksen", email: "*****@*****.**", phone: "+4522123631", preferredCulture: "da" ); _instance = new InstantiatedMessage( "This is the subject", "This is the body" ); }
async public Task TransmitAsync(User recipient, InstantiatedMessage instance) { TwilioClient.Init(TwilioConstants.AccountSid, TwilioConstants.AuthToken); string contents = string.Format(TwilioConstants.ContentsFormat, instance.Subject.ToUpper(), instance.Body ); MessageResource mr = await MessageResource.CreateAsync( to : new PhoneNumber(recipient.Phone), from : new PhoneNumber(TwilioConstants.FromPhone), body : contents ); }
public async Task TransmitAsync(User recipient, InstantiatedMessage instance) { ISendGridClient client = new SendGridClient(SendGridConstants.ApiKey); EmailAddress from = new EmailAddress( SendGridConstants.FromEmail, SendGridConstants.FromName ); EmailAddress to = new EmailAddress( recipient.Email, recipient.Name ); SendGridMessage emailMessage = MailHelper.CreateSingleEmail( from, to, instance.Subject, instance.Body, null ); await client.SendEmailAsync(emailMessage); }
// Deliberately do nothing! :-) public Task TransmitAsync(User recipient, InstantiatedMessage instance) => Task.CompletedTask;
async public Task TransmitAsync(User recipient, InstantiatedMessage instance) { await Task.WhenAll(_strategies. Select(s => s.TransmitAsync(recipient, instance)) ); }