Beispiel #1
0
        static void Main(string[] args)
        {
            try
            {
                var clientId = "PUT CLIENT ID FROM SLACK APPLICATION REGISTATION HERE";
                var clientSecret = "PUT CLIENT SECRET FROM SLACK APPLICATION REGISTATION HERE";
                var redirectUri = "PUT REDIRECT FROM SLACK APPLICATION REGISTATION HERE";

                Console.WriteLine("------------------------------------------------------------------");
                Console.WriteLine("This app will open your web browser pointing at an authentication");
                Console.WriteLine("page. When you complete authentication, you'll be sent back to ");
                Console.WriteLine("whatever 'redirectUri' is above, plus some query-string values. ");
                Console.WriteLine("Paste the URI into the console window when prompted.");
                Console.WriteLine();
                Console.WriteLine("In a proper web application, the user experience will obviously");
                Console.WriteLine("be more sensible...");
                Console.WriteLine("------------------------------------------------------------------");

                // start...
                var state = Guid.NewGuid().ToString();
                var uri = SlackClient.GetAuthorizeUri(clientId, SlackScope.Identify | SlackScope.Read | SlackScope.Post, redirectUri, state, "socialsaleslounge");
                Console.WriteLine("Directing to: " + uri);
                Process.Start(uri.ToString());

                // read the result -- in a web application you can pick this up directly, here we're fudging it...
                Console.WriteLine("Paste in the URL of the authentication result...");
                var asString = Console.ReadLine();
                var index = asString.IndexOf('?');
                if (index != -1)
                    asString = asString.Substring(index + 1);

                // parse...
                var qs = HttpUtility.ParseQueryString(asString);
                var code = qs["code"];
                var newState = qs["state"];

                // validate the state. this isn't required, but it's makes sure the request and response line up...
                if (state != newState)
                    throw new InvalidOperationException("State mismatch.");

                // then get the token...
                Console.WriteLine("Requesting access token...");
                SlackClient.GetAccessToken((response) =>
                    {
                        var accessToken = response.access_token;
                        Console.WriteLine("Got access token '{0}'...", accessToken);

                        // post...
                        var client = new SlackClient(accessToken);
                        client.PostMessage(null, "#registrations", "Test", "Jo the Robot");

                    }, clientId, clientSecret, redirectUri, code);

                // finished...
                Console.WriteLine("Done.");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                Console.ReadLine();
            }
        }
Beispiel #2
0
 public ChannelAdapter(Channel info, ConnectedInterface connected, SlackClient client)
 {
     this.info = info;
     this.connected = connected;
     this.client = client;
 }
