コード例 #1
0
        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);
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
        /// <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);
        }
コード例 #3
0
 public void ReconnectSlackClient(SlackSocketClient client)
 {
     client.Connect(ClientOnConnect);
 }
コード例 #4
0
 public void SendSlackMessage(SlackSocketClient client, string channelId, string textMessage, string userName = null)
 {
     client.SendMessage(OnSent, channelId, textMessage, userName);
 }