2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Slackのチャンネル名からIDを取得する

Last updated at Posted at 2022-03-23

概要

Slackアプリケーションでチャンネル名からチャンネルIDを取得したい。
しかし、API一覧では、channel関係はすべてdeprecatedになっている。

Web API methods

解決策

conversations.list APIを使うらしい。
target_channelのIDをtarget_channel_idに入れる例:

from slack_bolt import App

app = App(token=bot_token)
channels = app.client.conversations_list()["channels"]

try:
    target_channel_id = next(ch["id"] for ch in channels if ch["name"] == target_channel)
except StopIteration:
    raise ValueError(f"{target_channel} is not found")

参考

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?