ボタンを押された際の処理の追加
GASプロジェクトの作成と設定
手順1
Google Drive 内の空いているスペースで右クリックし、「その他」から「Google Apps Script」を選択し、GASプロジェクトを作成する。
Slack のメッセージのボタンが押された際の処理を記述するGASプロジェクトは必ず Google Drive 内に単体で存在しなければならない。
![](https://tsubasamusu.com/wp-content/uploads/2023/07/image-42.png)
手順2
作成したプロジェクト開いた後、左の「ライブラリ」の「+」を押し、「ライブラリの追加」内の「スクリプトID」に「1on93YOYfSmV92R5q59NpKmsyWIQD8qnoLYk-gkQBI92C58SPyA2x1-bq」と入力し、「検索」を押す。
![](https://tsubasamusu.com/wp-content/uploads/2023/07/image-32-1024x597.png)
手順3
「バージョン」を最も大きい数字(今回は22)に設定して、右下の「追加」を押す。
![](https://tsubasamusu.com/wp-content/uploads/2023/07/image-33.png)
手順4
適切なコードを記述し、上の「実行」を押す。
![](https://tsubasamusu.com/wp-content/uploads/2023/07/image-44-1024x477.png)
手順5
下の画像を参考にして権限を承認する。
![](https://tsubasamusu.com/wp-content/uploads/2023/07/image-36.png)
![](https://tsubasamusu.com/wp-content/uploads/2023/07/image-37.png)
![](https://tsubasamusu.com/wp-content/uploads/2023/07/image-38.png)
![](https://tsubasamusu.com/wp-content/uploads/2023/07/image-39.png)
![](https://tsubasamusu.com/wp-content/uploads/2023/07/image-40.png)
Slack への GAS プロジェクトの登録
手順6
右上の「デプロイ」から「新しいデプロイ」を押す。
![](https://tsubasamusu.com/wp-content/uploads/2023/07/image-45.png)
手順7
「種類の選択>歯車マーク」から「ウェブアプリ」を押す。
![](https://tsubasamusu.com/wp-content/uploads/2023/07/image-46.png)
手順8
「アクセスできるユーザー」を「全員」に設定し、右下の「デプロイ」を押す。
![](https://tsubasamusu.com/wp-content/uploads/2023/07/image-47.png)
手順9
「新しいデプロイ>ウェブアプリ>URL」の「コピー」を押して、URLをコピーした後、右下の「完了」を押す。
![](https://tsubasamusu.com/wp-content/uploads/2023/07/image-49.png)
手順10
Slack API に行き、ボタン付きメッセージを送信したボット(今回は「テスト用ボット」)を選択する。
![](https://tsubasamusu.com/wp-content/uploads/2023/07/image-50-1024x551.png)
まだボットを作成していない場合は下の記事を参考にしてボットを作成する。
手順11
「Interactivity & Shortcuts」に行き、「Interactivity」を「ON」にし、「手順9」でコピーしたURLを「Request URL」に貼り付け、右下の「Save Changes」を押す。
![](https://tsubasamusu.com/wp-content/uploads/2023/07/image-51-1024x590.png)
デバッグ
手順12
Slack のボタンをを押した際に処理が走る事を確認する。
![](https://tsubasamusu.com/wp-content/uploads/2023/07/image-52.png)