예제 #1
0
        public async Task Add(string slackKey, string name, string channel = null, string messageTs = null, string file = null, string fileComment = null)
        {
            var request = ClientConstants
                          .SlackApiHost
                          .AppendPathSegment(REACTIONS_ADD_PATH)
                          .SetQueryParam("token", slackKey)
                          .SetQueryParam("name", name)
                          .SetQueryParam("channel", channel)
                          .SetQueryParam("timestamp", messageTs)
                          .SetQueryParam("file", file)
                          .SetQueryParam("file_comment", fileComment);

            var response = await request.GetJsonAsync <DefaultStandardResponse>();

            if (!response.Ok)
            {
                switch (response.Error)
                {
                case "already_reacted":
                case "too_many_emoji":
                case "too_many_reactions":
                    return;
                }
            }
            responseVerifier.VerifyResponse(response);
        }
예제 #2
0
        public async Task Close(string slackKey, string channel)
        {
            var response = await ClientConstants
                           .SlackApiHost
                           .AppendPathSegment(CONVERSATION_CLOSE_PATH)
                           .SetQueryParam("token", slackKey)
                           .SetQueryParam("channel", channel)
                           .GetJsonAsync <DefaultStandardResponse>();

            responseVerifier.VerifyResponse(response);
        }
예제 #3
0
        public async Task <Models.Channel> JoinDirectMessageChannel(string slackKey, string user)
        {
            var response = await ClientConstants
                           .SlackApiHost
                           .AppendPathSegment(JOIN_DM_PATH)
                           .SetQueryParam("token", slackKey)
                           .SetQueryParam("user", user)
                           .GetJsonAsync <JoinChannelResponse>();

            _responseVerifier.VerifyResponse(response);
            return(response.Channel);
        }
예제 #4
0
        public async Task PostFile(string slackKey, string channel, string filePath)
        {
            var httpResponse = await ClientConstants
                               .SlackApiHost
                               .AppendPathSegment(FILE_UPLOAD_PATH)
                               .SetQueryParam("token", slackKey)
                               .SetQueryParam("channels", channel)
                               .PostMultipartAsync(content => content.AddFile(POST_FILE_VARIABLE_NAME, filePath));

            var responseContent = await httpResponse.Content.ReadAsStringAsync();

            var response = JsonConvert.DeserializeObject <StandardResponse>(responseContent);

            _responseVerifier.VerifyResponse(response);
        }
예제 #5
0
        public async Task <T> Execute <T>(IRestRequest request) where T : class
        {
            IRestClient   client   = _restSharpFactory.CreateClient(SLACK_URL);
            IRestResponse response = await client.ExecutePostTaskAsync(request);

            return(_responseVerifier.VerifyResponse <T>(response));
        }
예제 #6
0
        public async Task <OAuthAccessResponse> OAuthAccess(string clientId, string clientSecret, string code, string redirectUri, string state)
        {
            var response = await ClientConstants
                           .SlackApiHost
                           .AppendPathSegment(OAUTH_ACCESS)
                           .PostUrlEncodedAsync(new {
                client_id     = clientId,
                client_secret = clientSecret,
                code,
                redirect_uri = redirectUri,
                state
            })
                           .ReceiveJson <OAuthAccessResponse>();

            responseVerifier.VerifyResponse(response);
            return(response);
        }
예제 #7
0
        public async Task <HandshakeResponse> FirmShake(string slackKey)
        {
            var response = await ClientConstants
                           .SlackApiHost
                           .AppendPathSegment(HANDSHAKE_PATH)
                           .SetQueryParam("token", slackKey)
                           .GetJsonAsync <HandshakeResponse>();

            _responseVerifier.VerifyResponse(response);
            return(response);
        }
예제 #8
0
        public async Task <PostMessageResponse> PostMessage(string slackKey, string channel, string text, IList <SlackAttachment> attachments)
        {
            var request = ClientConstants
                          .SlackApiHost
                          .AppendPathSegment(SEND_MESSAGE_PATH)
                          .SetQueryParam("token", slackKey)
                          .SetQueryParam("channel", channel)
                          .SetQueryParam("text", text)
                          .SetQueryParam("as_user", "true");

            if (attachments != null && attachments.Any())
            {
                request.SetQueryParam("attachments", JsonConvert.SerializeObject(attachments));
            }

            var response = await request.GetJsonAsync <PostMessageResponse>();

            _responseVerifier.VerifyResponse(response);
            return(response);
        }
예제 #9
0
        public async Task <Models.Team> GetTeamInfo(string slackKey)
        {
            var response = await ClientConstants
                           .SlackApiHost
                           .AppendPathSegment(TEAM_INFO)
                           .SetQueryParam("token", slackKey)
                           .GetJsonAsync <TeamInfoResponse>();

            responseVerifier.VerifyResponse(response);
            return(response.Team);
        }
예제 #10
0
        public async Task <MessageResponse> PostMessage(string slackKey, string channel, string text,
                                                        IEnumerable <SlackAttachment> attachments = null, string threadTs = null, string iconUrl = null,
                                                        string userName = null, bool asUser = false, bool linkNames = true, IEnumerable <BlockBase> blocks = null)
        {
            var request = ClientConstants
                          .SlackApiHost
                          .AppendPathSegment(SEND_MESSAGE_PATH);

            var args = new Dictionary <string, string>()
            {
                { "token", slackKey },
                { "channel", channel },
                { "text", text },
                { "as_user", asUser.ToString().ToLower() },
                { "link_names", linkNames.ToString().ToLower() },
            };

            if (threadTs != null)
            {
                args.Add("thread_ts", threadTs);
            }
            if (iconUrl != null)
            {
                args.Add("icon_url", iconUrl);
            }
            if (userName != null)
            {
                args.Add("username", userName);
            }


            if (attachments != null && attachments.Any())
            {
                args.Add("attachments", JsonConvert.SerializeObject(attachments));
            }

            if (blocks != null && blocks.Any())
            {
                var jsonBlocks = JsonConvert.SerializeObject(blocks);
                args.Add("blocks", jsonBlocks);
            }

            var response = await request.PostUrlEncodedAsync(args)
                           .ReceiveJson <MessageResponse>();

            _responseVerifier.VerifyResponse(response);
            return(response);
        }