티스토리 뷰
1. Slack 자체설정
1. 앱 만들기
2. Bots 선택
3. 좌측 OAuth & Permissions 클릭
4. Token 복사
5. 토큰 범위 쓰기 까지 설정
6. 알림을 보내고자 하는 채널 우클릭
우클릭을 하면 링크 복사가 있는데 거기에서
https:/testtest.slack.com/test/C234KDSF932DF
C234KDSF932DF이 부분이 채널이다.
2. 스프링 부트
1. application.yml
slack:
token: xoxb-????????????????????????????????????????????
channel:
monitor: ???????????
와 같이 저장을 하자. 각 자신의 토큰과 채널을 넣어주면 된다.
2. AlertService.java
@Service
@Slf4j
public class AlertService {
@Value(value = "${slack.token}")
String token;
@Value(value = "${slack.channel.monitor}")
String channel;
public void slackSendMessage(String message){
try{
Slack slack = Slack.getInstance();
slack.methods(token).chatPostMessage(req -> req.channel(channel).text(message));
} catch (SlackApiException | IOException e) {
log.error(e.getMessage());
}
}
}
필자는 다음과 같이 서비스로 사용하여 필요한 곳에 가져다 쓰는 방식으로 구현하였다.
위의 sentryWithSlackMessage는 slack과 sentry 결합하여 쓴 것으로 기본적으로 위에 존재하는 코드 내용이 포함되어 있다고 생각하면 된다.
결과는 성공!
참고: https://slack.dev/java-slack-sdk/guides/web-api-basics
API Client Basics | Slack SDK for Java
API Client Basics slack-api-client contains simple, easy-to-use, and flexibly configurable HTTP clients for making requests to Slack APIs. Before trying the samples on this page, you need to set up your Java project first. If you haven’t done it yet, che
slack.dev
https://suzxc2468.tistory.com/197
JAVA로 Slack API를 활용한 알림봇[자동알림] 설정하기 (feat. chat.postMessage)
#개요 IT업계 뿐만아니라 일반적인 기업도 요즘은 필수로 사용되는 생산성 툴 중 전사적인 협업툴로 불리는 Slack이 몹시 유명하다. 이러한 Slack에는 트랜드에 맞게 유용한 API를 몹시 많이 제공해
suzxc2468.tistory.com
GitHub - YAPP-19th/iOS-Team-1-Backend
Contribute to YAPP-19th/iOS-Team-1-Backend development by creating an account on GitHub.
github.com
'JVM > Spring' 카테고리의 다른 글
[JAVA][Spring][dirty checking] 준영속 엔티티 대해서 (0) | 2021.12.09 |
---|---|
[JPA] JPA N+1 문제 (0) | 2021.12.03 |
[Spring Boot] [Jpa] [PrePersist] default 값 설정하기 (0) | 2021.10.15 |
[Spring] JPA (0) | 2021.10.09 |
[스프링] [WAS] [Web Server] (0) | 2021.09.30 |
- Total
- Today
- Yesterday
- django
- DRF
- BFS
- 2021 KAKAO BLIND RECRUITMENT
- env
- 자바
- 그래프
- 알고리즘
- 면접
- Linux
- Python
- 백준
- thread
- Pattern
- 파이썬
- setattr
- Spring
- docker-compose
- headers
- Command Line
- 카카오
- Java
- postgres
- ubuntu
- PostgreSQL
- dockerignore
- Collections
- Celery
- docker
- 프로그래머스
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |