在Slack中获取DM消息的接收者

发布于 2025-01-30 12:04:36 字数 1037 浏览 2 评论 0原文

我有一个Slack应用程序,可以使用适当的用户和机器人示波器来听消息事件(应用具有IM:read and im:history permissions im:除其他外,代表用户)。事件有效负载看起来像这样:

{"client_msg_id": "...", 
"type": "message", 
"text": "...", 
"user": "<sender id>", 
"ts": "...", 
"team": "...", 
"blocks": [...], 
"channel": "D012345678 <example direct channel id>", 
"event_ts": "...", 
"channel_type": "im"}

有没有办法识别此消息的收件人ID?

  1. 我已经研究了对话_members api,并使用了事件有效载荷提供的channel_id。它抛出channel_not_found错误。我尝试了使用该应用程序用户所在的实际私人频道进行的硬编码测试,并返回了预期的用户ID列表。因此,这个问题似乎与DM渠道有关。
  2. 尝试使用用户-ID代替频道ID 正如此评论所建议的。也没有工作。

任何帮助都将受到赞赏。

附加信息:

pip冻结| grep slack

slack-bolt==1.13.2
slack-sdk==3.16.1

I have a Slack App that listens to message events with the appropriate user and bot scopes (The app has im:read and im:history permissions among others, on behalf of the user). The event payload looks like this:

{"client_msg_id": "...", 
"type": "message", 
"text": "...", 
"user": "<sender id>", 
"ts": "...", 
"team": "...", 
"blocks": [...], 
"channel": "D012345678 <example direct channel id>", 
"event_ts": "...", 
"channel_type": "im"}

Is there a way to identify the recipient id of this message?

  1. I have looked into conversations_members API and used the channel_id provided by the event payload. It throws a channel_not_found error. I tried a hardcoded test with an actual private channel that the user of the app is in, and it returned the list of user-ids as expected. So it seems like the issue is related to DM channels.
  2. Tried to use the user-id instead of the channel id as this comment suggested. Didn't work either.

Any help is appreciated.

Additional info:

pip freeze | grep slack

slack-bolt==1.13.2
slack-sdk==3.16.1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

余罪 2025-02-06 12:04:36

对于任何面临同一问题的人,我都要求Slackbolt Devs投入并这是他们的答案。。总而言之,converty_members Questuon中提到的是正确的起点。但是,如果您的用户和机器人令牌都具有im:读取权限,则优先级是对机器人令牌。用用户令牌替换它,您应该没问题。在讨论链接中,更详细的答案。

For anyone who is facing the same issue, I asked the SlackBolt devs to pitch in and here's their answer. . In summary, conversation_members mentioned in the questuon is the correct starting point. But if both your user and bot tokens have im:read permissions, the priority is to the bot token. Replace it with user token and you should be fine. More elaborate answer is in the discussion link.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文