Help us understand the problem. What is going on with this article?

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

More than 1 year has passed since last update.

概要

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
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  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
ユーザーは見つかりませんでした