LoginSignup
0
1

シェルスクリプトからSlackにメッセージを送る

Posted at

シェルスクリプトからSlackへのメッセージを送る手法になります。
すぐできるので所要時間としては15分あればいけると思います。

事前注意

現在(2024年4月6日現在)、Slackでのカスタムインテグレーションは非推奨となっています。
以下のようなカスタムインテグレーションがありましたが、新しい機能がなく将来的には非推奨となり廃止される可能性があるので、今回はSlack Appを使用します。

  • Incoming Webhook: 外部からSlackにメッセージを投稿できる
  • Outgoing Webhook: Slackメッセージを外部に送信できる
  • Bots
  • Slash Commands

Using legacy custom integrations is an outdated way for teams to integrate with Slack. Legacy custom integrations lack newer features and will be deprecated and possibly removed in the future. We do not recommend their use.

準備

1. Slack Appの作成

Slack Appを作成し、Webhookを利用してSlackへの投稿を行います。
以下のクイックスタートドキュメントを参考に設定していきます。

Go to Your AppsからSlack Appを作成し、書いてある順番の通りに設定をします。

image.png

Incomming Webhooks > Activate Incoming WebhooksをONにし、Add New Webhook to Wordspaceから通知したいチャンネルのWebhookを作成します。

Capture-2024-04-07-100929.png

2. Slack通知テキストを作成

Slackに送信するメッセージのテキストを作成します。JSON形式で記述しますが、SlackのBlock Kit Builderを使用すると簡単に作成できます。

image.png

実装

以下のcurlコマンドを使用して、curlリクエストを送信します。

  • JSONテキスト
  • Webhook URL

を作成したものに変えていただければ問題ないです。

$ curl -X POST -H 'Content-type: application/json' --data JSONテキスト WebhookURL

参考

0
1
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
0
1