This represents a place in Slack where people can chat - typically a channel, group, or DM.
 public static SlackChatHub ToChatHub(this Channel channel)
 {
     var newChannel = new SlackChatHub
     {
         Id = channel.Id,
         Name = "#" + channel.Name,
         Type = SlackChatHubType.Channel,
         Members = channel.Members
     };
     return newChannel;
 }
        public static SlackChatHub ToChatHub(this Group group)
        {
            var newGroup = new SlackChatHub
            {
                Id = group.Id,
                Name = "#" + group.Name,
                Type = SlackChatHubType.Group,
                Members = group.Members
            };

            return newGroup;
        }
        private Dictionary<string, SlackChatHub> GetChatHubs(HandshakeResponse handshakeResponse)
        {
            var hubs = new Dictionary<string, SlackChatHub>();

            foreach (Channel channel in handshakeResponse.Channels.Where(x => !x.IsArchived))
            {
                if (channel.IsMember)
                {
                    var newChannel = new SlackChatHub
                    {
                        Id = channel.Id,
                        Name = "#" + channel.Name,
                        Type = SlackChatHubType.Channel
                    };

                    hubs.Add(channel.Id, newChannel);
                }
            }

            foreach (Group group in handshakeResponse.Groups.Where(x => !x.IsArchived))
            {
                if (group.Members.Any(x => x == handshakeResponse.Self.Id))
                {
                    var newGroup = new SlackChatHub
                    {
                        Id = group.Id,
                        Name = "#" + group.Name,
                        Type = SlackChatHubType.Group
                    };

                    hubs.Add(group.Id, newGroup);
                }
            }

            foreach (Im im in handshakeResponse.Ims)
            {
                User user = handshakeResponse.Users.FirstOrDefault(x => x.Id == im.User);
                var dm = new SlackChatHub
                {
                    Id = im.Id,
                    Name = "@" + (user == null ? im.User : user.Name),
                    Type = SlackChatHubType.DM
                };

                hubs.Add(im.Id, dm);
            }

            return hubs;
        }
        public void given_hub_id_then_should_return_expected_slack_hub(string hubId, SlackChatHubType hubType)
        {
            // given

            // when
            var interpreter = new ChatHubInterpreter();
            SlackChatHub chatHub = interpreter.FromId(hubId);

            // then
            var expected = new SlackChatHub
            {
                Id = hubId,
                Name = hubId,
                Type = hubType
            };
            chatHub.ShouldLookLike(expected);
        }
Beispiel #5
0
        private async Task<SlackChatHub> GetChatHub(ResponseMessage responseMessage)
        {
            SlackChatHub chatHub = null;

            if (responseMessage.ResponseType == ResponseType.Channel)
            {
                chatHub = new SlackChatHub { Id = responseMessage.Channel };
            }
            else if (responseMessage.ResponseType == ResponseType.DirectMessage)
            {
                if (string.IsNullOrEmpty(responseMessage.Channel))
                {
                    chatHub = await GetUserChatHub(responseMessage.UserId);
                }
                else
                {
                    chatHub = new SlackChatHub { Id = responseMessage.Channel };
                }
            }

            return chatHub;
        }
 public Task IndicateTyping(SlackChatHub chatHub)
 {
     throw new NotImplementedException();
 }
 public async Task SayTo(SlackChatHub chatHub, string message)
 {
     await ContinueslyTryToConnect();
     if (chatHub != null)
     await _connection.Say(new BotMessage() {ChatHub = chatHub, Text = message});
 }
Beispiel #8
0
        public async Task SendMessage(ResponseMessage responseMessage)
        {
            SlackChatHub chatHub = null;

            if (responseMessage.ResponseType == ResponseType.Channel)
            {
                chatHub = new SlackChatHub { Id = responseMessage.Channel };
            }
            else if (responseMessage.ResponseType == ResponseType.DirectMessage)
            {
                if (string.IsNullOrEmpty(responseMessage.Channel))
                {
                    chatHub = await GetUserChatHub(responseMessage.UserId);
                }
                else
                {
                    chatHub = new SlackChatHub { Id = responseMessage.Channel };
                }
            }

            if (chatHub != null)
            {
                var botMessage = new BotMessage
                {
                    ChatHub = chatHub,
                    Text = responseMessage.Text
                };

                await _client.Say(botMessage);
            }
            else
            {
                Console.WriteLine("Unable to find channel for message '{0}'. Message not sent", responseMessage.Text);
            }
        }
        private async Task RaiseChatHubJoined(SlackChatHub hub)
        {
            var e = OnChatHubJoined;

            if (e != null)
            {
                try
                {
                    await e(hub);
                }
                catch
                {
                }
            }
        }
        public async Task IndicateTyping(SlackChatHub chatHub)
        {
            var message = new TypingIndicatorMessage
            {
                Channel = chatHub.Id,
                Type = "typing"
            };

            await _webSocketClient.SendMessage(message);
        }