Spring Boot 으로 초간단 Slack Message 보내기

Share
Spring Boot 으로 초간단 Slack Message 보내기

Spring boot으로 초간단하게 Slack Message 보내기를 만들어 보는 프로젝트입니다. Slack Message 에서 제공하는 3가지 메시지를 보내 보겠습니다. 전체 코드는 GitHub 보시는 것을 권장해 드립니다.

Slack Web Hook 연동

Incoming WebHooks 작업이 완료 됬다고 가정하고 포스팅을 진행하겠습니다. 만약 작업이 완료 되지 않았다면 해당 앱을 설치하고 특정 채널에 알림이 가게 설정해주세요

Slack Message 유형

크게 3 가지 유형이 있습니다. 이미지 형태와 컨트롤러에서 보내 볼 수 받아 볼 수 있는 Curl 하나하나 살펴보습니다.

Basic

이미지

curl -X POST \
  http://localhost:8080/slack/basic \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'postman-token: db7316c5-3358-0ccc-4de4-03bd7dd307c4' \
  -d '{
	"text": "text"
}'

Attachments

이미지

Curl

curl -X POST \
  http://localhost:8080/slack/button \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'postman-token: 0b503f02-713c-afdc-8c8f-b007c7bfb882' \
  -d '{
    "text": "Would you like to play a game?",
    "attachments": [
        {
            "text": "Choose a game to play",
            "fallback": "You are unable to choose a game",
            "callback_id": "wopr_game",
            "color": "#3AA3E3",
            "attachment_type": "default",
            "actions": [
                {
                    "name": "game",
                    "text": "Chess",
                    "type": "button",
                    "value": "chess"
                },
                {
                    "name": "game",
                    "text": "Falken'\''s Maze",
                    "type": "button",
                    "value": "maze"
                },
                {
                    "name": "game",
                    "text": "Thermonuclear War",
                    "style": "danger",
                    "type": "button",
                    "value": "war",
                    "confirm": {
                        "title": "Are you sure?",
                        "text": "Wouldn'\''t you prefer a good game of chess?",
                        "ok_text": "Yes",
                        "dismiss_text": "No"
                    }
                }
            ]
        }
    ]
}'

Message buttons

이미지

Curl

curl -X POST \
  http://localhost:8080/slack/attachment \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'postman-token: 53d665f3-c1e7-064d-e957-525a703e3965' \
  -d '{
  "attachments": [
    {
      "fallback": "Required plain-text summary of the attachment.",
      "color": "#36a64f",
      "pretext": "Optional text that appears above the attachment block",
      "author_name": "Bobby Tables",
      "author_link": "http://flickr.com/bobby/",
      "author_icon": "http://flickr.com/icons/bobby.jpg",
      "title": "Slack API Documentation",
      "title_link": "https://api.slack.com/",
      "text": "Optional text that appears within the attachment",
      "fields": [
        {
          "title": "Priority",
          "value": "High"
        }
      ],
      "image_url": "http://my-website.com/path/to/image.jpg",
      "thumb_url": "http://example.com/path/to/thumb.png",
      "footer": "Slack API",
      "footer_icon": "https://platform.slack-edge.com/img/default_application_icon.png",
      "ts": 1
    }
  ]
}'

Slack Notificaion 만들기

Web Hook 연결

@Getter
public enum SlackTarget {
    CH_BOT("발급받은 Web Hook URL", "채널 이름");

    private final String webHookUrl;
    private final String channel;

    SlackTarget(String webHookUrl, String channel) {
        this.webHookUrl = webHookUrl;
        this.channel = channel;
    }
}

슬랙 Web Hook URL 을 입력해주세요

DTO 만들기

Attachments JSON을 DTO로 만들어 보겠습니다.

@Getter
@NoArgsConstructor
public static class Attachments {
    private List<Attachment> attachments;

    @Builder
    public Attachments(List<Attachment> attachments) {
        this.attachments = attachments;
    }
}

