-
Notifications
You must be signed in to change notification settings - Fork 395
Bolt v3 ‐ v4 Migration Guide
This migration guide helps you transition an application written using the v3.x series of the @slack/bolt
package to the v4.x series. This guide focuses specifically on the breaking changes to help get your existing app up and running as quickly as possible.
At this time, bolt-js 4.0 is still in release candidacy:
npm install @slack/bolt@4.0.0rc
- ⬆️ Support for node v14 and v16 have been officially dropped, as these node versions have been EOL'ed.
- 🚳 A variety of types, methods and constants related to Steps from Apps have been deprecated. These have been gently deposited into their final resting place 🥀. If you are still using these, you should now get a warning in your IDE about that, and expect them to be removed in v5 of bolt-js.
- 🚥
*MiddlewareArgs
interfaces, modeling middleware arguments for different kinds of Slack event payloads processed by bolt apps, have been improved. - 🌐 The Web API client,
@slack/web-api
, has been upgraded from v6 to v7. - 🔌 The Socket Mode handler package,
@slack/socket-mode
, has been upgraded from v1 to v2. - 🚅 For those using the
ExpressReceiver
,express
has been upgraded from v4 to v5. - 🍽️ The
@slack/types
package is now longer exported without a namespace; it is now exported under the namedtypes
export. - 🧘 The
SocketModeFunctions
class with a single static method instead now directly exports the singledefaultProcessEventErrorHandler
method from it. - 🏭 Some of the built-in middleware functions like
ignoreSelf
anddirectMention
have had their APIs changed to create a consistent middleware style. - 🌩️ The
AwsEvent
interface has changed. - 🧹 Deprecated methods, modules and properties in v3 were removed.
If any of the above changes affect you, please see the following sections for guidance on how to migrate to v4 as smoothly as possible.
Many middleware argument types, for example the SlackEventMiddlewareArgs
type, previously used a conditional to sometimes define particular additional helper utilities on the middleware arguments. For example, the say
utility, or tacking on a convenience message property for message-event-related payloads. This was problematic: when the payload was not of a type that required the extra utility, these properties would be required to exist on the middleware arguments but have a type of undefined
. Those of us trying to build generic middleware utilities would have to deal with TypeScript compilation errors and needing to liberally type-cast to avoid these conditional mismatches with undefined
.
Instead, these MiddlewareArgs
types now conditionally create a type intersection when appropriate in order to provide this conditional-utility-extension mechanism. That looks something like:
type SomeMiddlewareArgs<EventType extends string = string> = {
// some type in here
} & (EventType extends 'message'
// If this is a message event, add a `message` property
? { message: EventFromType<EventType> }
: unknown
)
With the above, now when a message payload is wrapped in middleware arguments, it will contain an appropriate message
property, whereas a non-message payload will be intersected with unknown
- effectively a type "noop." No more e.g. say: undefined
or message: undefined
to deal with!
All bolt handlers are provided a convenience client
argument. The bundled version of @slack/web-api
, the package that powers this convenience client
, has been upgraded from v6 to v7. More APIs! Better argument type safety! And a whole slew of other changes, too. Many of these changes won't affect JavaScript application builders, but if you are building a bolt app using TypeScript, you may see some compilation issues. Head over to the @slack/web-api
v6 -> v7 migration guide to get the details on what changed and how to migrate to v7.
While the breaking changes from this upgrade should be shielded from bolt-js users, if you are using the SocketModeReceiver
or setting socketMode: true
, and attach custom code to how the SocketModeReceiver
operates, we suggest you read through the @slack/socket-mode
v1 -> v2 migration guide, just in case.
For those building bolt-js apps using the ExpressReceiver
, the packaged express
version has been upgraded to v5. Best to check the list of breaking changes in express
v5 and keep tabs on express#5944, which tracks the creation of an express
v4 -> v5 migration guide.
We are slowly moving more core Slack domain object types and interfaces into the utility package @slack/types
. For example, recently we shuffled Slack Events API payloads from bolt-js over to @slack/types
. Similar moves will continue as we improve bolt-js. Ideally, we'd like for everyone - ourselves as Slack employees but of course you as well, dear developer - to leverage these types when modeling Slack domain objects.
Anyways, previously we simply export * from '@slack/types';
in bolt-js. We've tweaked this somewhat, it is now: export * as types from '@slack/types';
. So if you are using @slack/types
when packaged within bolt-js, please update your references to something like:
import { App, type types } from '@slack/bolt';
// Now you can get references to e.g. `types.BotMessageEvent`
If you previously imported the SocketModeFunctions
class, you likely only did so to get a reference to the single static method available on this class: defaultProcessEventErrorHandler
. Instead, you can now directly import the named defaultProcessEventErrorHandler
export instead.
- The deprecated type
KnownKeys
was removed. Admittedly, it wasn't very useful:export type KnownKeys<_T> = never;