노출되는 이미지가 불편하시겠지만 양해를 구합니다. 노출, 클릭등에 관한 자료로 활용 중입니다.

Java Spring + Slack Web Hook API



슬랙으로 메시지를 보내기



1. 슬랙에서 채널을 생성


2. 원하는 채널을 선택하고, 접근API를 생성


- 메뉴 : https://my.slack.com/services/new/incoming-webhook/

- 설명 : api.slack.com -> incoming webhooks




3. 연동(Java) 모듈 생성



  String hooksSlack = "https://hooks.slack.com/services/xx/yy/zz";


CloseableHttpClient client = HttpClients.createDefault();

HttpPost httpPost = new HttpPost(hooksSlack);


String message = " " ;

String json = "{ \"text\": \""+ message.toString() + "\" }";

StringEntity entity = new StringEntity(json);

httpPost.setEntity(entity);

httpPost.setHeader("Accept", "application/json");

httpPost.setHeader("Content-type", "application/json");

CloseableHttpResponse response = client.execute(httpPost);

log.error("getStatusCode : " + response.getStatusLine().getStatusCode() );

//assertThat( response.getStatusLine().getStatusCode(), equalTo(200) );

client.close();



- 실행 결과 (샘플)




# Spring Slack Integration


http://wooriworld2006.tistory.com/382



# POST with JSON


http://www.baeldung.com/httpclient-post-http-request



# Webhook URL 


https://stackoverflow.com/questions/37423129/slack-incoming-web-hook-and-getting-it-to-work-with-httppost

블로그 이미지

StartGuide

I want to share the basic to programming of each category and how to solve the error. This basic instruction can be extended further. And I have been worked in southeast Asia more than 3 years. And I want to have the chance to work another country.

,