/// <summary> /// Send a message syncronously /// </summary> /// <returns>The messages</returns> public IEnumerable <SendResponse> SendMessageSync(long notifierId, string sendingNumber, string message, IEnumerable <string> numbers) { var cleanFailNumber = PhoneNumberHelper.CleanNumber(FailNumber); var statusUrl = _receiver.GetStatusUpdateUrl(notifierId); var incommingUrl = _receiver.GetIncommingUrl(_notifier.Id); var reply = $"Reply:{message}"; var result = new List <SendResponse>(); foreach (var number in numbers) { //TODO: Emulate status updating bool isFailNumber = number == cleanFailNumber; var messageSid = Guid.NewGuid().ToString(); if (!isFailNumber) { var twilioSms = new TwilioSms { MessageSid = messageSid, AccountSid = _notifier.TpAccountSid, From = PhoneNumberHelper.CleanNumber(number), To = PhoneNumberHelper.CleanNumber(sendingNumber), Body = $"TestMode:Reply:{ResponseFromNumber(number)}" }; _replies.Add(twilioSms); } var sendResponse = new SendResponse { Number = number, MessageSid = messageSid, Success = !isFailNumber, Message = isFailNumber ? FailMessage : null }; result.Add(sendResponse); } return(result); }
void HandleUrlForIncomingSms(string accountSid, string authToken, string receivingNumber, PhoneNumberOptions phoneOptions) { if (!receivingNumber.StartsWith(TestSendNumberPrefix)) { var cleanNumber = PhoneNumberHelper.CleanNumber(receivingNumber); var twilioClient = new TwilioRestClient(accountSid, authToken); var numbersRequest = twilioClient.ListIncomingPhoneNumbers(); if (numbersRequest.RestException != null) { throw new TwilioException($"Failed to fetch list of numbers from Twilio: {numbersRequest.RestException.Message}"); } var number = numbersRequest.IncomingPhoneNumbers.FirstOrDefault(n => PhoneNumberHelper.CleanNumber(n.PhoneNumber) == cleanNumber); if (number == null) { throw new ArgumentException("Unable to find matching number", nameof(receivingNumber)); } twilioClient.UpdateIncomingPhoneNumber(number.Sid, phoneOptions); } }