예제 #1
0
        private void SlackTokenCallBack(IRestResponse restResponse, RestRequestAsyncHandle arg2)
        {
            string sToken = restResponse.Content;
            //string Token = "{\"ok\":true,\"access_token\":\"xoxp-108334113943-221049390612-246282639767-2e5c136f20e80573ca7ac3c00ee07606\",\"scope\":\"identify,files:write:user\",\"user_id\":\"U6H1FBGJ0\",\"team_name\":\"ExpressBase Systems\",\"team_id\":\"T369U3BTR\"}";

            string    jsonToken  = sToken.Replace("\\", string.Empty);
            SlackJson slackToken = JsonConvert.DeserializeObject <SlackJson>(jsonToken);
            bool      res        = this.ServiceClient.Post <bool>(new SlackAuthRequest {
                IsNew = true, SlackJson = slackToken
            });
        }
예제 #2
0
            public string Post(SlackPostMqRequest req)
            {
                TenantDbFactory dbFactory = new TenantDbFactory(req.TenantAccountId, this.Redis);

                string sql = "SELECT slackjson FROM eb_users WHERE id = @id";

                var       dt        = dbFactory.DataDB.DoQuery(sql, new DbParameter[] { dbFactory.DataDB.GetNewParameter("id", System.Data.DbType.Int32, req.UserId) });
                var       json      = dt.Rows[0][0];
                SlackJson slackJson = JsonConvert.DeserializeObject <SlackJson>(json.ToString());

                var client = new RestClient("https://slack.com");

                if (req.PostType == 1)
                {
                    var request = new RestRequest("api/files.upload", Method.POST);

                    request.AddParameter("token", slackJson.AccessToken);
                    request.AddParameter("user_id", slackJson.UserId);
                    request.AddParameter("team_id", slackJson.TeamId);
                    request.AddParameter("channels", req.Payload.Channel);
                    if (!string.IsNullOrEmpty(req.Payload.Text))
                    {
                        request.AddParameter("content", req.Payload.Text);
                    }

                    if (req.Payload.SlackFile != null && req.Payload.SlackFile.FileByte != null && req.Payload.SlackFile.FileByte.Length > 0)
                    {
                        request.AddFile("file", req.Payload.SlackFile.FileByte, req.Payload.SlackFile.FileName, contentType: "multipart/form-data");
                    }

                    //Execute the request
                    var res = client.ExecuteAsyncPost(request, SlackCallBack, "POST");
                }
                else if (req.PostType == 0)
                {
                    var request = new RestRequest("api/chat.postMessage", Method.POST);

                    request.AddParameter("token", slackJson.AccessToken);
                    request.AddParameter("channels", req.Payload.Channel);
                    request.AddParameter("user_id", slackJson.UserId);
                    request.AddParameter("team_id", slackJson.TeamId);
                    if (!string.IsNullOrEmpty(req.Payload.Text))
                    {
                        request.AddParameter("text", req.Payload.Text);
                    }

                    //Execute the request
                    var res = client.ExecuteAsyncPost(request, SlackCallBack, "POST");
                }

                return(null);
            }