-
Notifications
You must be signed in to change notification settings - Fork 248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do I get the correct workspace team ID in message and mention handlers? #1107
Comments
Hi @paulkuhle, thanks for asking the question! The Nonetheless, in your case, I guess one of your customer workspaces added your app's bot user, and all members in the channel use that bot user regardless of which workspace they belong to. Long story short, there are two patterns:
I hope this clarifies things. |
Thank you for clarifying! We're essentially just trying to reliably get the team ID of the workspace that the bot is installed in. Based on your explanation, What about the |
When it comes to message events, it is unfortunately not that simple. You can find "authorizations": [
{
"enterprise_id": null,
"team_id": "T03E94MJU",
"user_id": "U06MGSUFUJY",
"is_bot": true,
"is_enterprise_install": false
}
],
"event_context": "4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDNFOTRNSlUiLCJhaWQiOiJBMDZNVDNEQU4yViIsImNpZCI6IkNIRTJEVVc1ViJ9" The Although the If you can safely assume that only one bot user can exist in the Connect channel and that If there is a possibility to have more than one bot user in the channel, you will need to check the rest of the active installations. To fetch all the authorizations, you can call This is the essential way to identify the installed organization/workspace for Events API. If you want to consistently do the same, this works for the app_mention event and any other events too. Hope this makes sense to you. |
Thanks for the clarification! |
We have a Slack bot that is installed in several customer workspaces. Our bot can respond either to mentions using
@app.event("app_mention")
or to regular messages using@app.event("message")
, depending on whether the customer has a separate channel for our bot or not.In order to properly keep track of conversations and to verify customer's subscription details and so on, we need to reliably access the team ID of the workspace that the bot is running in. The main issues we've been facing are:
context_team_id
field gives us the team ID we're looking for (https://api.slack.com/enterprise/org-wide-apps#context-team-id). However, this field isn't available when using the@app.event("app_mention")
handler.body["event"]["team"]
seems to always be defined, but can return team IDs that we're not interested in (from what we've seen, when the user is a Slack Connect user from a different workspace, we'll get the user's team ID, which is different from the workspace team ID).We currently don't have a way to reliably get the correct team ID, at least for the
@app.event("app_mention")
handler. Is there a different method or workaround?Reproducible in:
The
slack_bolt
versionPython runtime version
OS info
ProductName: macOS ProductVersion: 14.5 BuildVersion: 23F79 Darwin Kernel Version 23.5.0: Wed May 1 20:16:51 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T8103
Steps to reproduce:
Register a basic Slack bot with the message/mention handlers in a workspace setup such as the one described above (external users/external connections) and try to get the team ID of the workspace that the bot is running in, not the user's team ID.
Expected result:
Get the workspace's team ID.
Actual result:
Sometimes we can only get the team ID that the user belongs to, but not the team ID of the workspace that the bot belongs to.
Requirements
Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.
The text was updated successfully, but these errors were encountered: