Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 | 31 |
Tags
- vm
- cloud armor
- direnv
- cicd
- vpc peering
- cloud
- 우테캠
- devops
- 후기
- Uptime Check
- Python
- Java
- github
- IAM
- AWS
- docker
- pub/sub
- gcp
- VAGRANT
- Terraform Cloud
- terraform
- 자격증
- cloud function
- Clean Code
- kubernetes
- MIG
- Google Cloud Platform
- interconnect
- 보안 규칙
- CentOS
Archives
- Today
- Total
EMD Blog
Slack API App 작성 및 수신 Webhook 설정 본문
반응형
특정 서비스를 사용 할 때 Slack으로 알림을 받고 싶다면 수신 Webhook을 만들어 사용하면 된다.
매니페스트를 사용한 App 생성
수신 Webhook을 사용하려면 App을 생성해야 한다. App 생성은 이 페이지로 가서 UI로 생성해도 되지만 Slack의 매니페스트(Slack App 전용 YAML or Json 형식의 구성)를 사용해 생성 할 수도 있다. 매니페스트를 사용하더라도 UI로 등록 할 수 있으며 아래 예시는 API를 사용해 진행한다.
API를 사용해 매니페스트를 적용하려면 token이 필요하다. token은 API로 발급 받을 수 없기 때문에 아래 URL로 접근해서 직접 생성해줘야 한다.
https://api.slack.com/apps?new_app=1
이 토큰은 12시간 마다 만료되며 아래 API를 사용해 refresh 해주어야 한다.
curl -X GET "<https://slack.com/api/tooling.tokens.rotate?refresh_token=>" \\
-H "Content-Type: application/x-www-form-urlencoded"
<refresh_token> token 설정에서 복사 할 수 있다.
token을 생성했으면 매니페스트를 생성 한다. (스키마 구조 정보)
cat <<EOF > manifest.json
{
"display_information": {
"name": "terraform-demo"
},
"features": {
"bot_user": {
"display_name": "terraform-demo",
"always_online": false
}
},
"oauth_config": {
"scopes": {
"bot": [
"incoming-webhook"
]
}
},
"settings": {
"org_deploy_enabled": false,
"socket_mode_enabled": false,
"token_rotation_enabled": false
}
}
EOF
매니페스트를 생성했으면 아래 API를 사용해 앱을 생성하면 된다.
curl -X POST "<https://slack.com/api/apps.manifest.create>" \\
-H "Content-Type: application/json" \\
-H "Authorization: Bearer " \\
-d "{'manifest':'`(cat manifest.json)`'}"
마지막으로 앱 목록으로 이동해
생성한 앱 → Features → Incoming Webhooks → Add New Webhook to Workspace를 클릭한다.
그럼 채널에 앱이 추가되고 Webhook URL이 생성된다.
추가로 기존에 사용 중인 매니페스트를 내보낼 수도 있다. 앱에서 매니페스트 내보내려면 export API 사용한다.
curl -X POST "<https://slack.com/api/apps.manifest.export>" \\
-H "Content-Type: application/json" \\
-H "Authorization: Bearer " \\
-d '{"app_id":""}'
만약 manifest만 뽑아오고 싶다면 jq라이브러리를 사용하면 된다.
curl -X POST "<https://slack.com/api/apps.manifest.export>" \\
-H "Content-Type: application/json" \\
-H "Authorization: Bearer " \\
-d '{"app_id":""}' | jq .manifest
반응형