Help us understand the problem. What is going on with this article?

SlackAPIでuser groupにmentionをとばす

More than 3 years have passed since last update.

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.

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

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away