top / index / prev / next / target / source
日記形式でつづる いがぴょんコラム ウェブページです。
import java.io.IOException;
import java.net.URI;
import org.springframework.http.RequestEntity;
import org.springframework.web.client.RestTemplate;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
public class SimpleSlackIncomingWebhook {
private static final String SLACK_INCOMING_WEBHOOK
= "https://hooks.slack.com/services/TXXXXXXXX/BXXXXXXXX/FXXXXXXXXXXXXXXXXXXXXXXv";
@JsonSerialize
static class SimpleSlackIncoming {
public String channel = "#general";
public String username = "webhook.bot";
public String text = "これはシンプルな Slack へのメッセージ投げ込みです。";
public String icon_emoji = ":ghost:";
}
public static void main(String[] args) throws IOException {
SimpleSlackIncoming incoming = new SimpleSlackIncoming();
// 送信データを JSONテキスト化
final ObjectMapper mapper = new ObjectMapper();
final String incomingJson = "payload=" + mapper.writeValueAsString(incoming);
// API 呼び出し
RequestEntity<?> req = RequestEntity //
.post(URI.create(SLACK_INCOMING_WEBHOOK)) //
.header("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8") //
.body(incomingJson);
new RestTemplate().exchange(req, String.class);
}
}
めっきり夏を感じさせる春の今日この頃。
Last modified: $Date: 2019-05-16 $