7
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

GAS から Slack に投稿するシンプルなコード(incoming webhooks)

Last updated at Posted at 2017-09-28

GAS から Slack に投稿するコードです。 incoming webhooks を用いているので、GAS から Slack に一方向にしか送れません。

GAS から Slack に投稿するコード

function main() {
   postMessage('gas から slack に投稿', 'https://hooks.slack.com incoming web hook のエンドポイント')
}

function postMessage(message, hookPoint) {
  var payload = {
    "text": message,
    "icon_emoji": ':sparkles:',
    "username": 'bot'
  }
  var options = {
    "method" : "POST",
    "payload" : JSON.stringify(payload),
    "headers": {
      "Content-type": "application/json",
    }
  }
  var response = UrlFetchApp.fetch(hookPoint, options);

  if (response.getResponseCode() == 200) {
    return response;
  }
  return false;
}

注意点

参考

7
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?