internal static TwilioSmsConfiguration CreateConfiguration(JObject metadata) { var twilioConfig = new TwilioSmsConfiguration(); JObject configSection = (JObject)metadata.GetValue("twilioSMS", StringComparison.OrdinalIgnoreCase); JToken value = null; if (configSection != null) { if (configSection.TryGetValue("from", StringComparison.OrdinalIgnoreCase, out value)) { twilioConfig.From = value.ToString(); } if (configSection.TryGetValue("to", StringComparison.OrdinalIgnoreCase, out value)) { twilioConfig.To = value.ToString(); } if (configSection.TryGetValue("body", StringComparison.OrdinalIgnoreCase, out value)) { twilioConfig.Body = value.ToString(); } } return(twilioConfig); }
public TwilioHttpClient(TwilioSmsConfiguration twilioSmsConfiguration) { _innerClient = new TwilioRestClient( twilioSmsConfiguration.AccountSid, twilioSmsConfiguration.AuthToken, httpClient: new SystemNetHttpClient(new System.Net.Http.HttpClient())); }
public async Task SendSmsWithoutParametersShouldThrowException() { ISmsNotification emptySmsNotification = null; var source = new Mock <ISmsSender>(); TwilioSmsConfiguration emptyConfig = new TwilioSmsConfiguration(); var mockSmsService = new SmsNotificationService(source.Object); await Assert.ThrowsAsync <ArgumentNullException>(() => mockSmsService.SendAsync(emptySmsNotification)); }
/// <summary> /// Enables use of the Twilio extensions /// </summary> /// <param name="config">The <see cref="JobHostConfiguration"/> to configure.</param> /// <param name="twilioSmsConfig">The <see cref="TwilioSmsConfiguration"/> to use.</param> public static void UseTwilioSms(this JobHostConfiguration config, TwilioSmsConfiguration twilioSmsConfig = null) { if (config == null) { throw new ArgumentNullException("config"); } if (twilioSmsConfig == null) { twilioSmsConfig = new TwilioSmsConfiguration(); } config.RegisterExtensionConfigProvider(twilioSmsConfig); }
public static void CreateMessageOptions_ReturnsExpectedResult_Simple() { JObject options = new JObject { { "to", "+12223334444" }, { "from", "+12223334444" }, { "body", "Knock knock." } }; var result = TwilioSmsConfiguration.CreateMessageOptions(options); Assert.Equal(options["to"], result.To.ToString()); Assert.Equal(options["from"], result.From.ToString()); Assert.Equal(options["body"], result.Body.ToString()); }
public SmsNotificationServiceTestConfiguration() { var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddEnvironmentVariables(); var config = builder.Build(); Configuration = new TwilioSmsConfiguration { AccountSid = config[TwilioSmsConfigurationSettings.AccountSid], AuthToken = config[TwilioSmsConfigurationSettings.AuthToken], FromNumber = config[TwilioSmsConfigurationSettings.FromNumber] }; RecipientPhoneNumber = config[TwilioSmsConfigurationSettings.RecipientTestPhoneNumber]; TwilioRestClient = new TwilioHttpClient(Configuration); }
public static void CreateMessageOptions_ReturnsExpectedResult_Full() { JObject options = new JObject { { "to", "+14254570421" }, { "from", "+14254570422" }, { "body", "Knock knock." }, { "forceDelivery", true }, { "maxRate", 123 }, { "validityPeriod", 123 }, { "provideFeedback", true }, { "maxPrice", 0.55 }, { "applicationSid", "aaaa" }, { "statusCallback", "http://aaa" }, { "messagingServiceSid", "bbbb" }, { "pathAccountSid", "ccc" }, { "mediaUrl", new JArray { "http://aaa", "http://bbb" } } }; var result = TwilioSmsConfiguration.CreateMessageOptions(options); Assert.Equal(options["to"], result.To.ToString()); Assert.Equal(options["from"], result.From.ToString()); Assert.Equal(options["body"], result.Body.ToString()); Assert.Equal(options["forceDelivery"], result.ForceDelivery); Assert.Equal(options["maxRate"], result.MaxRate); Assert.Equal(options["validityPeriod"], result.ValidityPeriod); Assert.Equal(options["provideFeedback"], result.ProvideFeedback); Assert.Equal(options["maxPrice"], result.MaxPrice); Assert.Equal(options["applicationSid"], result.ApplicationSid); Assert.Equal(new Uri((string)options["statusCallback"]), result.StatusCallback); Assert.Equal(new Uri((string)options["statusCallback"]), result.StatusCallback); Assert.Equal(options["messagingServiceSid"], result.MessagingServiceSid); Assert.Equal(options["pathAccountSid"], result.PathAccountSid); Assert.Equal(new Uri((string)options["mediaUrl"][0]), result.MediaUrl[0]); Assert.Equal(new Uri((string)options["mediaUrl"][1]), result.MediaUrl[1]); }
public TwilioSmsSender(TwilioSmsConfiguration twilioSmsConfiguration, ITwilioRestClient twilioRestClient) { _twilioSmsConfiguration = twilioSmsConfiguration; _twilioRestClient = twilioRestClient; }
public TwilioSms(TwilioSmsConfiguration smsConfiguration) { SmsConfiguration = smsConfiguration; }