LoginSignup
2
0

More than 1 year has passed since last update.

Slackで所属channel一覧を出すsnippet

Last updated at Posted at 2022-04-12

背景

チームにjoinするメンバーに自分が入ってるchannel一覧を伝えたいです。
APIで取得しようとすると、直接とるAPIがなく、後述するようにコストが高いです。
したがってブラウザのDOMからそのまま抜き出すのがシンプルだと考えました。

js snippet

slackのウェブページにて、下記をchrome consoleに入れて実行します

Array.from(document.querySelectorAll(".c-virtual_list__scroll_container div.p-channel_sidebar__static_list__item")).filter(x => x.firstChild.className == 'p-channel_sidebar__channel').map(x => `#${x.innerText}`)

※public channelとprivate channelの両方を取得します

APIでやるなら

上記を要約すると、
https://api.slack.com/methods/conversations.info
にてすべてのpublic channelを取得した後に、
https://api.slack.com/methods/conversations.members
をchannelごとに呼び出し、自分が入っているかどうかを判定する必要がありそうです。

2
0
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
2
0