5
7

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でGoogle Formの入力をSlackにポストする

Last updated at Posted at 2016-08-08

GAS -> Slackに投げる

Google Formからの入力をSlackにポストしたかったのだが、
良さげなサンプルが見つからなかったのでゴニョゴニョして自作。

SendToSlack
function onFormSubmit(e) {

  var itemResponses = e.response.getItemResponses();
  var message = '';

  for (var i = 0; i < itemResponses.length; i++) {
    var itemResponse = itemResponses[i];
    var question = itemResponse.getItem().getTitle();
    var answer = itemResponse.getResponse();
    message += (i + 1).toString() + '. ' + question + ': ' + answer + '\n';
  }

  var url = 'ここにIncoming Webhookのアドレスを入力';
  var data = { "text" : message};
  var payload = JSON.stringify(data);
  var options = {
    "method" : "POST",
    "contentType" : "application/json",
    "payload" : payload
  };

  //slackにポスト
  var response = UrlFetchApp.fetch(url, options);

}
5
7
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
5
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?