Skip to content

Comments

fix: allow all web api client option types in app initialization#2501

Merged
zimeg merged 3 commits intomainfrom
zimeg-fix-ts-client-options
May 5, 2025
Merged

fix: allow all web api client option types in app initialization#2501
zimeg merged 3 commits intomainfrom
zimeg-fix-ts-client-options

Conversation

@zimeg
Copy link
Member

@zimeg zimeg commented Apr 15, 2025

Summary

This PR exposes all options of WebClient to the App constructor since these values can be customized for behaviors that might be specific to calls of the Slack Web API methods. Perhaps for a custom logger or other added options.

Fixes #2484.

Preview

With typescript setups the following will now check without errors:

const app = new App({
  token: process.env.SLACK_BOT_TOKEN,
  socketMode: true,
  appToken: process.env.SLACK_APP_TOKEN,
  logLevel: LogLevel.DEBUG,
  clientOptions: {
    allowAbsoluteUrls: false,
    slackApiUrl: "http://localhost:8080/api",
  },
});

Notes

All provided options are shared when the WebClient is constructed:

bolt-js/src/App.ts

Lines 336 to 353 in 20a5997

/* ------------------------ Set client options ------------------------*/
this.clientOptions = clientOptions !== undefined ? clientOptions : {};
if (agent !== undefined && this.clientOptions.agent === undefined) {
this.clientOptions.agent = agent;
}
if (clientTls !== undefined && this.clientOptions.tls === undefined) {
this.clientOptions.tls = clientTls;
}
if (logLevel !== undefined && logger === undefined) {
// only logLevel is passed
this.clientOptions.logLevel = logLevel;
} else {
// Since v3.4, WebClient starts sharing logger with App
this.clientOptions.logger = this.logger;
}
// The public WebClient instance (app.client)
// Since v3.4, it can have the passed token in the case of single workspace installation.
this.client = new WebClient(token, this.clientOptions);

Requirements

@zimeg zimeg added bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented semver:patch TypeScript-specific labels Apr 15, 2025
@zimeg zimeg added this to the 4.2.2 milestone Apr 15, 2025
@zimeg zimeg self-assigned this Apr 15, 2025
@codecov
Copy link

codecov bot commented Apr 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.97%. Comparing base (cad34f5) to head (86c6c0d).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2501   +/-   ##
=======================================
  Coverage   92.96%   92.97%           
=======================================
  Files          36       36           
  Lines        7437     7442    +5     
  Branches      649      649           
=======================================
+ Hits         6914     6919    +5     
  Misses        518      518           
  Partials        5        5           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@hello-ashleyintech hello-ashleyintech left a comment

Choose a reason for hiding this comment

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

this looks great! thank you ✨

logLevel?: LogLevel;
ignoreSelf?: boolean;
clientOptions?: Pick<WebClientOptions, 'slackApiUrl'>;
/**
Copy link
Contributor

Choose a reason for hiding this comment

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

<3

Copy link
Contributor

@WilliamBergamin WilliamBergamin left a comment

Choose a reason for hiding this comment

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

Directly surfacing the WebClientOptions type in bolt-js feel a bit heavy handed 🤔
It may back us up into a corner where a breaking change in the WebClient results in a breaking change in Bolt, I may be over thinking this but it may be a good idea to add an interface layer

Didn't get much time to think this through fully these are just my initial thoughts

@zimeg
Copy link
Member Author

zimeg commented Apr 16, 2025

@hello-ashleyintech @WilliamBergamin Thank y'all both for reviewing this PR!

It may back us up into a corner where a breaking change in the WebClient results in a breaking change in Bolt, I may be over thinking this but it may be a good idea to add an interface layer

What a good callout. I do agree that this exposes @slack/bolt to more changes of @slack/web-api but to me it seems like WebClientOptions might be an alright interface to use here?

The big advantage IMO is that these types should correctly match the installed @slack/web-api version going forward.

TBH it's not so clear if types should match preferred or desired behavior though, since without typescript all options can be used already at the moment 🤔

@zimeg
Copy link
Member Author

zimeg commented Apr 22, 2025

I am finding these options work in additional cases such as setting retries to 0 to exit with error:

const app = new App({
  token: process.env.SLACK_BOT_TOKEN,
  socketMode: true,
  appToken: process.env.SLACK_APP_TOKEN,
  logLevel: LogLevel.DEBUG,
  clientOptions: {
    retryConfig: {
      retries: 0,
    },
  },
});

I'll merge this for the next release to match the javascript and typescript experiences soon, but I am open to other ideas beforehand!

@zimeg
Copy link
Member Author

zimeg commented May 5, 2025

@hello-ashleyintech @WilliamBergamin Thank y'all so much for thoughts and reviews 👾

After having considered how upstream changes of @slack/web-api might effect @slack/bolt I agree that we'll want to be aware of how changes to WebClient are surfaced. At the moment I'm excited to unlock these type hints though 🤖 ✨

@zimeg zimeg merged commit a47374a into main May 5, 2025
18 checks passed
@zimeg zimeg deleted the zimeg-fix-ts-client-options branch May 5, 2025 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented semver:patch TypeScript-specific

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: expose @slack/web-api options to bolt apps

3 participants