LoginSignup
221
157

More than 5 years have passed since last update.

SlackのIncoming Webhooksでメンションを飛ばす方法

Last updated at Posted at 2017-05-17

前段

SlackのIncoming Webhooksでは text パラメーターに "@channel Hello" 等と書いてもそのままテキストになってしまい正しいメンションとならない。

記法

記法 メンション
<!here> @here
<!channel> @channel
<@user_id> @ChiyodaTarou

user_id の取得方法

ユーザープロフィールの中にある折りたたまれた部分を開いたところにある Copy number ID です。

まとめて取得したい場合は @gimKondo さんが書かれた こちらの記事を参考にされると良いでしょう

スクリーンショット 2018-08-28 15.40.09.png

例1

チャンネルの全員にソフトクリームくんがメンションで挨拶する

slack.sh
#!/bin/bash

PAYLOAD=`cat << EOS
    payload={
        "channel": "#general",
        "username": "softcream",
        "text": "<!channel> Hello, channel!",
        "icon_emoji": ":poop:"
    }
EOS`

curl -X POST --data-urlencode "$PAYLOAD" https://hooks.slack.com/services/QWEERTY/YTREWQ/ASDFGHJKL

14.png

例2

attachmentsでも同様です

slack-attachments.sh
#!/bin/bash

PAYLOAD=`cat << EOS
    payload={
        "channel": "#general",
        "username": "softcream",
        "attachments": [{
            "color": "#0000FF",
            "title": "I am softcream",
            "text": "<!channel> Hello, channel!"
        }],
        "icon_emoji": ":poop:"
    }
EOS`

curl -X POST --data-urlencode "$PAYLOAD" https://hooks.slack.com/services/QWEERTY/YTREWQ/ASDFGHJKL

スナップショット15.png

補足

ソフトクリームは和製英語であり、英語では"soft serve ice cream"というそうです。
参考資料

221
157
4

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
221
157