예제 #1
0
 private async Task UpdateUserCache(UserInboundMessage userInboundMessage)
 {
     if (userInboundMessage.User != null && !_userCache.ContainsKey(userInboundMessage.User))
     {
         _userCache[userInboundMessage.User] = await GetUser(userInboundMessage.User);
     }
 }
예제 #2
0
        private async Task UpdateHubCache(UserInboundMessage userInboundMessage)
        {
            if (userInboundMessage.Channel != null && !_hubCache.ContainsKey(userInboundMessage.Channel))
            {
                var chatHub = await GetChatHub(userInboundMessage.Channel);

                _hubCache[userInboundMessage.Channel] = chatHub ?? _chatHubInterpreter.FromId(userInboundMessage.Channel);
            }
        }
            protected override void Given()
            {
                UserInboundUserInboundMessage = new UserInboundMessage
                {
                    MessageType = MessageType.Unknown
                };

                base.Given();
            }
            protected override void Given()
            {
                base.Given();

                UserInboundUserInboundMessage = new UserInboundMessage
                {
                    User        = "******",
                    MessageType = MessageType.Message
                };
            }
            public void should_not_throw_exception_when_error_is_thrown()
            {
                var message = new UserInboundMessage
                {
                    User        = "******",
                    MessageType = MessageType.Message
                };

                WebSocket.RaiseOnMessage(message);
            }
            protected override void Given()
            {
                base.Given();

                UserInboundUserInboundMessage = new UserInboundMessage
                {
                    MessageType = MessageType.Message,
                    User        = null
                };
            }
            protected override void Given()
            {
                base.Given();

                ConnectionInfo.Self = new ContactDetails {
                    Id = "self-id", Name = "self-name"
                };

                UserInboundUserInboundMessage = new UserInboundMessage
                {
                    MessageType = MessageType.Message,
                    User        = ConnectionInfo.Self.Id
                };
            }
            protected override void Given()
            {
                base.Given();

                GetMockFor <IChatHubInterpreter>()
                .Setup(x => x.FromId(_hubId))
                .Returns(_expectedChatHub);

                UserInboundUserInboundMessage = new UserInboundMessage
                {
                    Channel     = _hubId,
                    MessageType = MessageType.Message,
                    User        = "******"
                };
            }
            protected override void Given()
            {
                base.Given();

                ConnectionInfo.SlackChatHubs.Add("channelId", new SlackChatHub {
                    Id = "channelId", Name = "NaMe23"
                });

                UserInboundUserInboundMessage = new UserInboundMessage
                {
                    Channel     = ConnectionInfo.SlackChatHubs.First().Key,
                    MessageType = MessageType.Message,
                    User        = "******"
                };
            }
예제 #10
0
        public async Task HandleInboundData(UserInboundMessage userInboundMessage)
        {
            if (string.IsNullOrEmpty(userInboundMessage.User))
            {
                return;
            }

            await UpdateHubCache(userInboundMessage);

            await UpdateUserCache(userInboundMessage);

            if (!string.IsNullOrEmpty(Self.Id) && userInboundMessage.User == Self.Id)
            {
                return;
            }

            SlackMessage message = new SlackMessage
            {
                User        = userInboundMessage.User == null ? null : _userCache[userInboundMessage.User],
                Text        = userInboundMessage.Text,
                ChatHub     = userInboundMessage.Channel == null ? null : _hubCache[userInboundMessage.Channel],
                Time        = userInboundMessage.Time,
                RawData     = userInboundMessage.RawData,
                MentionsBot = _mentionDetector.WasBotMentioned(Self.Name, Self.Id, userInboundMessage.Text)
            };

            if (message.User == null && userInboundMessage.User != null)
            {
                message.User = new SlackUser {
                    Id = userInboundMessage.User, Name = ""
                }
            }
            ;
            if (message.ChatHub == null && userInboundMessage.Channel != null)
            {
                message.ChatHub = new SlackChatHub {
                    Id = userInboundMessage.Channel, Name = ""
                }
            }
            ;

            if (userInboundMessage.MessageSubType == MessageSubType.bot_message)
            {
                message.User.Name = ((BotInboundMessage)userInboundMessage).UserName;
            }

            await RaiseMessageReceived(message);
        }
            protected override void Given()
            {
                base.Given();

                ConnectionInfo.Users.Add("userABC", new SlackUser {
                    Id = "userABC", Name = "i-have-a-name"
                });

                UserInboundUserInboundMessage = new UserInboundMessage
                {
                    User        = "******",
                    MessageType = MessageType.Message,
                    Text        = "amazing-text",
                    RawData     = "I am raw data yo"
                };
            }
        public void then_should_look_like_expected()
        {
            DateTime time = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);

            time = time.AddSeconds(Math.Round(double.Parse(Ts))).ToLocalTime();
            var expected = new UserInboundMessage
            {
                MessageType = MessageType.Message,
                Channel     = "<myChannel>",
                User        = "******",
                Text        = "hi, my name is <noobot>",
                Team        = "<myTeam>",
                Time        = time,
                RawData     = Json
            };

            Result.ShouldLookLike(expected);
        }
            protected override void Given()
            {
                base.Given();

                ConnectionInfo.Self = new ContactDetails {
                    Id = "self-id", Name = "self-name"
                };

                UserInboundUserInboundMessage = new UserInboundMessage
                {
                    Channel     = "idy",
                    MessageType = MessageType.Message,
                    Text        = "please send help... :-p",
                    User        = "******"
                };

                GetMockFor <IMentionDetector>()
                .Setup(x => x.WasBotMentioned(ConnectionInfo.Self.Name, ConnectionInfo.Self.Id, UserInboundUserInboundMessage.Text))
                .Returns(true);
            }
 public void RaiseOnMessage(UserInboundMessage userInboundMessage)
 {
     OnMessage.Invoke(this, userInboundMessage);
 }
 protected override void When()
 {
     Result = (UserInboundMessage)SUT.InterpretMessage(Json);
 }
 public async Task HandleUserMessage(UserInboundMessage userInboundData)
 {
     await _inboundDataHandler.HandleInboundData(userInboundData);
 }