4
2

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.

KibelaからLineに通知する

Posted at

手順

  • LineNotifyからtokenを発行する
  • GoogleAppsScriptで以下を作成してtokenを張り付ける
  • GoogleAppsScriptで発行されたアプリケーションのURLをKibelaのここで設定する
var postUrl = "https://notify-api.line.me/api/notify";
var token = "line側で発行して張り付ける";

function doPost(e){
  
  var json = e.postData.getDataAsString();
  var params = JSON.parse(json);
  
  // 新規、更新、削除
  var actionType = params["action"];
  // ブログ、WIKI、コメント
  var resourceType = params["resource_type"];
  // 実行した人の名前
  var name = params["action_user"]["account"];
  // URL
  var url = params[resourceType]["url"];
  // 通知メッセージ
  var message = "";
  
  // wikiの更新は頻繁にあるし削除は見なくても良さそうなので
  // 新規以外は通知しない
  if(actionType != "create"){
    
    return;
    
  }
  
  message = resourceType + "" + actionToJapanese(actionType)  + "\n" + name + "\n" + url;
  
  var options =
  {
    "method"  : "post",
    "payload" : "message=" + message,
    "headers" : {"Authorization" : "Bearer "+ token}
  };

  // lineに投げる
  UrlFetchApp.fetch(postUrl,options);
}

function actionToJapanese(actionType){
  switch(true){
    case actionType == "create":
      return "投稿";
      
    case actionType == "update":
      return "更新";
      
    case actionType == "delete":
      return "削除";
  }
}

参考

KibelaのwebhoockDoc
https://docs.kibe.la/api-documents/japanese/outgoing-webhook
Kibelaの投稿をSlackに通知する
https://qiita.com/yakimeron/items/5e2414c80947a68b6b52

4
2
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
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?