Beispiel #3
0
        private static void Main(string[] args)
        {
            SlackClient sc;

            #region args

            if (args.Length > 0)
            {
                try
                {
                    if (args[0].Equals("timo"))
                    {
                        sc = new SlackClient("xoxb-5134150563-iZKW7CIodzRbffqVmFmz6m2S");
                    }
                    else if (args[0].Equals("lily"))
                    {
                        sc = new SlackClient("xoxb-7444634401-UTU2IHZE2kULUWu70hgKV0FA");
                    }
                    else
                    {
                        sc = new SlackClient(args[0]);
                    }
                }
                catch
                {
                    sc = new SlackClient("xoxp-5007212458-11027941589-11025314452-ac4fcf3c3b");
                }
            }
            else
            {
                sc = new SlackClient("xoxp-5007212458-11027941589-11025314452-ac4fcf3c3b");
            }

            #endregion

            General.sc = sc;

            #region WS
            var ws = new WebSlack();
            ws.CreateWebSocket(sc.URL);
            General.ws = ws;
            #endregion

            #region Storage
            var s = new Storage();
            General.s = s;
            s.SetUp();
            #endregion

            #region LS
            var ls = new Listener(General.ws);
            General.ls = ls;
            var question = new Thread(ls.Listen);
            General.question = question;
            question.Start();
            #endregion

            #region sbr
            var sbr = new SlackBotRunner();
            General.sbr = sbr;
            #endregion

            #region BackupStarter
            if (!File.Exists(Helper.GetApplicationPath() + "/SlackBotBackup.exe"))
            {
                String things = Helper.GetApplicationPath().Remove(Helper.GetApplicationPath().Length - 16, 16);
                File.Copy(things + "Backup/bin/Debug/SlackBotBackup.exe", Helper.GetApplicationPath() + "/SlackBotBackup.exe");
            }
            if (Process.GetProcessesByName("SlackBotBackup").Length == 0)
            {
                Process.Start(Helper.GetApplicationPath() + "/SlackBotBackup.exe");
            }
            #endregion

            #region ProcessExit
            AppDomain.CurrentDomain.ProcessExit += OnProcessExit;
            Console.CancelKeyPress += OnProcessExit;
            #endregion

            sc.SendMessage("bot", "HELLO GUYS! IT'S ME, ANAL MOLLY!\n Only Testin'!");
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            try
            {
                var clientId     = "PUT CLIENT ID FROM SLACK APPLICATION REGISTATION HERE";
                var clientSecret = "PUT CLIENT SECRET FROM SLACK APPLICATION REGISTATION HERE";
                var redirectUri  = "PUT REDIRECT FROM SLACK APPLICATION REGISTATION HERE";

                Console.WriteLine("------------------------------------------------------------------");
                Console.WriteLine("This app will open your web browser pointing at an authentication");
                Console.WriteLine("page. When you complete authentication, you'll be sent back to ");
                Console.WriteLine("whatever 'redirectUri' is above, plus some query-string values. ");
                Console.WriteLine("Paste the URI into the console window when prompted.");
                Console.WriteLine();
                Console.WriteLine("In a proper web application, the user experience will obviously");
                Console.WriteLine("be more sensible...");
                Console.WriteLine("------------------------------------------------------------------");

                // start...
                var state = Guid.NewGuid().ToString();
                var uri   = SlackClient.GetAuthorizeUri(clientId, SlackScope.Identify | SlackScope.Read | SlackScope.Post, redirectUri, state, "socialsaleslounge");
                Console.WriteLine("Directing to: " + uri);
                Process.Start(uri.ToString());

                // read the result -- in a web application you can pick this up directly, here we're fudging it...
                Console.WriteLine("Paste in the URL of the authentication result...");
                var asString = Console.ReadLine();
                var index    = asString.IndexOf('?');
                if (index != -1)
                {
                    asString = asString.Substring(index + 1);
                }

                // parse...
                var qs       = HttpUtility.ParseQueryString(asString);
                var code     = qs["code"];
                var newState = qs["state"];

                // validate the state. this isn't required, but it's makes sure the request and response line up...
                if (state != newState)
                {
                    throw new InvalidOperationException("State mismatch.");
                }

                // then get the token...
                Console.WriteLine("Requesting access token...");
                SlackClient.GetAccessToken((response) =>
                {
                    var accessToken = response.access_token;
                    Console.WriteLine("Got access token '{0}'...", accessToken);

                    // post...
                    var client = new SlackClient(accessToken);
                    client.PostMessage(null, "#registrations", "Test", "Jo the Robot");
                }, clientId, clientSecret, redirectUri, code);

                // finished...
                Console.WriteLine("Done.");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                Console.ReadLine();
            }
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            try
            {
                //ManualResetEventSlim clientReady = new ManualResetEventSlim(false);
                //SlackSocketClient client2 = new SlackSocketClient("xoxb-146443698115-MntL68DGkXMjU2hyuHEWJ70H");

                //client2.Connect((connected) => {
                //    // This is called once the client has emitted the RTM start command
                //    clientReady.Set();
                //    foreach (var a in connected.channels)
                //    {
                //        Console.WriteLine(a.id + " " + a.name);
                //    }
                //}, () => {
                //    var id = client2.Channels.Where(x => x.name == "general").First();
                //    // This is called once the RTM client has connected to the end point
                //    client2.SendMessage((m)=>
                //    {
                //        Console.WriteLine("sent message" + m.error);
                //    }, id.id, "This should work");
                //});
                //client2.OnMessageReceived += (message) =>
                //{
                //    Console.WriteLine(message);
                //    // Handle each message as you receive them
                //};
                //clientReady.Wait();

                var clientId     = "146556577221.145791896241";
                var clientSecret = "4a9c2119c6705ff83462cbc8fde45333";
                var redirectUri  = "http://www.thisisatest.com/somethinggood/";

                Console.WriteLine("------------------------------------------------------------------");
                Console.WriteLine("This app will open your web browser pointing at an authentication");
                Console.WriteLine("page. When you complete authentication, you'll be sent back to ");
                Console.WriteLine("whatever 'redirectUri' is above, plus some query-string values. ");
                Console.WriteLine("Paste the URI into the console window when prompted.");
                Console.WriteLine();
                Console.WriteLine("In a proper web application, the user experience will obviously");
                Console.WriteLine("be more sensible...");
                Console.WriteLine("------------------------------------------------------------------");

                // start...
                var state = Guid.NewGuid().ToString();
                var uri   = SlackClient.GetAuthorizeUri(clientId, SlackScope.Identify | SlackScope.Read | SlackScope.Post, redirectUri, state, "TestingSlack");
                Console.WriteLine("Directing to: " + uri);
                Process.Start(uri.ToString());

                // read the result -- in a web application you can pick this up directly, here we're fudging it...
                Console.WriteLine("Paste in the URL of the authentication result...");
                var asString = Console.ReadLine();
                var index    = asString.IndexOf('?');
                if (index != -1)
                {
                    asString = asString.Substring(index + 1);
                }

                // parse...
                var qs       = HttpUtility.ParseQueryString(asString);
                var code     = qs["code"];
                var newState = qs["state"];

                // validate the state. this isn't required, but it's makes sure the request and response line up...
                if (state != newState)
                {
                    throw new InvalidOperationException("State mismatch.");
                }

                // then get the token...
                Console.WriteLine("Requesting access token...");
                SlackClient.GetAccessToken((response) =>
                {
                    var accessToken = response.access_token;
                    Console.WriteLine("Got access token '{0}'...", accessToken);

                    // post...
                    //var client = new SlackClient(accessToken);
                    //client.PostMessage(null, "#general", "Test", "Jo the Robot");

                    // Try this other thing:
                }, clientId, clientSecret, redirectUri, code);

                // finished...
                Console.WriteLine("Done.");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                Console.ReadLine();
            }
        }