3
Help us understand the problem. What are the problem?

More than 3 years have passed since last update.

posted at

updated at

GASでesaのwebhookを拾ってslackに飛ばそう!

概要

esaでslack連携をした時にメンションがactiveにならなくて困ったのでサクッとGASで作りました。

本編

GASの設定

var slack = {
  webhook: '', // Slackのwebhook
}

//esaからのpost
function doPost(e) {
  var params = JSON.parse(e.postData.getDataAsString());

  // mention分岐
  if(params.kind == "comment_mention") {
    var slack_post_data = {
      "text": params.user.name + "がメンションコメントしました。\n" + params.comment.body_md + "\n" + params.post.url,
      "link_names" : 1
    };
  }else{
     var slack_post_data = {
      "text": "esaでなにかが起こった、詳細は@dasisyouyuにきいて。"
    };
  }

  var payload = JSON.stringify(slack_post_data);

  var options = {
    "method" : "post",
    "contentType" : "application/json",
    "payload" : payload
  };

  //slack webhookへpost
  UrlFetchApp.fetch(slack["webhook"], options);
}

esaの設定

team設定のwebhookからGenericを選択し先程作ったGASのwebhookを設定しよう!

slackの設定

Incoming Webhooksを作成してできたwebhookURLをGASに貼っておく

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Sign upLogin
3
Help us understand the problem. What are the problem?