Skip to content

Commit ca2154a

Browse files
danishiclaude
andauthored
feat: support multiple Slack workspaces via ALLOWED_SLACK_WORKSPACES (#7)
Rename ALLOWED_SLACK_WORKSPACE to ALLOWED_SLACK_WORKSPACES (plural) and accept comma-separated team IDs so the bot can serve multiple workspaces. Add README section explaining how to obtain Slack workspace team IDs. https://claude.ai/code/session_01TbRoBBCX3BFXjUZaiiQDb7 Co-authored-by: Claude <noreply@anthropic.com>
1 parent e867684 commit ca2154a

4 files changed

Lines changed: 20 additions & 5 deletions

File tree

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
SLACK_BOT_TOKEN="xoxb-your-slack-bot-token"
22
SLACK_SIGNING_SECRET="your-slack-signing-secret"
3-
ALLOWED_SLACK_WORKSPACE="T0123456789"
3+
ALLOWED_SLACK_WORKSPACES="T0123456789,T9876543210"
44
GOOGLE_GENAI_USE_VERTEXAI=TRUE
55
GOOGLE_CLOUD_PROJECT="your-gcp-project"
66
GOOGLE_CLOUD_LOCATION="global"

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ llms-full.txt # Extended ADK documentation for LLM context
5050
```bash
5151
cp .env.example .env
5252
# edit .env and set your Slack and Google Cloud credentials
53-
# ALLOWED_SLACK_WORKSPACE is the Slack team ID to allow requests from
53+
# ALLOWED_SLACK_WORKSPACES is a comma-separated list of Slack team IDs to allow requests from
5454
```
5555
3. Run the server
5656
```bash
@@ -88,6 +88,18 @@ The Agent Development Kit includes a built-in web-based Development UI that you
8888
5. Subscribe to bot events: `app_mention`.
8989
6. Invite the bot to channels where you want to use it.
9090

91+
### Getting Slack Workspace (Team) IDs for `ALLOWED_SLACK_WORKSPACES`
92+
To restrict the bot to specific Slack workspaces, set `ALLOWED_SLACK_WORKSPACES` in your `.env` with comma-separated team IDs. You can find your workspace's team ID by:
93+
1. Open your Slack workspace in a browser.
94+
2. The team ID is the `T`-prefixed value in the URL (e.g., `https://app.slack.com/client/T0123456789/...`).
95+
3. Or go to your [Slack App settings](https://api.slack.com/apps), select your app, and find the **Team ID** displayed under **App Credentials** on the **Basic Information** page.
96+
97+
Example:
98+
```
99+
ALLOWED_SLACK_WORKSPACES="T0123456789,T9876543210"
100+
```
101+
If the variable is empty or unset, requests from all workspaces are allowed.
102+
91103
## Deploy to Cloud Run
92104
The repository includes a helper script to build the container and deploy to Cloud Run. Ensure your `.env` contains `SLACK_BOT_TOKEN` and `SLACK_SIGNING_SECRET` before running:
93105

app/main.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
SLACK_BOT_TOKEN = os.environ["SLACK_BOT_TOKEN"]
2525
SLACK_SIGNING_SECRET = os.environ["SLACK_SIGNING_SECRET"]
2626
MODEL_NAME = os.environ.get("MODEL_NAME", "gemini-3.1-pro-preview")
27-
ALLOWED_SLACK_WORKSPACE = os.environ.get("ALLOWED_SLACK_WORKSPACE")
27+
_allowed_ws_raw = os.environ.get("ALLOWED_SLACK_WORKSPACES", "")
28+
ALLOWED_SLACK_WORKSPACES: set[str] = {
29+
w.strip() for w in _allowed_ws_raw.split(",") if w.strip()
30+
}
2831
APP_NAME = os.environ.get("APP_NAME", "slack-bot")
2932

3033
# Initialize Slack Bolt AsyncApp
@@ -272,7 +275,7 @@ async def slack_events(req: Request):
272275
return JSONResponse(content={"challenge": challenge})
273276

274277
team_id = data.get("team_id")
275-
if ALLOWED_SLACK_WORKSPACE and team_id != ALLOWED_SLACK_WORKSPACE:
278+
if ALLOWED_SLACK_WORKSPACES and team_id not in ALLOWED_SLACK_WORKSPACES:
276279
return JSONResponse(status_code=403, content={"error": f"{team_id}:workspace_not_allowed"})
277280
return await handler.handle(req)
278281

scripts/deploy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ SERVICE_URL=$(gcloud run deploy "${SERVICE_NAME}" \
6565
--allow-unauthenticated \
6666
--no-cpu-throttling \
6767
--project "${PROJECT_ID}" \
68-
--set-env-vars "SLACK_BOT_TOKEN=${SLACK_BOT_TOKEN},SLACK_SIGNING_SECRET=${SLACK_SIGNING_SECRET},GOOGLE_GENAI_USE_VERTEXAI=${GOOGLE_GENAI_USE_VERTEXAI},GOOGLE_CLOUD_PROJECT=${PROJECT_ID},GOOGLE_CLOUD_LOCATION=global,ALLOWED_SLACK_WORKSPACE=${ALLOWED_SLACK_WORKSPACE:-},MODEL_NAME=${MODEL_NAME:-gemini-3.1-pro-preview}" \
68+
--set-env-vars "SLACK_BOT_TOKEN=${SLACK_BOT_TOKEN},SLACK_SIGNING_SECRET=${SLACK_SIGNING_SECRET},GOOGLE_GENAI_USE_VERTEXAI=${GOOGLE_GENAI_USE_VERTEXAI},GOOGLE_CLOUD_PROJECT=${PROJECT_ID},GOOGLE_CLOUD_LOCATION=global,ALLOWED_SLACK_WORKSPACES=${ALLOWED_SLACK_WORKSPACES:-},MODEL_NAME=${MODEL_NAME:-gemini-3.1-pro-preview}" \
6969
--format 'value(status.url)')
7070

7171
echo "--------------------------------------------"

0 commit comments

Comments
 (0)