Skip to content

Instantly share code, notes, and snippets.

@zpapez
Last active November 20, 2020 21:05
Show Gist options
  • Save zpapez/c20235322f46603f48b9a2d5b75dc704 to your computer and use it in GitHub Desktop.
Save zpapez/c20235322f46603f48b9a2d5b75dc704 to your computer and use it in GitHub Desktop.
SlackFeignClient
@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);
}
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