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); } Dictionary <string, SlackUser> users = GenerateUsers(handshakeResponse.Users); 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 = users, SlackChatHubs = GetChatHubs(handshakeResponse, users.Values.ToArray()), WebSocket = await _connectionFactory.CreateWebSocketClient(handshakeResponse.WebSocketUrl) }; var connection = await _slackConnectionFactory.Create(connectionInfo); return(connection); }
public async Task <ISlackConnection> Connect(string slackKey, ProxySettings proxySettings = null) { 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, proxySettings) }; return(_slackConnectionFactory.Create(connectionInfo)); }
private async Task Reconnect() { var reconnectingEvent = RaiseOnReconnecting(); var handshakeClient = _connectionFactory.CreateHandshakeClient(); var handshake = await handshakeClient.FirmShake(SlackKey); await _webSocketClient.Connect(handshake.WebSocketUrl); await Task.WhenAll(reconnectingEvent, RaiseOnReconnect()); }