Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TwilioAdapter"/> class.
        /// </summary>
        /// <param name="options">The options to use to authenticate the bot with the Twilio service.</param>
        /// <param name="twilioClient">The Twilio client to connect to.</param>
        /// <exception cref="ArgumentNullException"><paramref name="options"/> is <c>null</c>.</exception>
        public TwilioAdapter(TwilioAdapterOptions options, TwilioClientWrapper twilioClient)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (string.IsNullOrWhiteSpace(options.TwilioNumber))
            {
                throw new ArgumentException("TwilioNumber is a required part of the configuration.", nameof(options));
            }

            if (string.IsNullOrWhiteSpace(options.AccountSid))
            {
                throw new ArgumentException("AccountSid is a required part of the configuration.", nameof(options));
            }

            if (string.IsNullOrWhiteSpace(options.AuthToken))
            {
                throw new ArgumentException("AuthToken is a required part of the configuration.", nameof(options));
            }

            _twilioClient = twilioClient ?? throw new ArgumentNullException(nameof(twilioClient));
            _options      = options;

            _twilioClient.LogIn(_options.AccountSid, _options.AuthToken);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TwilioAdapter"/> class.
 /// </summary>
 /// <param name="configuration">Configuration.</param>
 /// <param name="twilioClient">The Twilio client to connect to.</param>
 /// <param name="adapterOptions">Options for the <see cref="TwilioAdapter"/>.</param>
 /// <param name="logger">The ILogger implementation this adapter should use.</param>
 public TwilioAdapter(IConfiguration configuration, TwilioClientWrapper twilioClient, TwilioAdapterOptions adapterOptions, ILogger logger = null)
     : base(new ConfigurationCredentialProvider(configuration))
 {
     _configuration = configuration;
     _twilioClient  = twilioClient ?? throw new ArgumentNullException(nameof(twilioClient));
     _logger        = logger ?? NullLogger.Instance;
     _options       = adapterOptions ?? new TwilioAdapterOptions();
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TwilioClientWrapper"/> class.
        /// </summary>
        /// <param name="options">An object containing API credentials, a webhook verification token and other options.</param>
        public TwilioClientWrapper(TwilioAdapterOptions options)
        {
            Options = options ?? throw new ArgumentNullException(nameof(options));

            if (string.IsNullOrWhiteSpace(options.TwilioNumber))
            {
                throw new ArgumentException(nameof(options.TwilioNumber));
            }

            if (string.IsNullOrWhiteSpace(options.TwilioAccountSid))
            {
                throw new ArgumentException(nameof(options.TwilioAccountSid));
            }

            if (string.IsNullOrWhiteSpace(options.TwilioAuthToken))
            {
                throw new ArgumentException(nameof(options.TwilioAuthToken));
            }

            TwilioClient.Init(Options.TwilioAccountSid, Options.TwilioAuthToken);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TwilioAdapter"/> class.
 /// </summary>
 /// <param name="twilioClient">The Twilio client to connect to.</param>
 /// <param name="adapterOptions">Options for the <see cref="TwilioAdapter"/>.</param>
 /// <param name="logger">The ILogger implementation this adapter should use.</param>
 public TwilioAdapter(TwilioClientWrapper twilioClient, TwilioAdapterOptions adapterOptions, ILogger logger = null)
 {
     _twilioClient = twilioClient ?? throw new ArgumentNullException(nameof(twilioClient));
     _logger       = logger ?? NullLogger.Instance;
     _options      = adapterOptions ?? new TwilioAdapterOptions();
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TwilioAdapter"/> class using configuration settings.
 /// </summary>
 /// <param name="configuration">An <see cref="IConfiguration"/> instance.</param>
 /// <remarks>
 /// The configuration keys are:
 /// TwilioNumber: The phone number associated with the Twilio account.
 /// TwilioAccountSid: The string identifier of the account. See https://www.twilio.com/docs/glossary/what-is-a-sid
 /// TwilioAuthToken: The authentication token for the account.
 /// TwilioValidationUrl: The validation URL for incoming requests.
 /// </remarks>
 /// <param name="adapterOptions">Options for the <see cref="TwilioAdapter"/>.</param>
 /// <param name="logger">The ILogger implementation this adapter should use.</param>
 public TwilioAdapter(IConfiguration configuration, TwilioAdapterOptions adapterOptions = null, ILogger logger = null)
     : this(
         new TwilioClientWrapper(new TwilioClientWrapperOptions(configuration[TwilioNumberKey], configuration[TwilioAccountSidKey], configuration[TwilioAuthTokenKey], new Uri(configuration[TwilioValidationUrlKey]))), adapterOptions, logger)
 {
 }