public TableStorageService(IOptionsMonitor <TableOptions> tableOptionsMonitor, IOptionsMonitor <TwilioOptions> twilioOptionsMonitor, ILogger <TableStorageService> logger)
 {
     _tableOptions  = tableOptionsMonitor.CurrentValue;
     _twilioOptions = twilioOptionsMonitor.CurrentValue;
     _logger        = logger;
     InitializeTableStorage();
 }
Example #2
0
        /// <summary>
        /// Helper function.
        /// </summary>
        private static void ValidateOptions(TwilioOptions opt)
        {
            // Perform some startup validation
            if (string.IsNullOrWhiteSpace(opt?.AccountSid))
            {
                throw new InvalidOperationException(
                          $"SMS is enabled, therefore a Twilio Account Sid must be in a configuration provider under the key '{TwilioSectionName}:{nameof(TwilioOptions.AccountSid)}'");
            }

            if (string.IsNullOrWhiteSpace(opt?.AuthToken))
            {
                throw new InvalidOperationException(
                          $"SMS is enabled, therefore a Twilio Auth Token must be in a configuration provider under the key '{TwilioSectionName}:{nameof(TwilioOptions.AuthToken)}'");
            }

            if (string.IsNullOrWhiteSpace(opt?.Sms?.ServiceSid))
            {
                throw new InvalidOperationException(
                          $"SMS is enabled, therefore a Twilio Messaging Service Sid must be in a configuration provider under the key '{SmsSectionName}:{nameof(TwilioSmsOptions.ServiceSid)}'");
            }

            bool webhooksEnabled = opt?.Sms?.CallbacksEnabled ?? false;

            if (webhooksEnabled)
            {
                if (string.IsNullOrWhiteSpace(opt?.Sms?.CallbackHost))
                {
                    throw new InvalidOperationException(
                              $"{SmsSectionName}:{nameof(TwilioSmsOptions.CallbacksEnabled)} = true, therefore the host name of the system must be in a configuration provider under the key '{SmsSectionName}:{nameof(TwilioSmsOptions.CallbackHost)}'");
                }
            }
        }
 public TwilioService(
     IOptions <TwilioOptions> twilioConfiguration,
     ILogger <TwilioService> logger)
 {
     _logger = logger;
     _twilioCenterConfiguration = twilioConfiguration.Value;
     TwilioClient.Init(_twilioCenterConfiguration.AccountSid, _twilioCenterConfiguration.AuthToken);
 }
Example #4
0
 /// <summary>
 /// Service to deliver SMS messages
 /// </summary>
 public SmsService(ILoggerFactory loggerFactory, IOptions <TwilioOptions> twilioConfig, IOptions <JwtIssuerOptions> jwt)
 {
     _jwt          = jwt.Value;
     _twilioConfig = twilioConfig.Value;
     _logger       = loggerFactory.CreateLogger <DAO>();
     //setup the config items to send messages
     _accountSid    = twilioConfig.Value.AccountSid;
     _authToken     = twilioConfig.Value.AuthToken;
     _msgServiceSid = twilioConfig.Value.MsgServiceSid;
 }
Example #5
0
 public PublishersController(
     ILogger <PublishersController> log,
     IOptions <TwilioOptions> opts,
     IDataSource db,
     PgresUser creds
     )
 {
     _db     = db;
     _creds  = creds;
     _log    = log;
     _twilio = opts.Value;
 }
Example #6
0
        private SmsService GetSmsService(string fromPhoneNumber = null, string accountSid = null, string authToken = null)
        {
            TwilioClient.Init(accountSid ?? _fixture.Configuration["Twilio:AccountSid"], authToken ?? _fixture.Configuration["Twilio:AuthToken"]);

            var twilioOptions = new TwilioOptions
            {
                FromPhoneNumber          = fromPhoneNumber ?? _fixture.Configuration["Identity:TwilioOptions:FromPhoneNumber"],
                TwoFactorTokenBodyFormat = _fixture.Configuration["Identity:TwilioOptions:TwoFactorTokenBodyFormat"]
            };

            return(new SmsService(new OptionsWrapper <TwilioOptions>(twilioOptions)));
        }
Example #7
0
        public void Constructor_WithInvalidClient_ShouldThrow()
        {
            var options = Substitute.For <IOptions <TwilioOptions> >();
            var config  = new TwilioOptions();

            options.Value.Returns(config);

            var actual = Assert.Throws <ArgumentNullException>(() => new TwilioSmsService(options, null));

            Assert.NotNull(actual);
            Assert.Equal("httpClient", actual.ParamName);
        }
