Skip to content

feat: default the client base_url from SLACK_API_URL - #1639

Merged
zimeg merged 4 commits into
mainfrom
feat-slack-api-url
Dec 3, 2026
Merged

zimeg merged 4 commits into
mainfrom
feat-slack-api-url

Conversation

@zimeg

@zimeg zimeg commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Summary

This pull request makes the client that App and AsyncApp create default its base_url to the SLACK_API_URL environment variable when that variable is set and not empty. It's the Python twin of slackapi/bolt-js#3164.

  • A client you pass in keeps its own base_url.
  • An empty SLACK_API_URL keeps the default https://slack.com/api/.
  • The Slack CLI sets SLACK_API_URL for the selected API host, so apps started with the CLI reach that host.
  • A standalone OAuthFlow, AsyncOAuthFlow or LambdaS3OAuthFlow builds its default client with the same helpers, so it follows SLACK_API_URL too.
  • Per-request clients, Socket Mode adapters, and OAuthFlow built from oauth_settings already reuse the app's client, so they pick up the same base_url. Token rotation under oauth_settings and OAuthFlow.sqlite3() still build their own default client. That was already true for any custom base_url, and it's tracked in OAuth token rotation and OAuthFlow.sqlite3() ignore the app client's base_url and proxy #1640.
  • The client docstring and the "Using the Web API" docs page note the new default.

Testing

  1. Run this with the variable set:
    SLACK_API_URL=https://qa.slack.com/api/ python -c "from slack_bolt import App; print(App(token='xoxb-example', signing_secret='example', token_verification_enabled=False).client.base_url)"
    It prints https://qa.slack.com/api/.
  2. Run it again without SLACK_API_URL, or with SLACK_API_URL=. It prints https://slack.com/api/.
  3. Optional: start a Bolt Python app with slack run against a non-production API host and confirm Web API calls go to that host.

Category

  • slack_bolt.App and/or its core components
  • slack_bolt.async_app.AsyncApp and/or its core components
  • Adapters in slack_bolt.adapter
  • Document pages under /docs
  • Others

Requirements

  • I've read and understood the Contributing Guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I have signed the Salesforce CLA (required before your PR can be reviewed or merged).
  • I've run ./scripts/install_all_and_run_tests.sh after making the changes.

🤖 Generated with Claude Code

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
@zimeg zimeg added this to the next milestone Dec 3, 2026
@zimeg zimeg self-assigned this Dec 3, 2026
@zimeg
zimeg marked this pull request as ready for review December 3, 2026 06:49
@zimeg
zimeg requested a review from a team as a code owner December 3, 2026 06:49
@codecov

codecov Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.57%. Comparing base (61b5721) to head (2816f13).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1639   +/-   ##
=======================================
  Coverage   91.57%   91.57%           
=======================================
  Files         228      228           
  Lines        7287     7289    +2     
=======================================
+ Hits         6673     6675    +2     
  Misses        614      614           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@cchensh cchensh left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked at 5066d15.

  • Imports: os is already imported in both app modules.
  • Client reuse: the per-request client copies self._client.base_url. Socket Mode adapters default to app.client. App-level installation_store and oauth_settings flows get client=self.client. say, function tokens and the assistant thread store all use context.client.
  • Trailing slash: slack_sdk appends a trailing / to base_url when it's missing, so a value without one is harmless.
  • Parity: this matches bolt-js#3164 for an empty value and for a given client.

Nits: the "OAuth ... reuse the app's client" bullet is a little broad. Two paths still build their own client at the default URL. Both are existing gaps for any custom base_url, not something this PR introduces, but worth a note or a follow-up:

  • OAuthSettings/AsyncOAuthSettings build InstallationStoreAuthorize(...) with no client (oauth_settings.py:140, async_oauth_settings.py:147). So the TokenRotator refresh calls go to slack.com.
  • OAuthFlow.sqlite3()/AsyncOAuthFlow.sqlite3() pass client=client or WebClient() (oauth_flow.py:132, async_oauth_flow.py:137). That skips the app's fill-in, so the OAuth callback's oauth.v2.access goes to slack.com.

@zimeg

zimeg commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

📝 Good catch on both paths, @cchensh. I narrowed the summary bullet to say which clients follow the app's client, and added the sqlite3() path to #1640 next to the TokenRotator one, so a single fix can cover both.

@WilliamBergamin WilliamBergamin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧪 Thanks @zimeg! The empty SLACK_API_URL and passed-in client tests pin exactly the two cases that would surprise folks, in both sync and async.
Left two optional comments, nothing blocking 💯

Comment thread slack_bolt/util/utils.py Resolved
Comment thread slack_bolt/util/async_utils.py Resolved
Comment thread slack_bolt/app/app.py Resolved
Co-authored-by: William Bergamin <25348381+WilliamBergamin@users.noreply.github.com>
Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
@zimeg
zimeg requested a review from WilliamBergamin December 3, 2026 16:07

@WilliamBergamin WilliamBergamin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧪 Thanks @zimeg! Moving the lookup into the shared helpers means the standalone OAuth flows follow SLACK_API_URL too, and the new tests pin that for sync and async. Fair point on the docstring feeding the reference docs.
One optional cleanup left, nothing blocking 💯

Comment thread slack_bolt/util/utils.py Resolved
Comment thread slack_bolt/util/async_utils.py Resolved

@mwbrooks mwbrooks left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Thanks @zimeg! Moving the lookup into the shared helpers means the CLI's API host now reaches the standalone OAuth flows too, with nice coverage on both sides.

zimeg and others added 2 commits December 3, 2026 12:10
Co-authored-by: William Bergamin <25348381+WilliamBergamin@users.noreply.github.com>
Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
@zimeg
zimeg requested a review from a team as a code owner December 3, 2026 20:10
@zimeg zimeg added the docs Improvements or additions to documentation label Dec 3, 2026

@WilliamBergamin WilliamBergamin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📚 Thanks @zimeg! With the param gone the helpers match main again, and the new docs line is right about the trailing slash, since the SDK adds it.
No more comments from me 🚀

@zimeg

zimeg commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

🌟 Thanks for the kind reviews @WilliamBergamin, @cchensh and @mwbrooks!

@zimeg
zimeg merged commit 20d4dd4 into main Dec 3, 2026
17 checks passed
@zimeg
zimeg deleted the feat-slack-api-url branch December 3, 2026 21:38
@cchensh cchensh mentioned this pull request Dec 4, 2026
4 of 9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:async area:sync docs Improvements or additions to documentation enhancement New feature or request semver:minor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants