LoginSignup
41
27

More than 5 years have passed since last update.

Slack APIでユーザー宛のメンションができなくなったので対策した

Last updated at Posted at 2017-09-12

あるアクションに対して、API経由でユーザー宛にメンションする仕組みを動かしていたのですが、本日突然メンションされない(Slackアプリ上でリンクがつかず、通知も飛ばない)状態になりました。

curl -XPOST -d "token=TOKEN" -d 'channel=channellname' -d "text=<@username> こんにちは"  -d 'as_user=true' 'https://slack.com/api/chat.postMessage' >&/dev/null

どうやらSlack APIに仕様変更があったらしい。
https://api.slack.com/changelog/2017-09-the-one-about-usernames

When evaluating messages to determine if your user or bot user is mentioned, look for a user ID, not a username.

<@username>ではなく<@userID>を使え、ということのようです。

ユーザーIDなんて知らんがな。
ということでWebテスターからサクッと探します。
https://api.slack.com/methods/users.list/test

結果から、メンションを飛ばしたい相手を見つけてidをコピーし、usernameを置き換え。

curl -XPOST -d "token=TOKEN" -d 'channel=channellname' -d "text=<@userID> こんにちは"  -d 'as_user=true' 'https://slack.com/api/chat.postMessage' >&/dev/null

無事メンションできました。

41
27
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
41
27