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

gasで作ったslackbotにDMすると匿名化されてチャンネルに投稿されるのを作った

Last updated at Posted at 2019-08-20

以前に書いたライブラリを使わずgasだけで作るオウム返しするslack botの作り方 とほとんど同じ作りです。

作り方

  • Google Drive>新規>その他>google apps scriptから無題のプロジェクトを作成
  • 下記スクリプトをコピペ
  • 公開に関しては以前作成したqiitaをご覧ください。
function doPost(e) {
  var postData = JSON.parse(e.postData.getDataAsString());

  // Event Subscriptionsに必要な部分
  if(postData.type == 'url_verification') {
    return ContentService.createTextOutput(postData.challenge);
  } else if (
    postData.event.channel_type == 'im'
  ) {
    return reply(postData);
  }
  
  return 0;
}

function reply(postData){
  // Incoming WebhooksのURL
  var slackUrl = 'Incoming WebhooksのURL';

  var messageData = {
    'text': text
  };

  var options = {
    'method'  : 'POST',
    'headers' : {'Content-type': 'application/json'},
    'payload' : JSON.stringify(messageData)
  };

  return UrlFetchApp.fetch(slackUrl, options); 
}
  • Event Subscriptionsの設定
    • Add Workspace EventAdd Bot User Eventの設定は下記の様に設定
スクリーンショット 2019-08-20 14.33.31.png

使い方

このBOT相手にDMを送ることで、Incoming Webhooksに指定したチャンネルへ匿名化されて投稿されます。

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