Example #8
0
        public void Constructor_WithValidArguments_ShouldConstruct()
        {
            var client  = Substitute.For <HttpClient>();
            var options = Substitute.For <IOptions <TwilioOptions> >();
            var config  = new TwilioOptions();

            options.Value.Returns(config);

            var actual = new TwilioSmsService(options, client);

            Assert.NotNull(actual);
        }
        public VerificationController(IHttpClientFactory clientFactory, IOptions <TwilioOptions> twilioOptions)
        {
            var options = twilioOptions.Value;

            if (string.IsNullOrEmpty(options.VerifyServiceSid))
            {
                throw new ArgumentException(nameof(options.VerifyServiceSid));
            }

            _clientFactory = clientFactory;
            _options       = options;
        }
Example #10
0
 /// <summary>
 /// Initialite the client.
 /// </summary>
 /// <param name="config">Twilio platform configuration.</param>
 /// <param name="httpClient">Http client.</param>
 public TwilioSmsService(IOptions <TwilioOptions> config, System.Net.Http.HttpClient httpClient)
 {
     _options = config
                .ThrowIfNull(nameof(config))
                .Value
                .ThrowIfNull(nameof(config.Value));
     _client = new TwilioRestClient(
         _options.AccountSID,
         _options.AuthToken,
         region: _options.Region,
         httpClient: new SystemNetHttpClient(httpClient.ThrowIfNull(nameof(httpClient)))
         );
 }
Example #11
0
        public TextMessagingService(
            IOptions <TwilioOptions> twilioOptions,
            ILogger <TextMessagingService> logger)
        {
            _options = twilioOptions?.Value ?? throw new ArgumentNullException(nameof(twilioOptions));
            _logger  = logger ?? throw new ArgumentNullException(nameof(logger));

            var accountId = Environment.GetEnvironmentVariable(_options.AccountIdKey)
                            ?? throw new ApplicationException($"Misconfigured environment variable. Missing {_options.AccountIdKey} value.");

            var authToken = Environment.GetEnvironmentVariable(_options.AuthTokenKey)
                            ?? throw new ApplicationException($"Misconfigured environment variable. Missing {_options.AuthTokenKey} value.");

            TwilioClient.Init(accountId, authToken);
        }
Example #12
0
        public async Task SendAndWaitForResponseAsync_WithValidParams_ShouldSendAndReceiveSms()
        {
            // Setup
            var options = Substitute.For <IOptions <TwilioOptions> >();
            var config  = new TwilioOptions
            {
                AccountSID = "xxx",
                AuthToken  = "yyy",
                Region     = "Middle East & Africa"
            };

            options.Value.Returns(config);

            var communicator = new TwilioSmsService(options, new HttpClient());
            var request      = new SmsRequest
            {
                From        = "+12019847676",
                Destination = "+27718690000",
                Message     = "Test message"
            };

            // Perform
            await communicator.SendAndWaitForResponseAsync(request, CancellationToken.None);
        }
Example #13
0
 public TextMessageHandler(IOptions <TwilioOptions> twilioOptions)
 {
     _twilioOptions = twilioOptions.Value;
 }
Example #14
0
 public Messager(IOptions <TwilioOptions> options, IJokeService jokeService)
 {
     _twilioOptions = options.Value;
     _jokeService   = jokeService ?? throw new ArgumentNullException(nameof(jokeService));
 }
Example #15
0
 public SmsSender(IOptions <TwilioOptions> options)
 {
     _twilioOptions = options.Value;
 }
 public static IServiceCollection AddTwilioSmsNotification(this IServiceCollection services, TwilioOptions options)
 {
     services.AddSingleton <ISmsNotification>(new TwilioSmsNotification(options));
     return(services);
 }
Example #17
0
 public TwilioOptionsTests()
 {
     _twilioOptions = new TwilioOptions();
 }
Example #18
0
 public SmsService(IOptions <TwilioOptions> options)
 {
     _config = options.Value;
 }
        public VerificationController(IOptions <TwilioOptions> twilioOptions)
        {
            var options = twilioOptions.Value;

            _options = options;
        }
Example #20
0
 public TwilioService(IOptionsMonitor <TwilioOptions> optionsMonitor)
 {
     _twilioOptions = optionsMonitor.CurrentValue;
     //Connect to Twilio
     TwilioClient.Init(_twilioOptions.AccountSid, _twilioOptions.AuthToken);
 }