public async Task <SmsDto> PostSms(SmsDto model) { var url = CRMApiUri + "/Sms"; var result = await PostRequestToApi(url, model); return(result); }
public IHttpActionResult SendSmsMessageForVehicles(SmsVehicleModel model) { if (String.IsNullOrEmpty(model.Text)) { return(Ok("Enter SMS text, please.")); } if (model.Vehicles.Count() <= 0) { return(Ok("Choose vehicles, please.")); } var phones = model.Vehicles.Select(x => x.PhoneNumber).Distinct(); //var phones = String.Join(",", phoneNumbers); if (phones.Count() > 0) { var data = new SmsDto { Text = model.Text, Phones = phones.ToList() }; _service.SendSms(data); } return(Ok()); }
public async Task <SmsDto> PutSms(int id, SmsDto model) { var url = CRMApiUri + "/Sms/" + id; var result = await PutRequestToApi(url, model); return(result); }
public void SendSms(SmsDto model) { try { SMSC smsc = new SMSC(); var senderSMSLimit = Configuration.SendSMSLimit; var totalSends = model.Phones.Count() / senderSMSLimit; for (int i = 0; i <= totalSends; i++) { var phonesForSend = model.Phones.Skip(i * senderSMSLimit).Take(senderSMSLimit); var phonesForSendString = String.Join(",", phonesForSend); if (!String.IsNullOrEmpty(phonesForSendString)) { #if !DEBUG smsc.send_sms(phonesForSendString, model.Text, sender: Configuration.SmsSender); #endif } } } catch (Exception e) { throw e; } }
public async Task <BaseEntity> SaveAndReturnEntityAsync(SmsDto entityDto) { var smsDb = _mapper.Map <Sms>(entityDto); var result = await _repository.SaveAndReturnEntityAsync(smsDb); return(result); }
public SmsDto SendSms(string toPhoneNumber, string messageBody) { string preparedNumber; TwilioClient.Init(accountSid, authToken); if (toPhoneNumber.StartsWith("+1")) { preparedNumber = toPhoneNumber; } else { preparedNumber = "+1" + toPhoneNumber; } var to = new PhoneNumber(preparedNumber); var message = MessageResource.Create( to, from: new PhoneNumber($"+1{fromNumber}"), body: messageBody); SmsDto smsDto = new SmsDto(); smsDto.DateCreated = DateTime.Now; smsDto.ToPhoneNumber = $"+1{toPhoneNumber}"; smsDto.FromPhoneNumber = $"+1{fromNumber}"; smsDto.MessageBody = messageBody; smsDto.Sid = message.Sid; return(smsDto); }
public static Sms Map(SmsDto dto) { return(new Sms { NumberOfSms = dto.NumberOfSms, FeePerSms = dto.FeePerSms, }); }
private static async Task <Result> SendAsync(SmsDto dto) { var userInfo = new UserInfoDto(dto.Options.UserName, dto.Options.Password); var loginResult = await LoginAsync(userInfo); if (!loginResult.Status) { return(new ErrorResult(loginResult.Error)); } //var phones = dto.Phones.Select(item => item.ToPhone()).Where(phone => phone != "").ToList(); var phones = dto.Phones.Select(item => item).Where(phone => phone != "").ToList(); var smsData = new SmsDataDto { IsTurkish = true, User = userInfo, Title = dto.Options.Title }; smsData.Messages.Add(new MessageDataDto(dto.Message, phones)); var data = $"data={smsData.ToJson().ToBase64String()}"; var request = (HttpWebRequest)WebRequest.Create("http://api.mesajpaneli.com/json_api/"); ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); }; request.Method = "post"; request.ContentType = "application/x-www-form-urlencoded"; try { await using (var stream = request.GetRequestStream()) { await using var writer = new StreamWriter(stream); await writer.WriteAsync(data); } using (var response = request.GetResponse() as HttpWebResponse) { if (response == null) { return(new ErrorResult("Response null")); } var read = await new StreamReader(response.GetResponseStream(), Encoding.UTF8).ReadToEndAsync(); var result = read.FromBase64String().FromJson <SmsResponse>(); if (!result.Status) { return(new ErrorResult(result.Error)); } return(new SuccessResult()); } } catch (Exception e) { return(new ErrorResult(e.Message)); } }
public async Task <IActionResult> Put(int id, [FromBody] SmsDto smsDto) { if (id == 0 || smsDto.Id == 0) { return(StatusCode(StatusCodes.Status400BadRequest, "Id needs to be greater than 0.")); } return(await SaveAndReturnEntityAsync(async() => await _smsService.SaveAndReturnEntityAsync(smsDto))); }
public async Task <IActionResult> Post([FromBody] SmsDto smsDto) { if (smsDto.Id != 0) { return(StatusCode(StatusCodes.Status400BadRequest, "Identity insert is not permitted.")); } return(await SaveAndReturnEntityAsync(async() => await _smsService.SaveAndReturnEntityAsync(smsDto))); }
private bool IsCompletionResponse(SmsDto sms) { if (sms.MessageBody.Trim().ToLower() == "done") { return(true); } return(false); }
private bool IsRejectionResponse(SmsDto sms) { if (sms.MessageBody.Trim().ToLower() == "n" || sms.MessageBody.Trim().ToLower() == "no") { return(true); } return(false); }
private bool IsAcceptanceResponse(SmsDto sms) { if (sms.MessageBody.Trim().ToLower() == "y" || sms.MessageBody.Trim().ToLower() == "yes") { return(true); } return(false); }
/// <inheritdoc/> public async Task SendAsync(NotificationContentRequestModel notificationContentRequestModel) { var model = notificationContentRequestModel as SmsRequestModel; var queueName = _configurationHelper.SmsQueueName(); var smsDto = new SmsDto { To = model.To, Body = model.Content }; await _serviceBusHelper.SendMessageToQueueAsync(smsDto, queueName); }
public async Task <Result> SendSmsAsync(SmsDto dto) { try { return(await SendAsync(dto)); } catch (Exception e) { return(new ErrorResult(e.Message)); } }
private void UnIdentifiedResponse(SmsDto smsResponse, SmsDto lastSmsSent = null) { string message = $"Uncertain how to execute your objective."; _sms.SendSms(smsResponse.FromPhoneNumber, message); //RESEND THE INITAL PROMPT SMS if (lastSmsSent != null) { _sms.SendSms(smsResponse.FromPhoneNumber, lastSmsSent.MessageBody); } //SHOULD IT BE ADDED TO THE OUTBOUND MESSAGES? }
//public void Process(SmsDto incomingSmsDto) //{ // if (CheckIfTheyreValidUser(incomingSmsDto)) // return; // Isfinished(incomingSmsDto); //} private bool Isfinished(SmsDto incomingSmsDto) { if (incomingSmsDto.MessageBody.ToLower().Contains("finished")) { _smsService.SendSms(incomingSmsDto.FromPhoneNumber, "Thank you, you'll now be set back as available for others" + "to request your help."); //Set the person from the incomingSmsDto back to isAvailable = true return(true); } else { return(false); } }
public async Task <IActionResult> Sms(SmsDto sms) { string clientId = _config.GetValue <string>("Sms:ClientId"); string clientSecret = _config.GetValue <string>("Sms:ClientSecret"); StringBuilder builder = new StringBuilder(); builder.Append("You have been registered on the Donor Trace Mobile App"); var host = new ApiHost(new BasicAuth(clientId, clientSecret)); var messageApi = new MessagingApi(host); MessageResponse msg = messageApi.SendQuickMessage("Donor Trace", sms.To, builder.ToString(), false); return(Ok(msg.Status)); }
public async Task OnGetAsync(long?id) { Templets = await _templetService.GetListAsync(new SmsTempletSearch { IsDeleted = false }, null); if (id.HasValue) { Dto = await _service.GetByIdAsync(id.Value); if (Dto == null) { throw new KuDataNotFoundException(); } ViewData["Mode"] = "Edit"; } else { Dto = new SmsDto(); ViewData["Mode"] = "Add"; } }
public async Task <IActionResult> SendSms(string userId, int actionId) { var user = _userRepository.GetUserById(userId); var action = _rescuersService.GetActionById(actionId); if (user.Sms != null) { var content = new SmsDto { message = "HGSS: Please respond if you are available for action: " + action.Naziv + " in " + action.NazivLokacije, phone = user.Sms }; var httpContent = new StringContent(JsonConvert.SerializeObject(content), Encoding.UTF8, "application/json"); var result = await new HttpClient().PostAsync("https://textbelt.com/text", httpContent); return(Ok(result)); } return(BadRequest(ErrorMessageCreator.GenerateErrorMessage(ErrorType.ValidationError, "User has no sms"))); }
public void Index(SmsRequest request, string To, string From, string Body) { var smsDto = new SmsDto(); smsDto.Sid = request.SmsSid; smsDto.DateCreated = DateTime.Now; smsDto.ToPhoneNumber = To; smsDto.FromPhoneNumber = From; smsDto.MessageBody = Body; //smsDto.DateCreated = DateTime.Now; //smsDto.MessageBody = Body; ////smsDto.Sid = request.SmsSid; //smsDto.ToPhoneNumber = "+12065086735"; //smsDto.FromPhoneNumber = From; var Db = MvcApplication.DbRepo; Db.Add <SmsDto>(smsDto); SmsRoutingConductor.InboundMessages.Enqueue(smsDto); }
public async Task <int> Send(SmsDto dto) { int statusCode = 400; try { string url = $"{_credential.ApiUrl}?Username={_credential.Username}&Password={_credential.Password}&From={_credential.From}&To=88{dto.MobileNumber}&Message={dto.Message}"; using (var response = await HttpHelper.SendRequest(HttpMethod.Get, url)) { var result = await response.Content.ReadAsStringAsync(); if (response.IsSuccessStatusCode) { var serializer = new XmlSerializer(typeof(ArrayOfServiceClass)); using (TextReader reader = new StringReader(result)) { var res = (ArrayOfServiceClass)serializer.Deserialize(reader); if (res.ServiceClass.StatusText == "success") { statusCode = 200; } string json = JsonConvert.SerializeObject(res); await _repository.Insert(dto.MobileNumber, dto.Message, (int)response.StatusCode, dto.AppId, responseJson : json); } } else { await _repository.Insert(dto.MobileNumber, dto.Message, (int)response.StatusCode, dto.AppId, result); } } } catch (Exception ex) { await _repository.Insert(dto.MobileNumber, dto.Message, statusCode, dto.AppId, ex.ToString()); } return(await Task.FromResult(statusCode)); }
public async Task SendAsync(SmsDto sms) { try { var messageResponse = await MessageResource.CreateAsync(new CreateMessageOptions(sms.RecipientPhoneNumber) { Body = sms.Text, From = _twilioSmsConfiguration.FromNumber }, _twilioRestClient); if (messageResponse.Status == MessageResource.StatusEnum.Failed || messageResponse.Status == MessageResource.StatusEnum.Undelivered) { var errors = new Dictionary <string, dynamic> { { "messageResponse", messageResponse } }; throw new SmsSenderException(string.Format(ErrorWhileSendingSmsTo, sms.RecipientPhoneNumber), errors); } } catch (System.Exception e) when(!(e is SmsSenderException)) { throw new SmsSenderException(string.Format(ErrorWhileSendingSmsTo, sms.RecipientPhoneNumber), e); } }
public ActionResult Update(SmsDto dto) { var data = _SmsContract.Update(dto); return(Json(data)); }
public async Task <IActionResult> Post([FromBody] SmsDto dto) { var response = await _service.Send(dto); return(StatusCode(response)); }
private void ResponseProcessedConfirmation(SmsDto sms) { string message = $"Response confirmed."; _sms.SendSms(sms.FromPhoneNumber, message); }
public async Task <SmsDto> PutSms(int id, SmsDto model) { return(await _smsApiClient.PutSms(id, model)); }
public async Task <SmsDto> PostSms(SmsDto model) { return(await _smsApiClient.PostSms(model)); }
public async Task <IActionResult> DoAdd(SmsDto model) { await _service.AddAsync(model); return(JsonData(true)); }
public async Task <int> SaveAsync(SmsDto sms) { var result = await SaveAndReturnEntityAsync(sms); return(result.Id); }