public async Task ShouldReturnSingleMessage() { var messageId = await SendTestMessage(100); FlowrouteClient client = new FlowrouteClient(AccessKey, SecretKey); var response = await client.Messaging.GetMessageDetailsAsync(messageId); Assert.IsTrue(response.Success); Assert.AreEqual(response.Data.Id, messageId); }
public async Task SendMessageAsyncShouldReturn401IfBadPassword() { FlowrouteClient client = new FlowrouteClient(AccessKey, ""); var response = await client.Messaging.SendMessageAsync("17578675309", KnownGoodPhoneNumber, "Test SendMessageAsyncShouldReturn401IfBadPassword"); Assert.IsFalse(response.Success); Assert.IsNotEmpty(response.Errors); Assert.AreEqual(response.Errors.First().Status, 401); }
public async Task SearchShouldReturnResultsWithJustRateCenterAndState() { FlowrouteClient client = new FlowrouteClient(AccessKey, SecretKey); var results = await client.PhoneNumbers.SearchAsync(new FlowroutePhoneNumberSearchCriteria() { RateCenter = "SEATTLE", State = "WA" }); Assert.IsTrue(results.Success); Assert.IsNotEmpty(results.TNS); }
public void SearchShouldThrowExceptionWithJustRateCenter() { Assert.ThrowsAsync <ArgumentOutOfRangeException>(async() => { FlowrouteClient client = new FlowrouteClient(AccessKey, SecretKey); var results = await client.PhoneNumbers.SearchAsync(new FlowroutePhoneNumberSearchCriteria() { RateCenter = "SEATTLE" }); }); }
public async Task SearchShouldReturnResultsWithJustNpa() { FlowrouteClient client = new FlowrouteClient(AccessKey, SecretKey); var results = await client.PhoneNumbers.SearchAsync(new FlowroutePhoneNumberSearchCriteria() { NPA = 757 }); Assert.IsTrue(results.Success); Assert.IsNotEmpty(results.TNS); }
private async Task <string> SendTestMessage(int id) { FlowrouteClient client = new FlowrouteClient(AccessKey, SecretKey); var response = await client.Messaging.SendMessageAsync("17578675309", KnownGoodPhoneNumber, $"TestMessage x{id}"); if (response.Success) { return(response.Data.Id); } throw new Exception("Error sending test message"); }
public async Task SendMessageAsyncShouldReturnSuccessWhenSmsSent() { FlowrouteClient client = new FlowrouteClient(AccessKey, SecretKey); var request = new SmsRequest { ToPhoneNumber = "17578675309", FromPhoneNumber = "17575555555", Body = "TestMessage" }; var response = await client.Messaging.SendMessageAsync("17578675309", KnownGoodPhoneNumber, "Test SendMessageAsyncShouldReturnSuccessWhenSmsSent"); Assert.AreEqual(true, response.Success); }
public async Task ShouldPurchasePhoneNumber() { if (PleaseSpendMoney) { var goodPhoneNumber = "17575555555"; FlowrouteClient client = new FlowrouteClient(AccessKey, SecretKey); var results = await client.PhoneNumbers.PurchasePhoneNumberAsync(goodPhoneNumber); Assert.IsTrue(results.Success); } else { Assert.Inconclusive("You don't want to spend money, so the test did not run"); } }
public async Task ShouldUpdateRoutesOfTelephoneNumber() { var goodPhoneNumber = "17575555555"; FlowrouteClient client = new FlowrouteClient(AccessKey, SecretKey); var results = await client.PhoneNumbers.UpdateTelephoneNumberRoutesAsync(goodPhoneNumber, new FlowrouteRoute() { Name = "Primary1" }, new FlowrouteRoute() { Name = "Primary2" }); Assert.IsTrue(results.Success); }
public async Task ShouldReturnListOfMessages() { var start = DateTimeOffset.UtcNow.DateTime; // send 5 messages var ids = new List <string>(); for (var x = 0; x < 5; x++) { var sendTestMessage = SendTestMessage(x); sendTestMessage.Wait(); ids.Add(sendTestMessage.Result); } FlowrouteClient client = new FlowrouteClient(AccessKey, SecretKey); var response = await client.Messaging.GetMessagesAsync(start, start.AddMinutes(1)); Assert.IsTrue(response.Success); Assert.IsNotEmpty(response.Data); Assert.GreaterOrEqual(5, response.Data.Count()); }
public void Post() { string body = ""; try { using (StreamReader sr = new StreamReader(Request.Body, Encoding.UTF8, true, 1024, true)) body = sr.ReadToEnd(); dynamic mb = JsonConvert.DeserializeObject(body); if (mb.notificationType != null && mb.notificationType == "AmazonSnsSubscriptionSucceeded") { return; } Message msg = Message.ParseMessage(body); if (msg.IsMessageSignatureValid()) { if (msg.IsSubscriptionType) { HttpClient client = new HttpClient(); _ = client.GetAsync(msg.SubscribeURL).Result; return; } if (msg.IsNotificationType) { //dynamic m = JsonConvert.DeserializeObject(msg.MessageText); //dynamic mail = m.mail; dynamic m = JsonConvert.DeserializeObject(msg.MessageText); if (m.notificationType == "Delivery") { return; } byte[] content = Convert.FromBase64String((string)m.content); var message = MimeMessage.Load(new MemoryStream(content)); string smsContent = message.TextBody; string fromAddress = ((MailboxAddress)message.From[0]).Address; var fromPhone = _context.OutgoingRoutes.Where(r => r.Email == fromAddress).Select(r => r.Phone).FirstOrDefault(); if (String.IsNullOrWhiteSpace(fromPhone)) { return; } string toPhone = ((MailboxAddress)message.To[0]).Address; toPhone = toPhone.Substring(0, toPhone.IndexOf("@")); // TODO: Send error message back if toPhone is incorrect format or fromAddress not authorized in lookup table FlowrouteClient client = new FlowrouteClient(Settings.FlowrouteAccessKey, Settings.FlowrouteSecretKey); var result = client.Messaging.SendMessageAsync(Digitize(toPhone), fromPhone, smsContent.Trim()).Result; if (!result.Success) { EmailService.SendEmail(new[] { Settings.ErrorReporting }, Settings.DefaultFrom, "Flowroute API Response", JsonConvert.SerializeObject(result), false); } //EmailService.SendEmail(new[] { Settings.ErrorReporting }, Settings.DefaultFrom, "Email Received", msgBody, false); //EmailService.SendEmail(new[] { Settings.ErrorReporting }, Settings.DefaultFrom, "SMS Content", smsContent.Trim() + " - " + Digitize(toPhone) + " - " + fromAddress + " - " + fromPhone, false); //EmailService.SendEmail(new[] { Settings.ErrorReporting }, Settings.DefaultFrom, "SES Non-Bounce Notification", msgBody, false); } else { EmailService.SendEmail(new[] { Settings.ErrorReporting }, Settings.DefaultFrom, "SES Non-NotificationType", body, false); } } } catch (Exception ex) { EmailService.SendEmail(new[] { Settings.ErrorReporting }, Settings.DefaultFrom, "SES SMS Receipt Error", ExcDetails.Get(ex), false); if (!String.IsNullOrWhiteSpace(body)) { EmailService.SendEmail(new[] { Settings.ErrorReporting }, Settings.DefaultFrom, "SES SMS Receipt Body for Error", body, false); } } }