public async Task<ISlackConnection> Connect(string slackKey) { if (string.IsNullOrEmpty(slackKey)) { throw new ArgumentNullException(nameof(slackKey)); } var handshakeClient = _connectionFactory.CreateHandshakeClient(); HandshakeResponse handshakeResponse = await handshakeClient.FirmShake(slackKey); if (!handshakeResponse.Ok) { throw new HandshakeException(handshakeResponse.Error); } var connectionInfo = new ConnectionInformation { SlackKey = slackKey, Self = new ContactDetails { Id = handshakeResponse.Self.Id, Name = handshakeResponse.Self.Name }, Team = new ContactDetails { Id = handshakeResponse.Team.Id, Name = handshakeResponse.Team.Name }, Users = GenerateUsers(handshakeResponse.Users), SlackChatHubs = GetChatHubs(handshakeResponse), WebSocket = await GetWebSocket(handshakeResponse) }; return _slackConnectionFactory.Create(connectionInfo); }
public void Initialise(ConnectionInformation connectionInformation) { SlackKey = connectionInformation.SlackKey; Team = connectionInformation.Team; Self = connectionInformation.Self; _userCache = connectionInformation.Users; _connectedHubs = connectionInformation.SlackChatHubs; _webSocketClient = connectionInformation.WebSocket; _webSocketClient.OnClose += (sender, args) => { ConnectedSince = null; RaiseOnDisconnect(); }; _webSocketClient.OnMessage += async (sender, message) => await ListenTo(message); ConnectedSince = DateTime.Now; }
public ISlackConnection Create(ConnectionInformation connectionInformation) { Create_ConnectionInformation = connectionInformation; return Create_Value; }
public ISlackConnection Create(ConnectionInformation connectionInformation) { var slackConnection = new SlackConnection(_connectionFactory, _mentionDetector); slackConnection.Initialise(connectionInformation); return slackConnection; }