向具有 Slack Workspace 令牌的用户开放直接消息通道?

Open direct message channel to a user with a Slack Workspace token?

我正在开发新的 Workspace app for Slack. I have a use case where I need to send notifications to users in Slack, through a direct message (or IM). Since the chat.postMessage endpoint requires a channel ID, I can get the existing IM channels using conversations.list 并向他们发送通知。

但是,如果用户尚未从他们这边打开 IM 频道,我需要创建一个。似乎 Web API 端点都没有(conversations.open or im.open) support Workspace tokens. I keep getting not_allowed_token_type error response. I can create a public channel with conversations.create,但这不是我需要的。

在使用 Workspace 令牌时,是否还有其他方法可以为用户打开 IM 通道?

我花了一些时间才弄明白这一点。您需要 add/request conversations.app_home:create 权限范围。然后您可以在 chat.postMessage 调用中将用户 ID 指定为频道参数。