Пример #1
0
        private Task <UserListResponse> GetUserListAsync()
        {
            var tskSource = new TaskCompletionSource <UserListResponse>(TaskCreationOptions.RunContinuationsAsynchronously);

            _client.GetUserList(response => tskSource.TrySetResult(response));
            return(tskSource.Task);
        }
Пример #2
0
 public void RefreshUserList(Action callback = null)
 {
     client.GetUserList((clr) =>
     {
         callback?.Invoke();
     });
 }
Пример #3
0
        private bool SendMessages(ref bool atLeastOneSuccess)
        {
            var success = true;
            var files   = SelectFiles();

            if (files.Length > 0)
            {
                ManualResetEventSlim clientReady = new ManualResetEventSlim(false);
                SlackSocketClient    client      = new SlackSocketClient(Token);
                client.Connect((connected) =>
                {
                    // This is called once the client has emitted the RTM start command
                    clientReady.Set();
                }, () =>
                {
                    // This is called once the RTM client has connected to the end point
                });
                client.OnMessageReceived += (message) =>
                {
                    // Handle each message as you receive them
                };
                clientReady.Wait();
                client.GetUserList((ulr) => { Info("Got users."); });

                foreach (FileInf file in files)
                {
                    try
                    {
                        var xdoc = XDocument.Load(file.Path);
                        foreach (XElement xMessage in xdoc.XPathSelectElements("Messages/Message"))
                        {
                            var username = xMessage.Element("User").Value;
                            var text     = xMessage.Element("Text").Value;

                            var user      = client.Users.Find(x => x.name.Equals(username));
                            var dmchannel = client.DirectMessages.Find(x => x.user.Equals(user.id));
                            client.PostMessage((mr) => Info("Message '" + text + "' sent to " + dmchannel.id + "."), dmchannel.id, text);

                            if (!atLeastOneSuccess)
                            {
                                atLeastOneSuccess = true;
                            }
                        }
                    }
                    catch (ThreadAbortException)
                    {
                        throw;
                    }
                    catch (Exception e)
                    {
                        ErrorFormat("An error occured while sending the messages of the file {0}.", e, file.Path);
                        success = false;
                    }
                }
            }

            return(success);
        }
Пример #4
0
        public ICollection <User> Users()
        {
            ICollection <User> users = new List <User>();

            _Client.GetUserList((ulr) => {
                foreach (User user in ulr.members)
                {
                    users.Add(user);
                }
            });
            return(users);
        }
Пример #5
0
        internal List <SlackAPI.User> GetUsers(List <string> userIds)
        {
            var token = Environment.GetEnvironmentVariable("SLACK_ACCESS_TOKEN");

            if (token == null)
            {
                throw new Exception("Error getting slack token from ssm");
            }

            ManualResetEventSlim clientReady = new ManualResetEventSlim(false);
            SlackSocketClient    client      = new SlackSocketClient(token);

            client.Connect((connected) => {
                // This is called once the client has emitted the RTM start command
                clientReady.Set();
            }, () => {
                // This is called once the RTM client has connected to the end point
            });
            // client.OnMessageReceived += (message) =>
            // {
            //     // Handle each message as you receive them
            // };
            clientReady.Wait();

            client.GetUserList((ulr) => { Console.WriteLine("got users"); });

            var userList = new List <SlackAPI.User>();

            foreach (var u in userIds)
            {
                userList.Add(client.Users.Find(x => x.id.Equals(u)));
            }

            // Release the socket.
            client.CloseSocket();

            return(userList);
        }