示例#1
0
        static void Main(string[] args)
        {
            SlackClient slackClient = new SlackClient(ConfigurationManager.AppSettings["oAuthTokenBot"]);

            slackClient.Connect();
            try
            {
                string   userId   = slackClient.Users.Find(item => item.RealName.Contains("Orhan")).Id;
                string   response = slackClient.ConnectRTM();
                Pipeline pipeline = new Pipeline();
                pipeline.Add(new WeatherMiddleware());
                pipeline.Add(new QuoteMiddleware());
                pipeline.Add(new StayHydratedMiddleware());

                TimerPipeline timerPipeline = new TimerPipeline();
                timerPipeline.Add(new StayHydratedTimerMiddleware());

                var rtmClient = new RTMBot(new WebSocket(response), slackClient, pipeline, timerPipeline, 8);
                rtmClient.Connect();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.Read();
        }
示例#2
0
 private bool Connect()
 {
     if (m_client != null)
     {
         m_client.Connect(x => OnClientConnected());
         return(true);
     }
     else
     {
         return(false);
     }
 }
示例#3
0
        public static string GetWorkspace(string token)
        {
            using var connectionEvent = new ManualResetEventSlim(false);
            var client = new SlackClient(token);

            LoginResponse?loginResponse = null;

            client.Connect(response =>
            {
                loginResponse = response;
                // ReSharper disable once AccessToDisposedClosure
                connectionEvent.Set();
            });
            connectionEvent.Wait(Timeout);

            return(loginResponse?.ok == true
        ? loginResponse.team.name
        : loginResponse?.error ?? "Empty response");
        }
        public SlackClientService(string authtoken, string socketauthtoken)
        {
            ManualResetEventSlim clientReady = new ManualResetEventSlim(false);
            SlackClient          client      = new SlackClient(authtoken);

            client.Connect((connected) => {
                if (!connected.ok)
                {
                    Console.WriteLine(connected.error);
                }
                else
                {
                    Console.WriteLine("Connected Client to Slack");
                }
                clientReady.Set();
            }, () => {});
            clientReady.Wait();

            this._client = client;

            SlackSocketClient socketclient = new SlackSocketClient(socketauthtoken);

            socketclient.Connect((connected) => {
                // This is called once the client has emitted the RTM start command
                if (!connected.ok)
                {
                    Console.WriteLine(connected.error);
                }
                clientReady.Set();
            }, () => {
                Console.WriteLine("Connected SocketClient to Slack");
            });
            clientReady.Wait();

            this._socketclient = socketclient;
        }