[Slack ์—ฐ๋™] ํŠน์ • ์ฑ„๋„์— ๋ฉ”์‹œ์ง€ ์ „์†ก
๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๋””์ง€ํ„ธ ๊ฟ€ํŒ

[Slack ์—ฐ๋™] ํŠน์ • ์ฑ„๋„์— ๋ฉ”์‹œ์ง€ ์ „์†ก

by ์ผ์ƒ์„ ๊ณต์œ ํ•ฉ๋‹ˆ๋‹ค 2022. 2. 3.

ํ˜‘์—… ์„œ๋น„์Šค ์Šฌ๋ž™์—๋Š” webhooks ๋ผ๋Š” ๊ธฐ๋Šฅ์ด ์žˆ๋‹ค. ํž˜๋“ค๊ฒŒ API๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ , ์ข€ ๋” ๊ฐ„ํŽธํ•˜๊ฒŒ ๋ฉ”์‹œ์ง€ ์ „๋‹ฌ์„ ํ•  ์ˆ˜ ์žˆ๋‹ค. ๋‹ค๋งŒ, ํŒŒ์ผ ์ „์†ก์ด๋‚˜ ๊ทธ๋Ÿฐ๊ฑด ์•ˆ๋œ๋‹ค. ๊ทธ๋Ÿฐ ๊ธฐ๋Šฅ์„ ํ™œ์šฉํ•˜๋ ค๋ฉด API๋กœ ํ•ด์•ผํ•œ๋‹ค.

Slack Application > Incoming Webhooks ์„ค์ •

๋จผ์ € ๋„ˆ์˜ Apps์„ ์ƒ์„ฑํ•ด์•ผ ํ•œ๋‹ค. ์˜ค๋ฅธ์ชฝ ์ƒ๋‹จ์— ์žˆ๋Š” create new app์„ ํด๋ฆญํ•˜์—ฌ ์•„๋ž˜์™€ ๊ฐ™์ด app์„ ๋งŒ๋“ค์–ด๋ณธ๋‹ค. ํ•ด๋‹น ๊ธฐ๋Šฅ์„ ํ†ตํ•ด ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด๋‚ผ ๋•Œ ์•ฑ์˜ ์•„์ด์ฝ˜ ๋ฐ App name ์œผ๋กœ ๋ฉ”์‹œ์ง€๊ฐ€ ๋ฐœ์†ก๋œ๋‹ค.
๋งํฌ 1 : https://api.slack.com/apps

incoming webhooks์— ๋“ค์–ด๊ฐ€์„œ ๊ธฐ๋Šฅ์„ ON์œผ๋กœ ํ™œ์„ฑํ™” ํ•ด์•ผ ํ•œ๋‹ค. ๊ทธ๋ž˜์•ผ ํ•ด๋‹น ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉ ํ•  ์ˆ˜ ์žˆ๋‹ค. ๊ทธ๋Ÿฌ๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด webwhooks URL์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.  sample๋กœ ๋ช…๋ น์–ด ์ณ์„œ ๋ฉ”์‹œ์ง€ ๋‚ ๋ผ๊ฐ€๋Š”๊ฒƒ๋„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. 100๋…„์ด ์ง€๋‚˜๋„ hello world ๋ฉ”์„ธ์ง€๋Š” ๋ณ€ํ•จ์ด ์—†๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.


๋งํฌ 2 : https://api.slack.com/apps/xxxxxxxx/incoming-webhooks?

 

Google App Script ์‚ฌ์šฉํ•˜์—ฌ ํŠน์ • ์ฑ„๋„์— Msg ์ „์†ก

function sendSlackMsg(msg){

  var url = "https://hooks.slack.com/services/xxxxxxxxxx";

  const params = {
    method: "post",
    contentType: "application/json",
    payload: JSON.stringify({
      "text": String(msg)
    }),
    muteHttpExceptions: true
  }
  const sendMsg = UrlFetchApp.fetch(url, params);
  var responseJson = JSON.parse(response.getContentText());

  return responseJson;
}

 

๋‹จ, webhook ์™ธ์— ์ผ๋ถ€๊ธฐ๋Šฅ์—๋Š” ๋ผ์ด์„ ์Šค ๋ณ„๋กœ ๊ธฐ๋Šฅ์ด ์ œํ•œ๋˜์–ด ์žˆ๋‹ต๋‹ˆ๋‹ค. ์ €๋Š” ์ด์ œ ํ”„๋ฆฌ๋žœ์„œ์ด๊ธฐ๋•Œ๋ฌธ์— ์ด๊ฑด ์กฐ๊ธˆ ์•„์‰ฝ๊ธด ํ•˜์ง€๋งŒ , ๋‹ค๋ฅธ ์‚ฌ๋žŒ์˜ ์ •๋ณด๋ฅผ ๋„์›€๋ฐ›์•„ ์ž‘์—… ํ•ด์•ผํ•  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค ๐Ÿฅบ  ๋‚˜์ค‘์— ์ •๋ณด๋ ฅ์ด ๊ฐ•ํ•ด์ง€๋ฉด, ๊ทธ๋•Œ๋Š” ๊ตฌ๋งคํ• ์ง€ ์ƒ๊ฐํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

๋Œ“๊ธ€