public async Task TryResendAsync() { var smses = await _smsRepository.GetPendingOrFailedSmsesAsync(); foreach (var sms in smses) { await _smsClient.SendAsync(sms); } }
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); }
public async Task Consume(ConsumeContext <ISendSmsRequestReceived> context) { await _smsLogRepository.LogAsync(SmsLog.CreateUsageLog(context.Message)); var smsList = context.Message.SmsMessages.Select(s => new Sms(context.Message, s)); await StoreAsync(smsList); foreach (var message in smsList) { try { await _smsClient.SendAsync(message); } catch (Exception ex) { _logger.LogError(ex, "Error while sending sms"); await UpdateSmsStatusAsync(ex, message); await PublishSmsRequestFailedEventAsync(context, message, ex); } } }
public async Task Consume(ConsumeContext <ISendSmsRequestReceived> context) { var smsList = ToSmsList(context); await StoreAsync(smsList); foreach (var message in smsList) { try { var smsBody = await _smsClient.SendAsync(message); if (context.Message.UserId != default) { await _webApiClient.DeductSmsCreditsAsync(context.Message.UserId, smsBody); } } catch (Exception ex) { _logger.LogError(ex, "Error while sending sms"); await PublishSmsRequestFailedEventAsync(context, message, ex); } } }