LoginSignup
0
1

More than 3 years have passed since last update.

【python】SlackのAPIで、複数人にメンションする

Posted at

概要

表題の通り。こちらで書いた記事⑥のための記事。
複数人にメンションしたいとき、どうすれば良いかと考えて以下の通りに実行した。

やりたかったこと

赤枠のように複数人にメンションしたい。
a.jpeg

私が間違えたところ

通知先:記法
@user:<@user>
ここはuserなので"user": "U012YTNNPB5"使用すること。(slackのapiusers.listで取得可能)
"real_name": "test_1"ではないで注意。

コード

menber = ['U012JDYRD2T', 'U012X478FNZ']
tmptmp = []
for i in menber:
    tmptmp.append("<@" + i + ">")
r = map(str,tmptmp)
mojiretsu = ' '.join(r)
text = mojiretsu + " 出勤者はステータスに合わせて、スタンプを押下してください!!"

<@user>の形にしないといけないので、【member】を一つずつ取り出して【i】に代入。そこに文字列"<@"などを加える。
【map(str,tmptmp)】と書いているので、リストtmptmpの全ての要素に対してstr()関数を使用。
③文字列となったリストに' '.join(半角アンダースペース)を追加。
④このtextを使用してpostする。

わかったこと

苦労してreal_nameを取得したが、結局は使わなかった。
エンドポイントのパスパラメータで何をどのように使うかは事前に調べておく必要がある。

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