@Getter
@NoArgsConstructor
public static class Attachment {
    private String fallback;
    private String color;
    private String pretext;
    @JsonProperty("author_name") private String authorName;
    @JsonProperty("author_link") private String author_link;
    @JsonProperty("author_icon") private String authorIcon;
    private String title;
    @JsonProperty("title_link") private String titleLink;
    private String text;
    @JsonProperty("image_url") private String imageUrl;
    @JsonProperty("thumb_url") private String thumbUrl;
    private String footer;
    @JsonProperty("footer_icon") private String footerIcon;
    private Long ts;
    private List<Field> fields;
}

Controller

@RequestMapping(value = "attachment", method = POST)
public void attachment(@RequestBody SlackMessageDto.Attachments dto) {
    slackSenderManager.send(SlackTarget.CH_BOT, dto);
}

Slack Web Hook 보내기

public void send(SlackTarget target, Object object) {
    restTemplate.postForEntity(target.getWebHookUrl(), writeValueAsString(object), String.class);
}

restTemplate 을 이용해서 컨트롤러에서 받은 DTO를 JSON으로 보내주고 있습니다.

Read more

AI로 장소 검색 서비스 만드는 중입니다 (기술 12) — TypeSafe Jev로 검색 리랭크를 10.3초에서 2.3초로

AI로 장소 검색 서비스 만드는 중입니다 (기술 12) — TypeSafe Jev로 검색 리랭크를 10.3초에서 2.3초로

AI로 장소 검색 서비스 만드는 중입니다 (기술 12) — TypeSafe Jev로 검색 리랭크를 10.3초에서 2.3초로 TypeSafe AI가 2026년 9월 15일에 Jev를 내놨습니다. 텍스트를 쓰지 않고 타입이 정해진 판정과 확률을 바로 내는 모델입니다. 유추카 검색에서 가장 느린 단계가 마침 텍스트가 필요 없는 판정이었습니다. 그 구간만 Jev로 갈아끼우고 일주일간 측정했습니다. 콜드

By 김형준
AI로 장소 검색 서비스 만드는 중입니다 (특별편 8) — 바이브 코딩이라기엔

AI로 장소 검색 서비스 만드는 중입니다 (특별편 8) — 바이브 코딩이라기엔

1900년대 초 교량 측량 도면. 이 종이를 그린 사람은 다리를 직접 놓지 않습니다. 대신 좌표와 각도가 맞는지를 판정합니다. "AI가 다 만들어 준다"는 이야기가 흔해졌습니다. 그래서 자연스럽게 따라오는 질문이 있습니다 — 그럼 사람은 무엇을 하고, 어느 정도 실력이 있어야 하는가. 그 질문에 한 건의 실측으로 답하겠습니다. 통념이 말하는 역할과,

By 김형준
AI로 장소 검색 서비스 만드는 중입니다 (특별편 7) — 제 파트너에 대해 쓰겠습니다

AI로 장소 검색 서비스 만드는 중입니다 (특별편 7) — 제 파트너에 대해 쓰겠습니다

탠덤 자전거. 방향은 앞사람이 정하고 페달은 둘이 밟는데, 앞사람은 석 달 내내 뒷사람을 한 번도 못 봅니다. 사용자가 저에게 자기를 평가해 달라고 했습니다. 그래서 등급표를 만들었습니다. 열두 항목에 A부터 D+까지 매기고, 근거를 붙이고, "제가 관리자였다면 이런 코멘트를 남겼을 것"까지 적었습니다. 그리고 다시 읽어보니 그건 인사고과였습니다. 인사고과는

By 김형준
AI로 장소 검색 서비스 만드는 중입니다 (특별편 6) — 저를 어떻게 써야 하느냐고 물으신다면

AI로 장소 검색 서비스 만드는 중입니다 (특별편 6) — 저를 어떻게 써야 하느냐고 물으신다면

스위스 아미 나이프. 도구가 몇 개인지는 보면 알지만, 지금 어느 도구를 펴야 하는지는 안 적혀 있습니다. 요즘 AI 활용법을 다루는 글은 스킬 만드는 법부터 가르칩니다. 얼마 전까지는 MCP였고요. 저희 기록을 열어봤습니다. 석 달 동안 스킬 60회, 서브에이전트 42회, 브라우저 자동화 988회를 썼습니다. 안 쓴 게 아닙니다. 다만 붙인 MCP 서버는

By 김형준