예제 #1
0
 private void FetchData()
 {
     using (var syncClient = new InSync($"{nameof(SlackFixture.FetchData)} - Connected callback"))
     {
         this.UserClient.GetUserList(list =>
         {
             Console.WriteLine($"Slack users retrieved. Total: {list?.members?.Length}");
             this.Users = list?.members?.ToDictionary(x => x.id, x => x);
         });
         syncClient.Proceed();
     }
 }
예제 #2
0
        /// <summary>Sends the confirmation response.</summary>
        /// <param name="sender">The Slack sender.</param>
        /// <param name="originalMessage">The original message.</param>
        private void SendConfirmationResponse(User sender, IEnumerable <string> receivers, int kudosCount)
        {
            var slackBot = slackFixture.BotClient;
            var message  = GenerateConfirmMessage(sender, receivers, kudosCount);

            using (var syncDirectJoint = new InSync("JoinDirectMessageChannel"))
            {
                slackBot.JoinDirectMessageChannel(response =>
                {
                    using (var syncPosting = new InSync("DirectMessagePosting"))
                    {
                        slackBot.PostMessage(response =>
                        {
                            syncPosting.Proceed();
                        }, response.channel?.id, message);
                    }
                    syncDirectJoint.Proceed();
                }, sender.id);
            }
        }
예제 #3
0
        public SlackSocketClient CreateClient(string authToken, IWebProxy proxySettings = null, bool maintainPresenceChanges = false, Action <SlackSocketClient, PresenceChange> presenceChanged = null)
        {
            SlackSocketClient client;

            LoginResponse loginResponse = null;

            using (var syncClient = new InSync($"{nameof(SlackAPI.SlackClient.Connect)} - Connected callback"))
                using (var syncClientSocket = new InSync($"{nameof(SlackAPI.SlackClient.Connect)} - SocketConnected callback"))
                    using (var syncClientSocketHello = new InSync($"{nameof(SlackAPI.SlackClient.Connect)} - SocketConnected hello callback"))
                    {
                        client = new SlackSocketClient(authToken, proxySettings, maintainPresenceChanges);

                        void OnPresenceChanged(PresenceChange x)
                        {
                            presenceChanged?.Invoke(client, x);
                        }

                        client.OnPresenceChanged += OnPresenceChanged;
                        client.OnHello           += () => syncClientSocketHello.Proceed();
                        client.Connect(x =>
                        {
                            loginResponse = x;

                            Console.WriteLine($"Connected {x.ok}");
                            syncClient.Proceed();
                            if (!x.ok)
                            {
                                // If connect fails, socket connect callback is not called
                                syncClientSocket.Proceed();
                                syncClientSocketHello.Proceed();
                            }
                        }, () =>
                        {
                            Console.WriteLine("Socket Connected");
                            syncClientSocket.Proceed();
                        });
                    }


            return(client);
        }
예제 #4
0
        /// <summary>Sends the inform messages.</summary>
        /// <param name="sender">The Slack sender.</param>
        /// <param name="originalMessage">The original message.</param>
        private void SendInformMessages(User sender, IEnumerable <string> receiverSlackIds, int kudosCount)
        {
            var slackBot = slackFixture.BotClient;
            var messages = GenerateInformMessages(sender, receiverSlackIds, kudosCount);

            foreach ((var receiver, var message) in messages)
            {
                using (var syncDirectJoint = new InSync($"JoinDirectMessageChannel - {receiver}"))
                {
                    slackBot.JoinDirectMessageChannel(response =>
                    {
                        using (var syncPosting = new InSync($"DirectMessagePosting - {receiver}"))
                        {
                            slackBot.PostMessage(response =>
                            {
                                syncPosting.Proceed();
                            }, response.channel?.id, message);
                        }
                        syncDirectJoint.Proceed();
                    }, receiver);
                }
            }
        }