Last active
November 20, 2020 21:05
-
-
Save zpapez/c20235322f46603f48b9a2d5b75dc704 to your computer and use it in GitHub Desktop.
SlackFeignClient
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@FeignClient(name = "Slack", url = "${slack.baseUrl}", configuration = SlackFeignClientConfiguration.class) | |
public interface SlackFeignClient { | |
@RequestMapping( | |
value = "/chat.postMessage", | |
method = RequestMethod.POST, | |
consumes = "application/json", | |
produces = "application/json") | |
SlackMessageResponseDto postSlackMessage( | |
@RequestBody(required = true) SlackMessageRequestDto messageRequest); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.springframework.beans.factory.annotation.Value; | |
import org.springframework.context.annotation.Bean; | |
import feign.RequestInterceptor; | |
import feign.RequestTemplate; | |
public class SlackFeignClientConfiguration { | |
@Value("${slack.app.oauth.accessToken}") | |
private String slackOauthAccessToken; | |
@Bean | |
public RequestInterceptor bearerTokenRequestInterceptor() { | |
return new RequestInterceptor() { | |
@Override | |
public void apply(RequestTemplate template) { | |
template.header("Authorization", | |
String.format("Bearer %s", slackOauthAccessToken)); | |
} | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment