From 0670537da0c52b5a4a0b0e73738a1dd8dd6bac89 Mon Sep 17 00:00:00 2001 From: Agi-Asi <206806952+Agi-Asi@users.noreply.github.com> Date: Thu, 27 Aug 2026 12:48:39 +0000 Subject: [PATCH] docs: convert remaining code examples from CommonJS to ESM The quickstart guides and README already use ESM imports; the concept, deployment, and tutorial pages listed in #2923 still used require() and module.exports. Convert exactly the in-scope files from that issue's checklist (11 English + 8 Japanese): - const { X } = require('pkg') -> import { X } from 'pkg' - const X = require('pkg') -> import X from 'pkg' - module.exports.handler = ... -> export const handler = ... (AWS Lambda deployment docs, both languages) The legacy steps-from-apps pages stay untouched, as called out under 'Out of scope' in the issue. npm run lint (biome covers docs/) passes. Fixes #2923 --- docs/english/concepts/authenticating-oauth.md | 4 ++-- docs/english/concepts/custom-routes.md | 4 ++-- docs/english/concepts/deferring-initialization.md | 2 +- docs/english/concepts/error-handling.md | 2 +- docs/english/concepts/logging.md | 6 +++--- docs/english/concepts/message-listening.md | 2 +- docs/english/concepts/receiver.md | 2 +- docs/english/concepts/socket-mode.md | 4 ++-- docs/english/concepts/token-rotation.md | 2 +- docs/english/deployments/aws-lambda.md | 4 ++-- docs/english/tutorials/code-assistant.md | 6 +++--- docs/japanese/concepts/authenticating-oauth.md | 4 ++-- docs/japanese/concepts/custom-routes.md | 4 ++-- docs/japanese/concepts/deferring-initialization.md | 2 +- docs/japanese/concepts/error-handling.md | 2 +- docs/japanese/concepts/logging.md | 6 +++--- docs/japanese/concepts/message-listening.md | 2 +- docs/japanese/concepts/socket-mode.md | 4 ++-- docs/japanese/deployments/aws-lambda.md | 4 ++-- 19 files changed, 33 insertions(+), 33 deletions(-) diff --git a/docs/english/concepts/authenticating-oauth.md b/docs/english/concepts/authenticating-oauth.md index cb7d54d00..2532d6912 100644 --- a/docs/english/concepts/authenticating-oauth.md +++ b/docs/english/concepts/authenticating-oauth.md @@ -44,8 +44,8 @@ Here we've provided a default implementation of the `installationStore` with developing and testing your app: ```javascript -const { App } = require("@slack/bolt"); -const { FileInstallationStore } = require("@slack/oauth"); +import { App } from "@slack/bolt"; +import { FileInstallationStore } from "@slack/oauth"; const app = new App({ signingSecret: process.env.SLACK_SIGNING_SECRET, clientId: process.env.SLACK_CLIENT_ID, diff --git a/docs/english/concepts/custom-routes.md b/docs/english/concepts/custom-routes.md index 5b7a676ed..420b4131c 100644 --- a/docs/english/concepts/custom-routes.md +++ b/docs/english/concepts/custom-routes.md @@ -9,7 +9,7 @@ Since `v3.13.0`, the default built-in receivers (`HTTPReceiver` and `SocketModeR To determine what port the custom HTTP route will be available on locally, you can specify an `installerOptions.port` property in the `App` constructor. Otherwise, it will default to port `3000`. ```javascript -const { App } = require('@slack/bolt'); +import { App } from '@slack/bolt'; // Initialize Bolt app, using the default HTTPReceiver const app = new App({ @@ -50,7 +50,7 @@ Adding custom HTTP routes is quite straightforward when using Bolt’s built-in ```javascript -const { App, ExpressReceiver } = require('@slack/bolt'); +import { App, ExpressReceiver } from '@slack/bolt'; // Create a Bolt Receiver const receiver = new ExpressReceiver({ signingSecret: process.env.SLACK_SIGNING_SECRET }); diff --git a/docs/english/concepts/deferring-initialization.md b/docs/english/concepts/deferring-initialization.md index 5a45fe853..972bd0dce 100644 --- a/docs/english/concepts/deferring-initialization.md +++ b/docs/english/concepts/deferring-initialization.md @@ -11,7 +11,7 @@ If you call `start()` before `init()`, Bolt will raise an exception. ## Example ```javascript -const { App } = require('@slack/bolt'); +import { App } from '@slack/bolt'; // deferInitialization is one of the options you can set in the constructor const app = new App({ diff --git a/docs/english/concepts/error-handling.md b/docs/english/concepts/error-handling.md index c8e80aa2c..25303bc48 100644 --- a/docs/english/concepts/error-handling.md +++ b/docs/english/concepts/error-handling.md @@ -67,7 +67,7 @@ Starting with version 3.8.0, when passing `extendedErrorHandler: true` to the co It is recommended to check whether a property exists on the `context` or `body` objects before accessing its value, as the data available in the `body` object differs from event to event, and because errors can happen at any point in a request's lifecycle (i.e. before a certain property of `context` has been set). ```javascript -const { App } = require('@slack/bolt'); +import { App } from '@slack/bolt'; const app = new App({ signingSecret: process.env.SLACK_SIGNING_SECRET, diff --git a/docs/english/concepts/logging.md b/docs/english/concepts/logging.md index 6d31dac9a..8cdd6ec4e 100644 --- a/docs/english/concepts/logging.md +++ b/docs/english/concepts/logging.md @@ -4,7 +4,7 @@ By default, Bolt for JavaScript will log information from your app to the consol ```javascript // Import LogLevel from the package -const { App, LogLevel } = require('@slack/bolt'); +import { App, LogLevel } from '@slack/bolt'; // Log level is one of the options you can set in the constructor const app = new App({ @@ -60,8 +60,8 @@ If you want to send logs to somewhere besides the console or want more control o A very simple custom logger might ignore the name and level, and write all messages to a file. ```javascript -const { App } = require('@slack/bolt'); -const { createWriteStream } = require('fs'); +import { App } from '@slack/bolt'; +import { createWriteStream } from 'fs'; const logWritable = createWriteStream('/var/my_log_file'); // Not shown: close this stream const app = new App({ diff --git a/docs/english/concepts/message-listening.md b/docs/english/concepts/message-listening.md index 7b4adb156..88e63e099 100644 --- a/docs/english/concepts/message-listening.md +++ b/docs/english/concepts/message-listening.md @@ -38,7 +38,7 @@ You can filter on subtypes of events by using the built-in `subtype()` middlewar ```javascript // Import subtype from the package -const { App, subtype } = require('@slack/bolt'); +import { App, subtype } from '@slack/bolt'; // Matches all message changes from users app.message(subtype('message_changed'), ({ event, logger }) => { diff --git a/docs/english/concepts/receiver.md b/docs/english/concepts/receiver.md index c42968da3..5fa5b92b6 100644 --- a/docs/english/concepts/receiver.md +++ b/docs/english/concepts/receiver.md @@ -30,7 +30,7 @@ Use the `customPropertiesExtractor` option to extract custom properties from inc This is particularly useful for extracting HTTP headers that you want to propagate to other services, for example, if you need to propagate a header for distributed tracing. ```javascript -const { App, HTTPReceiver } = require('@slack/bolt'); +import { App, HTTPReceiver } from '@slack/bolt'; const app = new App({ token: process.env.SLACK_BOT_TOKEN, diff --git a/docs/english/concepts/socket-mode.md b/docs/english/concepts/socket-mode.md index 1feb53851..54ba2060d 100644 --- a/docs/english/concepts/socket-mode.md +++ b/docs/english/concepts/socket-mode.md @@ -5,7 +5,7 @@ To use the `SocketModeReceiver`, just pass in `socketMode:true` and `appToken:YOUR_APP_TOKEN` when initializing `App`. You can get your App Level Token in your app configuration under the **Basic Information** section. ```javascript -const { App } = require('@slack/bolt'); +import { App } from '@slack/bolt'; const app = new App({ token: process.env.BOT_TOKEN, @@ -24,7 +24,7 @@ const app = new App({ You can define a custom `SocketModeReceiver` by importing it from `@slack/bolt`. ```javascript -const { App, SocketModeReceiver } = require('@slack/bolt'); +import { App, SocketModeReceiver } from '@slack/bolt'; const socketModeReceiver = new SocketModeReceiver({ appToken: process.env.APP_TOKEN, diff --git a/docs/english/concepts/token-rotation.md b/docs/english/concepts/token-rotation.md index 2b081bf80..8fd1e2046 100644 --- a/docs/english/concepts/token-rotation.md +++ b/docs/english/concepts/token-rotation.md @@ -11,7 +11,7 @@ Bolt for JavaScript will rotate tokens automatically in response to incoming eve To rotate tokens on a separate schedule, consider implementing the `InstallProvider` from the [`@slack/oauth`](/tools/node-slack-sdk/oauth) package for use of the provided `authorize` method: ```js -const { InstallProvider } = require("@slack/oauth"); +import { InstallProvider } from "@slack/oauth"; const installer = new InstallProvider({ clientId: process.env.SLACK_CLIENT_ID, diff --git a/docs/english/deployments/aws-lambda.md b/docs/english/deployments/aws-lambda.md index 316fd8f35..43993a79c 100644 --- a/docs/english/deployments/aws-lambda.md +++ b/docs/english/deployments/aws-lambda.md @@ -118,7 +118,7 @@ Next, we'll customize your Bolt app's [`receiver`](/tools/bolt-js/concepts/recei Update the [source code that imports your modules](https://github.com/slack-samples/bolt-js-getting-started-app/blob/4c29a21438b40f0cbca71ece0d39b356dfcf88d5/app.js#L1) in `app.js` to require Bolt's AwsLambdaReceiver: ```javascript -const { App, AwsLambdaReceiver } = require('@slack/bolt'); +import { App, AwsLambdaReceiver } from '@slack/bolt'; ``` :::warning @@ -155,7 +155,7 @@ Finally, at the bottom of your app, update the [source code that starts the HTTP ```javascript // Handle the Lambda function event -module.exports.handler = async (event, context, callback) => { +export const handler = async (event, context, callback) => { const handler = await awsLambdaReceiver.start(); return handler(event, context, callback); } diff --git a/docs/english/tutorials/code-assistant.md b/docs/english/tutorials/code-assistant.md index 459c6eca5..f3db0029f 100644 --- a/docs/english/tutorials/code-assistant.md +++ b/docs/english/tutorials/code-assistant.md @@ -168,9 +168,9 @@ HUGGINGFACE_API_KEY=hf_exampletoken Delete the template contents in the `app.js` file and replace it with this: ````js title="app.js" -const { App, LogLevel, Assistant } = require("@slack/bolt"); -const { config } = require("dotenv"); -const { InferenceClient } = require("@huggingface/inference"); +import { App, LogLevel, Assistant } from "@slack/bolt"; +import { config } from "dotenv"; +import { InferenceClient } from "@huggingface/inference"; config(); diff --git a/docs/japanese/concepts/authenticating-oauth.md b/docs/japanese/concepts/authenticating-oauth.md index 08341da01..592b7dd30 100644 --- a/docs/japanese/concepts/authenticating-oauth.md +++ b/docs/japanese/concepts/authenticating-oauth.md @@ -12,8 +12,8 @@ OAuth を有効にするために、以下を提供する必要があります 開発・テストの際に利用することを想定して `installationStore` オプションのデフォルト実装である `FileInstallationStore` を提供しています。 ```javascript -const { App } = require('@slack/bolt'); -const { FileInstallationStore } = require('@slack/oauth'); +import { App } from '@slack/bolt'; +import { FileInstallationStore } from '@slack/oauth'; const app = new App({ signingSecret: process.env.SLACK_SIGNING_SECRET, clientId: process.env.SLACK_CLIENT_ID, diff --git a/docs/japanese/concepts/custom-routes.md b/docs/japanese/concepts/custom-routes.md index 0116815e1..112433b70 100644 --- a/docs/japanese/concepts/custom-routes.md +++ b/docs/japanese/concepts/custom-routes.md @@ -9,7 +9,7 @@ カスタムの HTTP ルートがローカル環境でどのポートからアクセスできるかを指定するために `App` コンストラクターに `installerOptions.port` というプロパティを渡すことができます。指定しない場合は、デフォルトの `3000` ポートとなります。 ```javascript -const { App } = require('@slack/bolt'); +import { App } from '@slack/bolt'; // デフォルトの HTTPReceiver を使って Bolt アプリを初期化します const app = new App({ @@ -49,7 +49,7 @@ const app = new App({ Bolt の組み込みの `ExpressReceiver` を使っているなら、カスタムの HTTP ルートを追加するのはとても簡単です。`v2.1.0` から `ExpressReceiver` には `router` というプロパティが追加されています。これは、さらにルートを追加できるように `App` 内部で保持している Express の [Router](http://expressjs.com/en/4x/api.html#router) を public にしたものです。 ```javascript -const { App, ExpressReceiver } = require('@slack/bolt'); +import { App, ExpressReceiver } from '@slack/bolt'; // Bolt の Receiver を明に生成 const receiver = new ExpressReceiver({ signingSecret: process.env.SLACK_SIGNING_SECRET }); diff --git a/docs/japanese/concepts/deferring-initialization.md b/docs/japanese/concepts/deferring-initialization.md index 40e61d1e3..8f10855b3 100644 --- a/docs/japanese/concepts/deferring-initialization.md +++ b/docs/japanese/concepts/deferring-initialization.md @@ -5,7 +5,7 @@ Bolt は `deferInitialization` というオプションを使うことで、ア _注意: `init()` メソッドを呼び出す前に `start()` メソッドを呼び出した場合、 Bolt は例外を発生させます。_ ```javascript -const { App } = require('@slack/bolt'); +import { App } from '@slack/bolt'; // deferInitialization はコンストラクターで指定できるオプション const app = new App({ diff --git a/docs/japanese/concepts/error-handling.md b/docs/japanese/concepts/error-handling.md index 440ecc356..37afbff58 100644 --- a/docs/japanese/concepts/error-handling.md +++ b/docs/japanese/concepts/error-handling.md @@ -60,7 +60,7 @@ app.error(async (error) => { ```javascript -const { App } = require('@slack/bolt'); +import { App } from '@slack/bolt'; const app = new App({ signingSecret: process.env.SLACK_SIGNING_SECRET, diff --git a/docs/japanese/concepts/logging.md b/docs/japanese/concepts/logging.md index c92a2b3c7..b5953386c 100644 --- a/docs/japanese/concepts/logging.md +++ b/docs/japanese/concepts/logging.md @@ -4,7 +4,7 @@ Bolt はデフォルトの設定では、標準出力のコンソールにログ ```javascript // パッケージから LogLevel をインポート -const { App, LogLevel } = require('@slack/bolt'); +import { App, LogLevel } from '@slack/bolt'; // オプションとして、コンストラクタで Log level を設定可能 const app = new App({ @@ -31,8 +31,8 @@ const app = new App({ 非常に単純なカスタム logger では、名前やレベルが無視され、すべてのメッセージがファイルに書き込まれることがあります。 ```javascript -const { App } = require('@slack/bolt'); -const { createWriteStream } = require('fs'); +import { App } from '@slack/bolt'; +import { createWriteStream } from 'fs'; const logWritable = createWriteStream('/var/my_log_file'); const app = new App({ diff --git a/docs/japanese/concepts/message-listening.md b/docs/japanese/concepts/message-listening.md index 8317015fd..2e983941a 100644 --- a/docs/japanese/concepts/message-listening.md +++ b/docs/japanese/concepts/message-listening.md @@ -38,7 +38,7 @@ app.message(/^(hi|hello|hey).*/, async ({ context, say }) => { ```javascript // パッケージから subtype をインポート -const { App, subtype } = require('@slack/bolt'); +import { App, subtype } from '@slack/bolt'; // user からのメッセージの編集と一致 app.message(subtype('message_changed'), ({ event, logger }) => { diff --git a/docs/japanese/concepts/socket-mode.md b/docs/japanese/concepts/socket-mode.md index 8470783dd..452110dc2 100644 --- a/docs/japanese/concepts/socket-mode.md +++ b/docs/japanese/concepts/socket-mode.md @@ -5,7 +5,7 @@ `SocketModeReceiver` を使う方法は `App` インスタンスの初期化時にコンストラクターに `socketMode: true` と `appToken: YOUR_APP_TOKEN` を渡すだけです。App Level Token は、アプリ管理画面の **Basic Information** セクションから取得できます。 ```javascript -const { App } = require('@slack/bolt'); +import { App } from '@slack/bolt'; const app = new App({ token: process.env.BOT_TOKEN, @@ -24,7 +24,7 @@ const app = new App({ 以下のように `@slack/bolt` から `SocketModeReceiver` を import して、カスタムされたインスタンスとして定義することができます。 ```javascript -const { App, SocketModeReceiver } = require('@slack/bolt'); +import { App, SocketModeReceiver } from '@slack/bolt'; const socketModeReceiver = new SocketModeReceiver({ appToken: process.env.APP_TOKEN, diff --git a/docs/japanese/deployments/aws-lambda.md b/docs/japanese/deployments/aws-lambda.md index 59b7977d6..3d1ea88cd 100644 --- a/docs/japanese/deployments/aws-lambda.md +++ b/docs/japanese/deployments/aws-lambda.md @@ -122,7 +122,7 @@ const app = new App({ `app.js` のソースコードの中で[モジュールのインポートを行う部分](https://github.com/slackapi/bolt-js-getting-started-app/blob/main/app.js#L1)を編集し、Bolt の `AwsLambdaReceiver` モジュールを require します。 ```javascript -const { App, AwsLambdaReceiver } = require('@slack/bolt'); +import { App, AwsLambdaReceiver } from '@slack/bolt'; ``` :::tip @@ -158,7 +158,7 @@ const app = new App({ ```javascript // Lambda 関数のイベントを処理します -module.exports.handler = async (event, context, callback) => { +export const handler = async (event, context, callback) => { const handler = await awsLambdaReceiver.start(); return handler(event, context, callback); }