Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
3
Help us understand the problem. What is going on with this article?
@dasisyouyu

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に貼っておく

3
Help us understand the problem. What is going on with this article?
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.
Sign Up
If you already have a Qiita account Login
3
Help us understand the problem. What is going on with this article?