示例#1
0
        public void ListChannels()
        {
            if (_authHeaders != null)
            {
                dynamic channelsList = APICall.AuthenticatedGETRequest(_server + "/api/v1/channels.list", _authHeaders);
                var     channelList  = channelsList.channels;

                foreach (var channel in channelList)
                {
                    // Handle channel objects
                    // See https://rocket.chat/docs/developer-guides/rest-api/channels/list/
                }
            }
        }
示例#2
0
 private void Authenticate()
 {
     if (_username != string.Empty && _password != string.Empty && _server != string.Empty)
     {
         dynamic res = APICall.JSONPostRequest(_server + "/api/v1/login", "{\"user\": \"" + _username + "\", \"password\": \"" + _password + "\"}");
         if (res.status == "success")
         {
             _authToken   = res.data.authToken;
             _name        = res.data.me.name;
             _id          = res.data.me._id;
             _authHeaders = new WebHeaderCollection();
             _authHeaders["X-Auth-Token"] = _authToken;
             _authHeaders["X-User-Id"]    = _id;
             Console.WriteLine("[SUCCESS] Authenticated as " + _name + " [" + _id + "]");
         }
         else
         {
             Console.WriteLine("[ERROR] Authentication error. Are you using the correct login details?");
         }
     }
 }
示例#3
0
 public void SendMessage(string channelId, string message)
 {
     string  postData = "{ \"channel\": \"" + channelId + "\", \"text\": \"" + message + "\" }";
     dynamic res      = APICall.JSONPostRequest(_server + "/api/v1/chat.postMessage", postData, _authHeaders);
 }
示例#4
0
 public void JoinChannel(string channelName)
 {
     string  postdata = "{\"roomId\": \"" + channelName + "\"}";
     dynamic res      = APICall.JSONPostRequest(_server + "/api/v1/channels.join", postdata, _authHeaders);
 }