Esempio n. 1
0
 public override void OnCommand(List <string> extras)
 {
     if (extras.Count > 0)
     {
         Blah = extras[0];
     }
     SlackApp?.Say(string.IsNullOrWhiteSpace(Blah)
                                ? "Hello"
                                : $"Hello to {Blah}. :wave:",
                   Message !.channel);
 }
Esempio n. 2
0
        public override void OnCommand(List <string> extras)
        {
            if (extras.Count > 0)
            {
                Name = extras[0];
            }
            SlackApp?.SayToChannel(string.IsNullOrWhiteSpace(Name)
                                        ? "Example Hello"
                                        : $"Example Hello to {Name}. :wave:",
                                   null,
                                   channel: Message?.channel ?? "");

            Console.WriteLine("Example Command Executed");
        }
Esempio n. 3
0
        private void SetupSlackApp(string[] args)
        {
            // Parse any command line arguments and environment variables
            _config = ParamParser <CommandLine> .Parse(args);

            // Setup Slack integration
            // Depending on the scenario, you will need to supply only some fields
            //  - SocketMode app.          AppLevelToken from https://api.slack.com/apps/{id}/general
            //  - Make calls as a Bot.     BotAccessToken or (ClientId + ClientSecret + BotScopes + RedirectUrl for browser login)
            //  - Make calls as a User.    UserAccessToken or ((ClientId + ClientSecret + UserScopes + RedirectUrl for browser login)
            // RedirectUrl is optional for browser login. The default url will be http://localhost:3100/ if it is not supplied
            _app = new SlackApp
            {
                ClientId            = _config.ClientId,
                ClientSecret        = _config.ClientSecret,
                AppLevelToken       = _config.AppLevelToken,
                BotAccessToken      = _config.BotAccessToken,
                BotScopes           = _config.BotScopes ?? DefaultBotScope,
                UserAccessToken     = _config.UserAccessToken,
                UserScopes          = _config.UserScopes ?? DefaultUserScope,
                RedirectUrl         = _config.RedirectUrl ?? DefaultRedirectUrl,
                AccessTokensUpdated = slackApp =>
                {
                    // If you aren't supplying a bot or user access token,
                    // After the user logs in using the browser
                    Console.WriteLine($"Bot Access Token: {slackApp.BotAccessToken}");
                    Console.WriteLine($"User Access Token: {slackApp.UserAccessToken}");
                    // TODO: Save new access tokens to a safe place
                },
                LogBuilder = builder =>
                {
                    // Microsoft Logging framework. Configure as you feel best
                    // TODO: configure the Logger builder
                    builder
                                       #if DEBUG
                    .SetMinimumLevel(LogLevel.Debug)
                                       #endif
                    .AddDebug()
                    .AddConsole(options =>
                    {
                        options.LogToStandardErrorThreshold = LogLevel.Debug;
                    });
                }
            };
        }