LoginSignup
52
29

More than 5 years have passed since last update.

SlackAPIでuser groupにmentionをとばす

Posted at

Slackには、チャンネルとは別で、ユーザーグループを作る機能があります。

参考:SlackがUser Groups機能を追加、所属チャネルに関係なく「@engineers」などで対象者全員にメッセージ - THE BRIDGE(ザ・ブリッジ)

APIからだと、@hoge-group のように単に@をつけただけではメンションを送れません。

正しくメンションを送る方法を紹介します。なお、動作確認はnode-slackで行いました。

user group のIDを調べる

  1. usergroups.list method | Slack からusergroups.listAPIを叩く
    • tokenがない場合は、上部にメッセージが出てると思うので、リンクをクリックして、tokenを取得してください。
  2. メンションを送りたいグループのIDを取得する
    • idとteam_idの2つがありますが、idの方が正しいです

messageをつくる

slack.send({
    text: `Hello <!subteam^取得したID|グループ名> !`,
    channel: config.SLACK_CHANNEL
});

という感じで、取得したIDとグループ名をいれてください。

参考:user groups

For paid teams there is an additional command for user groups that follows the format <!subteam^ID|handle>. These indicate a user group message, and should cause a notification to be displayed by the client. User group IDs can be determined from the usergroups.list API endpoint.

これでメンション飛ばせます!

52
29
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
52
29