170 words
1min read
Edit

Slackのsubteam IDとchannel IDをまとめて取得する

Slackをブラウザで開き、次のスクリプトを検証ツールのConsoleで実行すれば、現在表示されているグループメンションのsubteam IDをまとめて取得できる。

copy(Array.from(new Map($$("[data-user-group-id]").map(e => ([e.innerText, e.dataset.userGroupId ])))).map(([label,id]) => ({label, id})))

実行するとクリップボードに次のような形式でコピーされる。

[
{
"label": "@user_group_name_1",
"id": "SUBTEAM_ID_1"
},
{
"label": "@user_group_name_2",
"id": "SUBTEAM_ID_2"
},
// ...
]

このスクリプトは、Slack内のグループメンションのHTML要素が次のようになっていることを利用している。

<a data-user-group-id="SUBTEAM_ID" >@user_group_name</a>

Channel IDの場合は、サイドバーを表示した状態で次のスクリプトを実行すれば、すべてのチャンネルのIDをまとめて取得できる。

copy(Array.from(new Map($$("[data-qa-channel-sidebar-channel-id]").map(e => ([e.innerText, e.dataset.qaChannelSidebarChannelId ])))).map(([label,id]) => ({label, id})))