### Handle Slack Installation Path Source: https://github.com/slackapi/node-slack-sdk/blob/main/docs/english/oauth.md Use `handleInstallPath` to let the package render the default installation page. This is suitable when no customization of the installation page is needed. ```javascript app.get('/slack/install', async (req, res) => { await installer.handleInstallPath(req, res, { scopes: ['chat:write'], userScopes: ['channels:read'], metadata: 'some_metadata', }); }); ``` -------------------------------- ### Authorize and Fetch Installation Data Source: https://github.com/slackapi/node-slack-sdk/blob/main/packages/oauth/README.md Use `installer.authorize()` to fetch a subset of installation data, or `installer.installationStore.fetchInstallation()` to retrieve the entire saved installation object. ```javascript // installer.authorize takes in an installQuery as an argument // installQuery = {teamId: 'string', enterpriseId: 'string', userId: string, conversationId: 'string', isEnterpriseInstall: boolean}; const result = installer.authorize({teamId: 'my-team-ID'}); /* result = { botToken: '', userToken: '', botId: '', botUserId: '', teamId: ''; enterpriseId: ''; } */ ``` ```javascript // installer.installationStore.fetchInstallation takes in an installQuery as an argument // installQuery = {teamId: 'string', enterpriseId: 'string', userId: 'string', conversationId: 'string', isEnterpriseInstall: boolean}; // returns an installation object const result = await installer.installationStore.fetchInstallation({teamId:'my-team-ID', enterpriseId:'my-enterprise-ID'}); ``` -------------------------------- ### Custom Installation Store Implementation Source: https://github.com/slackapi/node-slack-sdk/blob/main/docs/english/oauth.md Implement `storeInstallation`, `fetchInstallation`, and `deleteInstallation` to manage Slack app installation data in your database. This example shows how to handle both enterprise-wide and single-team installations. ```javascript const installer = new InstallProvider({ clientId: process.env.SLACK_CLIENT_ID, clientSecret: process.env.SLACK_CLIENT_SECRET, stateSecret: process.env.SLACK_STATE_SECRET, installationStore: { // takes in an installation object as an argument // returns nothing storeInstallation: async (installation) => { // replace myDB.set with your own database or OEM setter if (installation.isEnterpriseInstall) { // support for org wide app installation return myDB.set(installation.enterprise.id, installation); } else { // single team app installation return myDB.set(installation.team.id, installation); } throw new Error('Failed saving installation data to installationStore'); }, // takes in an installQuery as an argument // installQuery = {teamId: 'string', enterpriseId: 'string', userId: 'string', conversationId: 'string', isEnterpriseInstall: boolean}; // returns installation object from database fetchInstallation: async (installQuery) => { // replace myDB.get with your own database or OEM getter if (installQuery.isEnterpriseInstall && installQuery.enterpriseId !== undefined) { // org wide app installation lookup return await myDB.get(installQuery.enterpriseId); } if (installQuery.teamId !== undefined) { // single team app installation lookup return await myDB.get(installQuery.teamId); } throw new Error('Failed fetching installation'); }, // takes in an installQuery as an argument // installQuery = {teamId: 'string', enterpriseId: 'string', userId: 'string', conversationId: 'string', isEnterpriseInstall: boolean}; // returns nothing deleteInstallation: async (installQuery) => { // replace myDB.get with your own database or OEM getter if (installQuery.isEnterpriseInstall && installQuery.enterpriseId !== undefined) { // org wide app installation deletion return await myDB.delete(installQuery.enterpriseId); } if (installQuery.teamId !== undefined) { // single team app installation deletion return await myDB.delete(installQuery.teamId); } throw new Error('Failed to delete installation'); }, }, }); ``` -------------------------------- ### Fetch Extended Slack Installation Data Source: https://github.com/slackapi/node-slack-sdk/blob/main/docs/english/oauth.md Retrieve the complete saved installation data using `installer.installationStore.fetchInstallation()`. This method requires an `installQuery` object and returns the full installation details. ```javascript const result = await installer.installationStore.fetchInstallation({teamId:'my-team-ID', enterpriseId:'my-enterprise-ID'}); ``` -------------------------------- ### handleInstallPath() Source: https://github.com/slackapi/node-slack-sdk/blob/main/docs/english/reference/oauth/classes/InstallProvider.md Handles requests to the install path (e.g., `/slack/install`) from an app installer. ```APIDOC ## handleInstallPath() ### Description Handles the install path (the default is `/slack/install`) requests from an app installer. ### Parameters #### req * **`IncomingMessage`** - Required - The incoming request object. #### res * **`ServerResponse`** - Required - The server response object. #### options * **`InstallPathOptions`** (`object`) - Optional - Options for handling the install path. #### installOptions * **`InstallURLOptions`** (`object`) - Optional - Options for the installation process. ### Returns * **`Promise`** - A promise that resolves when the install path has been handled. ``` -------------------------------- ### Initialize InstallProvider for V2 OAuth Source: https://github.com/slackapi/node-slack-sdk/blob/main/docs/english/oauth.md Initialize the InstallProvider with your Slack app's client ID, client secret, and a state secret. This setup is for V2 OAuth and stores installations in memory (not recommended for production). ```javascript const { InstallProvider } = require('@slack/oauth'); // initialize the installProvider const installer = new InstallProvider({ clientId: process.env.SLACK_CLIENT_ID, clientSecret: process.env.SLACK_CLIENT_SECRET, stateSecret: process.env.SLACK_STATE_SECRET, }); ``` -------------------------------- ### fetchInstallation Source: https://github.com/slackapi/node-slack-sdk/blob/main/docs/english/reference/oauth/interfaces/InstallationStore.md Fetches installation information based on the provided query. It returns a Promise that resolves with the Installation object. ```APIDOC ## fetchInstallation(query, logger?) ### Description Fetches installation information based on the provided query. It returns a Promise that resolves with the Installation object. ### Method fetchInstallation ### Parameters #### query - **query** (`InstallationQuery`) - Required - The query object to find the installation. #### logger? - **logger** (`Logger`) - Optional - A logger instance for logging. ### Returns - `Promise>` - A promise that resolves with the fetched installation data. ``` -------------------------------- ### app.install() Source: https://github.com/slackapi/node-slack-sdk/blob/main/docs/english/reference/cli-test/variables/SlackCLI.md Installs a Slack application. This function corresponds to the `slack app install` command. ```APIDOC ## app.install() ### Description Installs a Slack application. ### Method `app.install` ### Parameters #### args - `args` (ProjectCommandArguments) - Required - Arguments for the project command. ### Returns - `Promise` - The command output. ``` -------------------------------- ### Custom Installation Store Implementation Source: https://github.com/slackapi/node-slack-sdk/blob/main/packages/oauth/README.md Implement a custom installation store by providing `storeInstallation`, `fetchInstallation`, and `deleteInstallation` methods to the `InstallProvider`. This allows you to save and retrieve installation data to your own database. ```javascript const installer = new InstallProvider({ clientId: process.env.SLACK_CLIENT_ID, clientSecret: process.env.SLACK_CLIENT_SECRET, stateSecret: process.env.SLACK_STATE_SECRET, installationStore: { // takes in an installation object as an argument // returns nothing storeInstallation: async (installation) => { // replace myDB.set with your own database or OEM setter if (installation.isEnterpriseInstall) { // support for org wide app installation return myDB.set(installation.enterprise.id, installation); } else { // single team app installation return myDB.set(installation.team.id, installation); } throw new Error('Failed saving installation data to installationStore'); }, // takes in an installQuery as an argument // installQuery = {teamId: 'string', enterpriseId: 'string', userId: 'string', conversationId: 'string', isEnterpriseInstall: boolean}; // returns installation object from database fetchInstallation: async (installQuery) => { // replace myDB.get with your own database or OEM getter if (installQuery.isEnterpriseInstall && installQuery.enterpriseId !== undefined) { // org wide app installation lookup return await myDB.get(installQuery.enterpriseId); } if (installQuery.teamId !== undefined) { // single team app installation lookup return await myDB.get(installQuery.teamId); } throw new Error('Failed fetching installation'); }, // takes in an installQuery as an argument // installQuery = {teamId: 'string', enterpriseId: 'string', userId: 'string', conversationId: 'string', isEnterpriseInstall: boolean}; // returns nothing deleteInstallation: async (installQuery) => { // replace myDB.get with your own database or OEM getter if (installQuery.isEnterpriseInstall && installQuery.enterpriseId !== undefined) { // org wide app installation deletion return await myDB.delete(installQuery.enterpriseId); } if (installQuery.teamId !== undefined) { // single team app installation deletion return await myDB.delete(installQuery.teamId); } throw new Error('Failed to delete installation'); }, }, }); ``` -------------------------------- ### Run Example Script (Tooling Token Required) Source: https://github.com/slackapi/node-slack-sdk/blob/main/prod-server-integration-tests/README.md Execute an example script that requires the SLACK_TOOLING_TOKEN environment variable. ```bash node scripts/apps_manifest_test.js ``` -------------------------------- ### Run Example Script (Grid Tokens Required) Source: https://github.com/slackapi/node-slack-sdk/blob/main/prod-server-integration-tests/README.md Execute an example script for managing user sessions that requires SLACK_SDK_TEST_GRID_*_TOKEN environment variables. ```bash node scripts/admin/usersSessionSettings.js ``` -------------------------------- ### authorize() Source: https://github.com/slackapi/node-slack-sdk/blob/main/docs/english/reference/oauth/classes/InstallProvider.md Fetches installation data from the `installationStore`. This method is used to retrieve existing installation information. ```APIDOC ## authorize() ### Description Fetches data from the installationStore. ### Parameters #### source * **`InstallationQuery`** (`object`) - Required - An object specifying the query parameters for fetching installation data. ### Returns * **`Promise`** - A promise that resolves with the authorization result. ``` -------------------------------- ### Install @slack/socket-mode Source: https://github.com/slackapi/node-slack-sdk/blob/main/docs/english/migration/migrating-socket-mode-package-to-v2.md Install the @slack/socket-mode package using npm. ```bash npm i @slack/socket-mode ``` -------------------------------- ### fetchInstallation Source: https://github.com/slackapi/node-slack-sdk/blob/main/docs/english/reference/oauth/classes/MemoryInstallationStore.md Fetches a Slack installation from the in-memory store. ```APIDOC ## fetchInstallation ### Description Fetches a Slack installation from the in-memory store based on the provided query. ### Parameters #### query - **query** (`InstallationQuery`) - Required - An object that specifies the criteria for finding the installation to fetch. #### logger? - **logger?** (`Logger`) - Optional - A logger instance for capturing logs during the operation. ### Returns `Promise>` - A promise that resolves with the found installation details. ``` -------------------------------- ### Customizing OAuth Success and Failure Handlers Source: https://github.com/slackapi/node-slack-sdk/blob/main/docs/english/oauth.md This example shows how to provide custom functions for handling successful OAuth installations and failures, allowing for tailored user experiences and responses. ```javascript const callbackOptions = { success: (installation, installOptions, req, res) => { // Do custom success logic here // Tips: // - Inspect the metadata with `installOptions.metadata` // - Add javascript and css in the htmlResponse using the