SLACK API 호출 규격
플랫폼 서버에서 SLACK API를 호출하여 해당 채널에 메시지를 다이렉트로 전송
POST https://api.slack.com/api/chat.postMessage
- headers {"Authorization": f"Bearer {SLACK_BOT_TOKEN}", "Content-Type": "application/json"}
- SLACK_BOT_TOKEN = ""
- 만든 슬랙봇의 토큰을 입력
- Request body (application/json)
{
"channel": CHANNEL_ID,
"text": message,
"blocks": [{....}]
}
- channel (string) : 메시지 전송 대상 채널 ID
- text (string) : 메시지 보낼 내용
- blocks (list) : 메시지 디자인 + 내용
- payload 예시
payload = {
"channel": CHANNEL_ID,
"text": message,
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Hello, this is a block message!"
}
}
]
}
- Response body (application/json)
- Success
- status code : 200
{
'ok': True,
'channel': '',
'ts': '',
'message': {
'bot_id': '',
'type': 'message',
'text': 'Hello, this is a block message!',
'user': '',
'ts': '',
'app_id': '',
'blocks': [
{
'type': 'section',
'block_id': 'HjEj',
'text': {
'type': 'mrkdwn',
'text': 'Hello, this is a block message!',
'verbatim': False
}
}
],
'team': '',
'bot_profile': {
'id': '',
'app_id': '',
'name': '',
'icons': {
'image_36': 'https://a.slack-edge.com/80588/img/plugins/app/bot_36.png',
'image_48': 'https://a.slack-edge.com/80588/img/plugins/app/bot_48.png',
'image_72': 'https://a.slack-edge.com/80588/img/plugins/app/service_72.png'
},
'deleted': False,
'updated': ,
'team_id': ''
},
'warning': 'missing_charset',
'response_metadata': {
'warnings': ['missing_charset']
}
}
}
- Error
# 채널ID가 올바르지 않은 경우
{
'ok': False,
'error': 'channel_not_found',
'warning': 'missing_charset',
'response_metadata': {'warnings': ['missing_charset']}
}
# 토큰이 유효하지 않는 경우
{
'ok': False,
'error': 'invalid_auth',
'warning': 'missing_charset',
'response_metadata': {'warnings': ['missing_charset']}
}
'다양한 활동 > 인턴' 카테고리의 다른 글
[인턴] Slack Bot 만들기 (6) : 슬랙봇 배포 후 사용 (0) | 2023.11.19 |
---|---|
[인턴] Slack Bot 만들기 (5) : SLACK BLOCK KIT 퍼블리싱 적용 (0) | 2023.08.30 |
[인턴] Slack Bot 만들기 (2) : 로컬 서버 외부 접근 환경 구성 (0) | 2023.07.21 |
[인턴] Slack Bot 만들기 (1) : Slack App (0) | 2023.07.19 |
[인턴] devops-backend 배운 내용 (6) API 설계 및 구현 (0) | 2023.07.05 |