/// <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); }
/// <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(); }
/// <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); }
/// <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(); }
/// <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) { }