private void ClientOnConnect(LoginResponse loginResponse, SlackClient socketClient) { if (OnConnected != null) { OnConnected(loginResponse, socketClient); return; } SlackSocketClient client = (SlackSocketClient)socketClient; if (!loginResponse.Ok) { if (loginResponse.Error == ReasonCode.InvalidAuth || loginResponse.Error == ReasonCode.AccountInactive) { foreach (KeyValuePair <string, SlackSocketClient> pair in _socketClients) { if (pair.Value == client) { if (OnRemoveSocketClient != null) { OnRemoveSocketClient(pair.Key, loginResponse); } lock (_socketClients) { _socketClients.Remove(pair.Key); } } } } } }
/// <summary> /// Create the connection /// </summary> /// <param name="teamId"></param> /// <param name="accessToken"></param> public SlackSocketClient CreateSlackClientConnect(string teamId, string accessToken) { SlackSocketClient client = new SlackSocketClient(accessToken); client.Connect(ClientOnConnect); client.OnMessageReceived += OnMessageReceived; client.OnConnectionClosed += OnConnectionClosed; client.OnHello += OnHello; client.OnChannelRename += OnChannelRename; client.OnUserChange += OnUserChange; client.OnPresenceChange += OnPresenceChange; client.OnTyping += OnTyping; client.OnChannelMarked += OnChannelMarked; client.OnReactionAdded += OnReactionAdded; client.OnPongReceived += OnPongReceived; if (!_socketClients.ContainsKey(teamId)) { lock (_socketClients) { _socketClients.Add(teamId, client); } } return(client); }
public void ReconnectSlackClient(SlackSocketClient client) { client.Connect(ClientOnConnect); }
public void SendSlackMessage(SlackSocketClient client, string channelId, string textMessage, string userName = null) { client.SendMessage(OnSent, channelId, textMessage, userName); }