webhook를 이용해서 curl 명령어로 슬랙에 메시지 보내는 방법이다.
명령어로 메시지를 보낼 수 있으면 여러가지 스크립트에 해당 명령어를 포함시켜 자동 메시지를 보내는 것이 가능하다.
1. 슬랙에 로그인된 상태에서 아래 링크에서 새 app를 생성한다.
https://api.slack.com/apps?new_app=1
2. From scratch 클릭
3. App 이름과 메시지를 전달할 workspace를 선택한다. app이름은 메시지가 발송되었을 때 메시지를 쓴사람 이름이 된다.
curl -X POST -H 'Content-type: application/json' --data '{"text":"Hello, World!"}' https://hooks.slack.com/services/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
10. 아래 링크로 가면 다양한 양식으로 메시지를 보낼 수 있도록 json 예시가 나와있다.
https://app.slack.com/block-kit-builder
예를 들어, json-test라는 파일을 만들어 아래 내용을 저장한다.{
"blocks": [
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "This is a mrkdwn section block :ghost: *this is bold*, and ~this is crossed out~, and <https://google.com|this is a link>"
}
}
]
}
그리고 아래명령어를 치면,
curl -X POST -H 'Content-type: application/json' -d @json_test https://hooks.slack.com/services/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
0 댓글