public async Task <Response> SendNotification(Notification notification) { if (notificationProperties.isWhiteListed(notification?.Communication?.Value)) { return(new Response(ResponseType.Success, "Notification sent")); } return(notification.Action switch { Action.ConsentRequestCreated => await smsClient.Send( notification.Communication.Value, GenerateConsentRequestMessage(notification.Content)), Action.ConsentManagerIdRecovered => await smsClient.Send( notification.Communication.Value, GenerateConsentManagerIdRecoveredMessage(notification.Content)), _ => new Response(ResponseType.InternalServerError, "") });
public async Task <Unit> Handle(InviteeCreatedCommand request, CancellationToken cancellationToken) { //Build message and destination //Note, the "?." syntax protects against NullReferenceExceptions, but //could result in a message with blank names if the request did truly //come in with an empty name var invitee = request?.RequestData?.payload?.invitee; var to = _config["PhoneNumber"]; //Comes from secrets //We shouldn't get a message without first_name and last_name, but just in case string message; if (!String.IsNullOrEmpty(invitee?.first_name) && !String.IsNullOrEmpty(invitee?.last_name)) { message = $"New meeting scheduled with {invitee?.first_name} {invitee?.last_name}!"; } else { message = $"New meeting scheduled! View your calendar for details."; } //Send _logger.LogInformation("Sending message"); await _smsClient.Send(to, message); _logger.LogInformation("Message sent"); return(await Unit.Task); }
private void SendAlert(ColdSpellEnteredNotification message) { var enteredAtLocal = _timeZone.ToLocalTime(message.EnteredAt); _smsClient.Send(_configuration.SmsFrom, _configuration.SmsTo, string.Format( "{0}: Entered cold spell. (Temp: {1}C).", enteredAtLocal.ToString("HH:mm"), message.CurrentTemp.ToString("f1"))); Trace.TraceInformation("{0}: INFO: Sent SMS for ColdSpellEnteredNotification.", message.DeviceId); }
public async Task <Response> GenerateOtp(OtpGenerationRequest otpGenerationRequest) { var otp = otpGenerator.GenerateOtp(); var generateMessage = GenerateMessage(otpGenerationRequest.GenerationDetail, otp); var sendOtp = await smsClient.Send(otpGenerationRequest.Communication.Value, generateMessage, otpGenerationRequest.GenerationDetail.GetTemplateID()); if (sendOtp.ResponseType == ResponseType.Success) { return(await otpRepository.Save(otp, otpGenerationRequest.SessionId)); } return(sendOtp); }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { try { var lowData = ""; while (!stoppingToken.IsCancellationRequested) { var cl = new GraphQLHttpClient(_configOptions.Value.GraphUrl, new NewtonsoftJsonSerializer()); cl.HttpClient.DefaultRequestHeaders.Add("simcontrol-api-key", _configOptions.Value.ApiKey); foreach (string contactNumber in _configOptions.Value.ContactNumbers) { var content = new GraphQLRequest(string.Format(queryList[0], contactNumber)); var res = await cl.SendQueryAsync <Data>(content); if (res.Data.Sims.Edges.Any()) { var data = res.Data.Sims.Edges.First().Node; _logger.LogInformation("\r\n\r\n\r\n"); _logger.LogInformation("\t\tDescription : " + data.Description); _logger.LogInformation("\t\tNumber : " + data.ContactNumber); _logger.LogInformation("\t\tActive: " + data.Active); _logger.LogInformation("\t\tAirtime Balance : " + data.AirtimeBalance); _logger.LogInformation("\t\tData Balance: " + data.DataBalanceInMb); if (data.DataBalanceInMb == null || long.Parse(_configOptions.Value.MinimumLimit) > data.DataBalanceInMb) { lowData += string.Format("{0} - {1} - {2}Mb\r\n", data.ContactNumber, data.Description, data.DataBalanceInMb); } } } cl.Dispose(); if (lowData.Length > 1) { var mm = new Message(_emailOptions.Value.AdministratorEmails, "Sim Control - Low Data Report", "The following users has low data : \r\n" + lowData); _emailClient.SendEmail(mm); _logger.LogInformation("\t\tSending SMS..."); _smsClient.Send("You have a few low data items"); } _logger.LogInformation("Next check will be at " + DateTime.Now.AddMilliseconds(_configOptions.Value.Delay)); await Task.Delay(_configOptions.Value.Delay, stoppingToken); } } catch (Exception ex) { _logger.LogError(ex.Message, ex); } }
public Task HandleAsync(ColdSpellLeftNotification message) { Trace.TraceInformation("{0}: HANDLE: {1} {{Temp: {2}, LeftAt: {3}, Duration: {4}}}.", message.DeviceId, message.GetType().Name, message.CurrentTemp, message.LeftAt, message.Duration); var leftAtLocal = _timeZone.ToLocalTime(message.LeftAt); _smsClient.Send( _configuration.SmsFrom, _configuration.SmsTo, string.Format("{0}: Cold spell over. (Temp: {1}C, Min: {2}C, Duration: {3}).", leftAtLocal.ToString("HH:mm"), message.CurrentTemp.ToString("f1"), message.MinTemp.ToString("f1"), message.Duration.ToString(@"h\h\ m\m"))); Trace.TraceInformation("{0}: INFO: Sent SMS for ColdSpellLeftNotification.", message.DeviceId); return(Task.FromResult(0)); }