Esempio n. 1
0
        public void TestManualSubscribePresenceChangeAndManualPresenceChange()
        {
            // Arrange
            slackClient = this.fixture.CreateUserClient();
            using (var sync = new InSync())
            {
                slackClient.OnPresenceChanged += x =>
                {
                    if (x.user == slackClient.MySelf.id)
                    {
                        // Assert
                        sync.Proceed();
                    }
                };

                slackClient.SubscribePresenceChange(slackClient.MySelf.id);
            }

            using (var sync = new InSync())
            {
                slackClient.OnPresenceChanged += x =>
                {
                    if (x is ManualPresenceChange && x.user == slackClient.MySelf.id)
                    {
                        // Assert
                        sync.Proceed();
                    }
                };

                // Act
                slackClient.EmitPresence(x => x.AssertOk(), Presence.away);
                slackClient.EmitPresence(x => x.AssertOk(), Presence.auto);
            }
        }
Esempio n. 2
0
        public SlackService(string authToken)
        {
            AuthToken = authToken;

            var waitEvent = new ManualResetEvent(false);

            Users = new Dictionary <string, SlackUser>();
            Slack = new SlackSocketClient(AuthToken);

            Console.WriteLine("Trying to connect to the Slack server....");
            Slack.Connect(
                (LoginResponse response) =>
            {
                if (response.ok == false)
                {
                    Console.WriteLine("Auth error : " + response.error);
                }

                Console.WriteLine("Connected");
                Console.WriteLine("  logged in as " + Slack.MyData.name);

                waitEvent.Set();
            });

            Slack.OnMessageReceived += OnMessageReceived;
            Slack.EmitPresence(_ => { }, Presence.active);

            waitEvent.WaitOne();
            waitEvent.Dispose();
        }