<目次>
(1) Slackでコマンドを作る方法をご紹介(自作スラッシュコマンド)
(1-0) やりたいこと
(1-1) STEP1:Slackボットの開発(所要時間:60分)
(1-2) STEP2:Slack AppにSlash Commandsの設定を追加(所要時間:10分)
(1-3) STEP3:Pythonプログラムに「/demo」が呼ばれた時の処理を追記(所要時間:5分)
(1-4) STEP4:疎通テスト(所要時間:5分)
(1) Slackでコマンドを作る方法をご紹介(自作スラッシュコマンド)
(1-0) やりたいこと

(1-1) STEP1:Slackボットの開発(所要時間:60分)
Slackで発生するイベント(例:チャンネル投稿)を検知し、動作するSlack App(ボット)を作成します。
(1-2) STEP2:Slack AppにSlash Commandsの設定を追加(所要時間:10分)


入力項目 | 例 |
Command | /demo |
Request URL | https://slack-howto-create-command.azurewebsites.net/demo |
Short Description | コマンドの作り方をデモする用 |
(図123①)

(表2)
入力項目 | 補足 |
Command | 利用者が打つコマンド |
Request URL | 利用者が打つコマンドのリクエスト送付先。 Event Subscriptionsに指定したURL(図123③)と合わせる。 これにより、コマンドが「/slack/events」にルーティングされ、リクエストハンドラにHTTPのPOSTリクエストが送られ、適切な先(今回は「@s_app.command(‘/demo’)」にディスパッチしてくれます) #イベント登録されたリクエストを受け付けるエンドポイント |
Short Description | 利用者がコマンドを打つ際の候補に出てくる説明文 |




(1-3) STEP3:Pythonプログラムに「/demo」が呼ばれた時の処理を追記(所要時間:5分)
# SlackBoltインスタンスで、コマンド「/demo」の実行を検知 @s_app.command('/demo') def demo(ack, respond, command): ack() # 投稿のチャンネルID、ユーザーID、投稿内容を取得 channel_id = command['channel_id'] user_id = command['user_id'] text = command['text'] # # もしボット以外の人からの投稿だった場合 if BOT_USER_ID != user_id: # 指定のメッセージを組み立て reply_text = ":small_blue_diamond::small_blue_diamond::small_blue_diamond:コマンド出力結果:small_blue_diamond::small_blue_diamond::small_blue_diamond:\r\n:earth_asia:他の方も/demoから使えます:+1:" # 指定のメッセージを返却 respond(reply_text) # 正常応答を返却 return Response(), 200

↓
・②Azure App Serviceへ再度リリースします。
(図132)
