LoginSignup
0
1

More than 1 year has passed since last update.

定例のミーティングのリンクをSlackに通知した

Posted at

定例のオンラインミーティングで、毎回「Zoomのリンクどこだったかいな?」ってなるのがつらくて、リマインドもかねてslackにリンクを飛ばす機能を作った。ついでに必要な資料のリンクなども送ることができる。

できたこと

  • Slackの特定のチャンネルに必要な情報入りのメンションを飛ばす
  • 文面に画像やボタンをいれる
  • 週一回特定の時間にメンションを飛ばす

前提

  • Zoomのリンクは固定であること

ZoomAPIなどを利用すればいい感じにリンクを取得できるが、今回は固定されているものとしてハードコーディング

URLを取得する

シェルスクリプトを書く

#!/bin/sh
url='https://'
json=`cat slack.json | jq -c`
curl -X POST -H 'Content-type: application/json' --data $json $url

$urlには取得したSlackのURLをいれる

url='https:'

$jsonには取得した--dataオプションに渡すjsonをslack.jsonファイルから取得する。jq -cでは、フォーマットされたjsonをいい感じに1行にすることができる。

このjson変数に渡される値によって、slackに通知されるメッセージの内容を加工することができる。MarkDownを書いたり、画像を乗せたり、ボタンを設置したりはここで設定する。

json=`cat slack.json | jq -c

curlコマンドを使って、slackへリクエストを送る。

curl -X POST -H 'Content-type: application/json' --data $json $url

jsonを作成する

--dataオプションへ渡すjsonを作成する。

中身の説明や、プレビューなどは以下から詳細を確認することができる。

{
  "blocks": [
    {
      "type": "header",
      "text": {
        "type": "plain_text",
        "text": "13時から全体ミーティングです",
        "emoji": true
      }
    },
    {
      "type": "section",
      "text": {
        "type": "mrkdwn",
        "text": "全体ミーティングの時間です。参加しましょう:loudspeaker:"
      },
      "accessory": {
        "type": "image",
        "image_url": "https://1.bp.blogspot.com/-PgPpfoGDxF0/WcB5sfrVQSI/AAAAAAABG1o/xGjjAfsxv_UddA_63hydv1M46uL0b4KHACLcBGAs/s800/kaigi_man_woman.png",
        "alt_text": "image"
      }
    },
    {
      "type": "actions",
      "elements": [
        {
          "type": "button",
          "text": {
            "type": "plain_text",
            "text": "Zoomに参加",
            "emoji": true
          },
          "url": ""
        },
        {
          "type": "button",
          "text": {
            "type": "plain_text",
            "text": "議事録",
            "emoji": true
          },
          "url": ""
        },
        {
          "type": "button",
          "text": {
            "type": "plain_text",
            "text": "案件管理表",
            "emoji": true
          },
          "url": ""
        }
      ]
    }
  ]
}

cronを設定する

cronは各々の環境でいい感じに設定してください。

$ crontab -e

crontab -lで確認する。

50 12 * * 1 ./meetingNotification.sh
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