private async Task ListenTo(InboundMessage inboundMessage) { if (inboundMessage?.MessageType != MessageType.Message) return; if (string.IsNullOrEmpty(inboundMessage.User)) return; if (!string.IsNullOrEmpty(Self.Id) && inboundMessage.User == Self.Id) return; if (inboundMessage.Channel != null && !_connectedHubs.ContainsKey(inboundMessage.Channel)) { _connectedHubs[inboundMessage.Channel] = _chatHubInterpreter.FromId(inboundMessage.Channel); } var message = new SlackMessage { User = new SlackUser { Id = inboundMessage.User, Name = GetMessageUsername(inboundMessage), }, Text = inboundMessage.Text, ChatHub = inboundMessage.Channel == null ? null : _connectedHubs[inboundMessage.Channel], RawData = inboundMessage.RawData, MentionsBot = _mentionDetector.WasBotMentioned(Self.Name, Self.Id, inboundMessage.Text) }; await RaiseMessageReceived(message); }
private Task ListenTo(InboundMessage inboundMessage) { if (inboundMessage == null) return Task.FromResult(false); switch (inboundMessage.MessageType) { case MessageType.Message: return HandleMessage((ChatMessage)inboundMessage); case MessageType.Group_Joined: return HandleGroupJoined((GroupJoinedMessage)inboundMessage); case MessageType.Channel_Joined: return HandleChannelJoined((ChannelJoinedMessage)inboundMessage); } return Task.FromResult(false); }
public void RaiseOnMessage(InboundMessage message) { OnMessage.Invoke(this, message); }
private string GetMessageUsername(InboundMessage inboundMessage) { string username = string.Empty; if (!string.IsNullOrEmpty(inboundMessage.User) && UserNameCache.ContainsKey(inboundMessage.User)) { username = UserNameCache[inboundMessage.User]; } return username; }