Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SlackClientWrapper"/> class.
        /// Creates a Slack client by supplying the access token.
        /// </summary>
        /// <param name="options">An object containing API credentials, a webhook verification token and other options.</param>
        public SlackClientWrapper(SlackAdapterOptions options)
        {
            Options = options ?? throw new ArgumentNullException(nameof(options));

            if (string.IsNullOrWhiteSpace(options.SlackVerificationToken) && string.IsNullOrWhiteSpace(options.SlackClientSigningSecret))
            {
                const string warning = "****************************************************************************************" +
                                       "* WARNING: Your bot is operating without recommended security mechanisms in place.     *" +
                                       "* Initialize your adapter with a clientSigningSecret parameter to enable               *" +
                                       "* verification that all incoming webhooks originate with Slack:                        *" +
                                       "*                                                                                      *" +
                                       "* var adapter = new SlackAdapter({clientSigningSecret: <my secret from slack>});       *" +
                                       "*                                                                                      *" +
                                       "****************************************************************************************" +
                                       ">> Slack docs: https://api.slack.com/docs/verifying-requests-from-slack";

                throw new Exception(warning + Environment.NewLine + "Required: include a verificationToken or clientSigningSecret to verify incoming Events API webhooks");
            }

            _api = new SlackTaskClient(options.SlackBotToken);
            LoginWithSlackAsync(default).Wait();
Exemple #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SlackAdapter"/> class.
 /// Creates a Slack adapter.
 /// </summary>
 /// <param name="adapterOptions">The adapter options to be used when connecting to the Slack API.</param>
 /// <param name="logger">The ILogger implementation this adapter should use.</param>
 /// <param name="slackClient">The SlackClientWrapper used to connect to the Slack API.</param>
 public SlackAdapter(SlackAdapterOptions adapterOptions, ILogger logger = null, SlackClientWrapper slackClient = null)
 {
     _slackClient = slackClient ?? new SlackClientWrapper(adapterOptions) ?? throw new ArgumentNullException(nameof(adapterOptions));
     _logger      = logger ?? NullLogger.Instance;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SlackAdapter"/> class using configuration settings.
 /// </summary>
 /// <param name="configuration">An <see cref="IConfiguration"/> instance.</param>
 /// <remarks>
 /// The configuration keys are:
 /// SlackVerificationToken: A token for validating the origin of incoming webhooks.
 /// SlackBotToken: A token for a bot to work on a single workspace.
 /// SlackClientSigningSecret: The token used to validate that incoming webhooks are originated from Slack.
 /// </remarks>
 /// <param name="options">An instance of <see cref="SlackAdapterOptions"/>.</param>
 /// <param name="logger">The ILogger implementation this adapter should use.</param>
 public SlackAdapter(IConfiguration configuration, SlackAdapterOptions options = null, ILogger logger = null)
     : this(new SlackClientWrapper(new SlackClientWrapperOptions(configuration["SlackVerificationToken"], configuration["SlackBotToken"], configuration["SlackClientSigningSecret"])), options, logger)
 {
 }