public async Task <CommandHandlingResult> Handle(ProcessSmsCommand command, IEventPublisher eventPublisher) { _log.WriteInfo(nameof(ProcessSmsCommand), new { Phone = command.Phone.SanitizePhone() }, "Processing sms"); var phone = command.Phone.GetValidPhone(); if (phone != null) { var phoneUtils = PhoneNumberUtil.GetInstance(); string countryCode = phoneUtils.GetRegionCodeForCountryCode(phone.CountryCode); var provider = await _settingsService.GetProviderByCountryAsync(countryCode); string id = await _smsRepository.AddAsync(new SmsMessage { CountryCode = countryCode, Message = command.Message, Phone = command.Phone, Provider = provider }); eventPublisher.PublishEvent(new SmsProviderProcessed { Phone = command.Phone, Message = command.Message, Provider = provider, CountryCode = countryCode, Id = id }); } return(CommandHandlingResult.Ok()); }
public async Task SendSmsAsync <TModel>(TModel model, Template template, string receiver) { var body = await _templateEngine.RenderTemplateAsync(template.BodyPath, model); var sms = new Sms() { Id = Guid.NewGuid(), Body = body, Phone = receiver, Subject = template.Subject, }; await _smsRepository.AddAsync(sms); await _smsClient.SendAsync(sms); }