/// <summary> /// Handles the specified request. /// </summary> /// <param name="command">The request.</param> public async void Handle(CustomerSendVerificationSmsCommand command) { string verificationWord = StringUtils.GenerateRandomEnglishString(); TwilioSendSmsCommand sendSmsCommand = CreateSendSmsCommand(command, verificationWord); InfoAccumulator info = new InfoAccumulator(); try { var response = await TwilioSmsAsyncSendReceive.SendAsync(Config.Address, sendSmsCommand); if (response.Sms != null) { response.Sms.UserId = int.Parse(EncryptionUtils.SafeDecrypt(command.CustomerId)); MobilePhoneQueries.SaveTwilioSms(response.Sms); } else { info.AddError("error sending sms"); } SendReply(info, command); } catch (TaskCanceledException ex) { Log.Error("Time out on sending sms"); info.AddError("Time out sending sms"); SendReply(info, command); } }
/// <summary> /// Creates the send SMS command. /// </summary> /// <param name="request">The request.</param> /// <param name="verificationWord">The verification word.</param> /// <returns></returns> private TwilioSendSmsCommand CreateSendSmsCommand(CustomerSendVerificationSmsCommand request, string verificationWord) { TwilioSendSmsCommand sendSmsCommand = new TwilioSendSmsCommand(); StringBuilder msgBuilder = new StringBuilder(); if (!string.IsNullOrEmpty(request.MessageHeader)) { msgBuilder.Append(request.MessageHeader); msgBuilder.AppendLine(); } else { msgBuilder.Append("Your verification code is: "); msgBuilder.AppendLine(); } msgBuilder.Append(verificationWord); if (!string.IsNullOrEmpty(request.MessageFooter)) { msgBuilder.AppendLine(); msgBuilder.Append(request.MessageFooter); } sendSmsCommand.Message = msgBuilder.ToString(); sendSmsCommand.PhoneNumber = request.PhoneNumber; return(sendSmsCommand); }
/// <summary> /// Handles the specified command. /// </summary> /// <param name="command">The command.</param> public async void Handle(TwilioSendSmsCommand command) { InfoAccumulator info = new InfoAccumulator(); TwilioSms sms = null; if (string.IsNullOrEmpty(command.Message) || string.IsNullOrEmpty(command.PhoneNumber)) { info.AddError("got empty message or phone number"); } else { Message response = await Twilio.SendSms(command.PhoneNumber, command.Message); if (response == null) { info.AddError("error in sending sms"); } else { sms = GetTwilioSms(response); } } SendReply(info, command, resp => resp.Sms = sms); }