### Initialize Node.js Project and Install Slack SDK Source: https://docs.slack.dev/tools/node-slack-sdk/getting-started Commands to initialize a new Node.js project and install the required @slack/web-api package via npm. ```bash npm init npm install @slack/web-api ``` -------------------------------- ### Project Setup and Dependency Installation Source: https://docs.slack.dev/tools/python-slack-sdk/tutorial/uploading-files These commands set up a new Python virtual environment, install the slack-sdk library, and ensure pip is up-to-date. This is a prerequisite for running the Python code samples. ```bash echo 'slack-sdk>=3.12,<4' > requirements.txt python3 -m venv .venv source .venv/bin/activate pip install -U pip pip install -r requirements.txt ``` -------------------------------- ### Example: Start Local Development Server Source: https://docs.slack.dev/tools/slack-cli/reference/commands/slack_run Use this command to initiate a local development server for your Slack application. ```bash $ slack platform run ``` -------------------------------- ### GET /slack/install Source: https://docs.slack.dev/tools/bolt-python/reference/adapter/fastapi/async_handler.html Handles the Slack OAuth installation flow initiation. ```APIDOC ## GET /slack/install ### Description Initiates the Slack OAuth installation flow for the workspace. ### Method GET ### Endpoint /slack/install ### Response #### Success Response (302) - **redirect** (url) - Redirects the user to the Slack authorization page. ``` -------------------------------- ### Example: Start a new project from a specific template Source: https://docs.slack.dev/tools/slack-cli/reference/commands/slack_project_create Illustrates creating a new project named 'my-project' from a specific template URL, 'slack-samples/deno-hello-world'. ```bash slack create my-project -t slack-samples/deno-hello-world ``` -------------------------------- ### Org-wide Installation Object Source: https://docs.slack.dev/tools/bolt-js/concepts/authenticating-oauth An example of the `installation` object for an app installed org-wide. It includes an `enterprise` object and `isEnterpriseInstall` set to true. ```json { team: undefined, enterprise: { id: "E0000000001", name: "laboratories" }, user: { token: undefined, scopes: undefined, id: "U0000000001" }, tokenType: "bot", isEnterpriseInstall: true, appId: "A0000000001", authVersion: "v2", bot: { scopes: [ "chat:write" ], token: "xoxb-000001-00*********-********************", userId: "U0000000002", id: "B0000000001" } } ``` -------------------------------- ### GET /slack/install Source: https://docs.slack.dev/tools/bolt-python/reference/adapter/starlette/index.html Handles the Slack OAuth installation flow, including the initial installation request and the callback redirect. ```APIDOC ## GET /slack/install ### Description Handles the OAuth installation process for Slack apps, including the installation initiation and the redirect URI callback. ### Method GET ### Endpoint /slack/install ### Parameters #### Query Parameters - **code** (string) - Optional - The authorization code provided by Slack during the OAuth callback. - **state** (string) - Optional - The state parameter used for CSRF protection. ### Request Example GET /slack/install?code=abc12345&state=xyz ### Response #### Success Response (200) - **body** (string) - HTML or redirect response confirming installation status. #### Response Example { "message": "Installation successful" } ``` -------------------------------- ### Gradle Command to Run Example Source: https://docs.slack.dev/tools/java-slack-sdk/guides/web-api-client-setup Run the 'gradle run' command in your terminal to execute the Example main class. This confirms your Gradle setup for the Slack API client. ```bash gradle run ``` -------------------------------- ### Example: Run with Custom App Entry Point Source: https://docs.slack.dev/tools/slack-cli/reference/commands/slack_run Specify a custom entry point file for your Slack app when starting the local development server. ```bash $ slack platform run ./src/app.py ``` -------------------------------- ### Example: Run with Cleanup Enabled Source: https://docs.slack.dev/tools/slack-cli/reference/commands/slack_run Start the local development server and ensure the local app is uninstalled after exiting by using the `--cleanup` flag. ```bash $ slack platform run --cleanup ``` -------------------------------- ### Create and Navigate to Slack App Source: https://docs.slack.dev/tools/deno-slack-sdk/guides/getting-started Commands to scaffold a new Slack application from a template and enter the project directory. ```bash slack create my-app --template https://github.com/slack-samples/deno-starter-template cd my-app ``` -------------------------------- ### Example: Initialize a Project Source: https://docs.slack.dev/tools/slack-cli/reference/commands/slack_project_init A basic example demonstrating how to initialize a project using the `slack init` command. ```bash $ slack init # Initialize a project ``` -------------------------------- ### Example Database Object for Testing Source: https://docs.slack.dev/tools/bolt-js/concepts/authenticating-oauth A simple in-memory database object for testing the custom installation store logic. It provides `get`, `set`, and `delete` methods. ```javascript const database = { store: {}, async get(key) { return this.store[key]; }, async delete(key) { delete this.store[key]; }, async set(key, value) { this.store[key] = value; }, }; ``` -------------------------------- ### Initialize Slack WebClient in Node.js Source: https://docs.slack.dev/tools/node-slack-sdk/getting-started A basic script to import the WebClient from the Slack SDK and verify the environment setup. ```javascript const { WebClient } = require('@slack/web-api'); console.log('Getting started with Node Slack SDK'); ``` -------------------------------- ### Handle Installation Request Source: https://docs.slack.dev/tools/bolt-python/reference/oauth/oauth_flow.html Initializes the installation flow by generating a state, building the authorization URL, and rendering the installation page if enabled. ```python def handle_installation(self, request: BoltRequest) -> BoltResponse: set_cookie_value: Optional[str] = None url = self.build_authorize_url("", request) if self.settings.state_validation_enabled is True: state = self.issue_new_state(request) url = self.build_authorize_url(state, request) set_cookie_value = self.settings.state_utils.build_set_cookie_for_new_state(state) if self.settings.install_page_rendering_enabled: html = self.build_install_page_html(url, request) return BoltResponse(status=200, body=html, headers=self.append_set_cookie_headers({"Content-Type": "text/html; charset=utf-8"}, set_cookie_value)) ``` -------------------------------- ### Basic Async App with Event Handling Source: https://docs.slack.dev/tools/bolt-python/concepts/async This snippet demonstrates the basic setup for an asynchronous Bolt application. It initializes AsyncApp, defines an event handler for app mentions, and starts the application server. Ensure you have `aiohttp` installed. ```python from slack_bolt.async_app import AsyncApp app = AsyncApp() @app.event("app_mention") async def handle_mentions(event, client, say): api_response = await client.reactions_add( channel=event["channel"], timestamp=event["ts"], name="eyes", ) await say("What's up?") if __name__ == "__main__": app.start(3000) ``` -------------------------------- ### Create Project with Git Source: https://docs.slack.dev/tools/bolt-js/getting-started Clone a starter template repository and install dependencies manually. ```bash $ git clone https://github.com/slack-samples/bolt-js-getting-started-app first-bolt-app$ cd first-bolt-app$ npm install ``` -------------------------------- ### HTTP Request Example Source: https://docs.slack.dev/reference/methods/admin.conversations.restrictAccess.addGroup This is an example of how to make a GET request to the admin.conversations.restrictAccess.addGroup API endpoint. ```http GET https://slack.com/api/admin.conversations.restrictAccess.addGroup ``` -------------------------------- ### Initialize Async Installation Store Authorize Source: https://docs.slack.dev/tools/bolt-python/reference/app/async_app.html Sets up an asynchronous authorization handler using an installation store, extracting necessary OAuth settings. ```python self._async_installation_store: Optional[AsyncInstallationStore] = installation_store if self._async_installation_store is not None and self._async_authorize is None: settings = oauth_flow.settings if oauth_flow is not None else oauth_settings self._async_authorize = AsyncInstallationStoreAuthorize( installation_store=self._async_installation_store, client_id=settings.client_id if settings is not None else None, client_secret=settings.client_secret if settings is not None else None, logger=self._framework_logger, bot_only=installation_store_bot_only or False, client=self._async_client, # for proxy use cases etc. user_token_resolution=(settings.user_token_resolution if settings is not None else "authed_user"), ) ``` -------------------------------- ### Install Slack CLI with Custom Flags Source: https://docs.slack.dev/tools/slack-cli/guides/installing-the-slack-cli-for-windows Example of invoking the installer script with specific flags for version, alias, and skipping Git installation. ```powershell .\install-windows.ps1 -Version 2.1.0 -Alias slackcli -SkipGit $true ``` -------------------------------- ### Complete SDK Configuration with Hooks and Watch Settings Source: https://docs.slack.dev/tools/slack-cli/reference/hooks This example demonstrates a comprehensive configuration returned by an SDK's `get-hooks` script, including definitions for `get-manifest`, `build`, `start`, and detailed `watch` settings for development. ```json { "hooks": { "get-manifest": "deno run -q --unstable --config=deno.jsonc --allow-read --allow-net https://deno.land/x/deno_slack_builder@0.0.8/mod.ts --manifest", "build": "deno run -q --unstable --config=deno.jsonc --allow-read --allow-write --allow-net https://deno.land/x/deno_slack_builder@0.0.8/mod.ts", "start": "deno run -q --unstable --config=deno.jsonc --allow-read --allow-net https://deno.land/x/deno_slack_runtime@0.0.5/local-run.ts" }, "config": { "watch": { "manifest": { "paths": ["manifest.json"] }, "app": { "paths": ["app.js", "listeners/"], "filter-regex": "\\.(ts|js)$" } }, "sdk-managed-connection-enabled": "true" } } ``` -------------------------------- ### Install Dependencies and Run Bolt Server Source: https://docs.slack.dev/ai/slack-mcp-server/developing Install project dependencies and start the Bolt server. ```bash # Install dependencies npm install # Run Bolt server npm start ``` -------------------------------- ### HTTP Request Example Source: https://docs.slack.dev/reference/methods/admin.conversations.restrictaccess.removegroup This is an example of how to make an HTTP GET request to the admin.conversations.restrictAccess.removeGroup API endpoint. ```http GET https://slack.com/api/admin.conversations.restrictAccess.removeGroup ``` -------------------------------- ### Create Project from Sample Source: https://docs.slack.dev/tools/slack-cli/reference/commands/slack_project_samples Provide a project name to interactively select and create a new app from one of the available sample projects. ```bash $ slack samples my-project # Select a sample app to create ``` -------------------------------- ### Run Installation Source: https://docs.slack.dev/tools/bolt-python/reference/oauth/oauth_flow.html Exchanges an authorization code for an access token and installation details, then returns an Installation object. ```APIDOC ## POST /oauth/v2/access ### Description Exchanges an authorization `code` for an access token and installation details. This method is typically called after a user authorizes your application. ### Method POST ### Endpoint `/oauth/v2/access` ### Parameters #### Query Parameters - **code** (string) - Required - The authorization code received from Slack. ### Request Body (Not applicable for this endpoint as parameters are in the query string) ### Response #### Success Response (200) Returns an `Installation` object containing details about the installed app, team, user, and tokens. #### Response Example ```json { "app_id": "B0123456789", "enterprise_id": "E0123456789", "enterprise_name": "Example Enterprise", "enterprise_url": "https://example-enterprise.slack.com", "team_id": "T0123456789", "team_name": "Example Team", "bot_token": "xoxb-your-bot-token", "bot_id": "B0123456789", "bot_user_id": "U0123456789", "bot_scopes": "chat:write,commands", "user_id": "U0123456789", "user_token": "xoxp-your-user-token", "user_scopes": "", "incoming_webhook_url": "https://hooks.slack.com/services/...", "incoming_webhook_channel": null, "incoming_webhook_channel_id": null, "incoming_webhook_configuration_url": "https://example.slack.com/apps/...", "is_enterprise_install": false, "token_type": "bot" } ``` #### Error Response - **400 Bad Request**: If the `code` is invalid or missing. - **500 Internal Server Error**: If there's an issue processing the request. ``` -------------------------------- ### GET User Request Example Source: https://docs.slack.dev/reference/scim-api This example shows how to make a GET request to retrieve a specific user's information using the SCIM API. Ensure you include the correct Host and Authorization headers. ```http GET /scim/v2/Users/U123ABC456 HTTP/1.1 Host: api.slack.com Accept: application/json Authorization: Bearer xoxp-4956040672-4956040692-6476208902-xxxxxx ``` -------------------------------- ### Collect Items from Datastore Starting at a Cursor Source: https://docs.slack.dev/tools/slack-cli/reference/commands/slack_datastore_query Example of retrieving items from a datastore by specifying a starting cursor for pagination. ```bash $ slack datastore query --datastore tasks '{"cursor": "eyJfX2NWaV..."}' ``` -------------------------------- ### Initialize and Run an AsyncApp Source: https://docs.slack.dev/tools/bolt-python/reference/app/async_app.html Demonstrates how to initialize an AsyncApp with credentials, register a message listener, and start the application server. ```python import os from slack_bolt.async_app import AsyncApp # Initializes your app with your bot token and signing secret app = AsyncApp( token=os.environ.get("SLACK_BOT_TOKEN"), signing_secret=os.environ.get("SLACK_SIGNING_SECRET") ) # Listens to incoming messages that contain "hello" @app.message("hello") async def message_hello(message, say): # async function # say() sends a message to the channel where the event was triggered await say(f"Hey there <@{message['user']}>!") # Start your app if __name__ == "__main__": app.start(port=int(os.environ.get("PORT", 3000))) ``` -------------------------------- ### Get Single Group Request Source: https://docs.slack.dev/reference/scim-api Example HTTP GET request to retrieve a specific group resource by its ID. ```http GET /scim/v1/Groups/42 HTTP/1.1 Host: api.slack.com Accept: application/json Authorization: Bearer xoxp-4956040672-4956040692-6476208902-xxxxxx ``` -------------------------------- ### Navigate to App Directory Source: https://docs.slack.dev/tools/bolt-js/deployments/heroku Change into the cloned application's directory to start configuration. ```bash cd bolt-js-getting-started-app/ ``` -------------------------------- ### GET /slack/install Source: https://docs.slack.dev/tools/bolt-python/reference/adapter/starlette/async_handler.html Handles the OAuth installation flow for Slack applications, including the initial installation page and the callback redirect. ```APIDOC ## GET /slack/install ### Description Handles the OAuth installation process. This endpoint is triggered when a user initiates the installation or returns from the Slack authorization page. ### Method GET ### Endpoint /slack/install ### Parameters #### Query Parameters - **code** (string) - Optional - The authorization code returned by Slack during the callback phase. ### Response #### Success Response (200) - **content** (string) - HTML or redirect response for the installation flow. ``` -------------------------------- ### start(port, path, host) Source: https://docs.slack.dev/tools/bolt-python/reference/app/async_app.html Starts a web server using AIOHTTP to handle incoming requests from Slack. ```APIDOC ## start(port, path, host) ### Description Start a web server using AIOHTTP. ### Parameters - **port** (int) - Optional - The port to listen on (Default: 3000) - **path** (str) - Optional - The path to handle request from Slack (Default: `/slack/events`) - **host** (str | None) - Optional - The hostname to serve the web endpoints. (Default: 0.0.0.0) ``` -------------------------------- ### Handle GET requests in AsyncSlackAppServer Source: https://docs.slack.dev/tools/bolt-python/reference/app/async_server.html Processes incoming GET requests, specifically handling OAuth installation and callback paths if configured. ```python async def handle_get_requests(self, request: web.Request) -> web.Response: oauth_flow = self._bolt_oauth_flow if oauth_flow: if request.path == oauth_flow.install_path: bolt_req = await to_bolt_request(request) bolt_resp = await oauth_flow.handle_installation(bolt_req) return await to_aiohttp_response(bolt_resp) elif request.path == oauth_flow.redirect_uri_path: bolt_req = await to_bolt_request(request) bolt_resp = await oauth_flow.handle_callback(bolt_req) return await to_aiohttp_response(bolt_resp) else: return web.Response(status=404) else: return web.Response(status=404) ``` -------------------------------- ### Get Custom Installation Value Source: https://docs.slack.dev/tools/python-slack-sdk/reference/oauth/installation_store/index.html Retrieves a custom value from the installation data by its name. Returns None if the custom value does not exist. ```python def get_custom_value(self, name: str) -> Optional[Any]: return self.custom_values.get(name) ``` -------------------------------- ### Run with Custom App Entry Point Source: https://docs.slack.dev/tools/slack-cli/reference/commands/slack_platform_run Starts a local development server using a specified Python file as the app's entry point. Ensure the path is correct relative to your project root. ```bash slack platform run ./src/app.py ``` -------------------------------- ### GET /Groups Response Example Source: https://docs.slack.dev/reference/scim-api This is an example response for retrieving a list of groups. It includes pagination details and a list of group resources. ```json { "schemas": [ "urn:ietf:params:scim:api:messages:2.0:ListResponse" ], "Resources": [ { "schemas": [ "urn:ietf:params:scim:schemas:core:2.0:Group" ], "id": "S123ABC456", "meta": { "created": "2022-07-26T14:05:41-07:00", "location": "https://api.slack.com/scim/v2/Groups/S123ABC456" }, "displayName": "SOMETHING NEW", "members": [] } ], "totalResults": 15, "itemsPerPage": 1, "startIndex": 1 } ``` -------------------------------- ### Get Groups List Request Source: https://docs.slack.dev/reference/scim-api Example HTTP GET request to retrieve a paginated list of groups. Use 'startIndex' and 'count' for pagination. ```http GET /scim/v1/Groups?startIndex=4&count=500 HTTP/1.1 Host: api.slack.com Accept: application/json Authorization: Bearer xoxp-4956040672-4956040692-6476208902-xxxxxx ``` -------------------------------- ### Configure Installation Management Source: https://docs.slack.dev/tools/bolt-python/reference/oauth/oauth_settings.html Sets up the installation store, token rotation, and user token resolution strategy. Uses default installation store if none is provided. ```python # Installation Management self.installation_store = installation_store or get_or_create_default_installation_store(client_id) self.user_token_resolution = user_token_resolution or "authed_user" self.installation_store_bot_only = installation_store_bot_only self.token_rotation_expiration_minutes = token_rotation_expiration_minutes self.authorize = InstallationStoreAuthorize( logger=logger, client_id=self.client_id, client_secret=self.client_secret, token_rotation_expiration_minutes=self.token_rotation_expiration_minutes, installation_store=self.installation_store, bot_only=self.installation_store_bot_only, user_token_resolution=user_token_resolution, ) ``` -------------------------------- ### Get Custom Value from Installation Store Source: https://docs.slack.dev/tools/python-slack-sdk/reference/oauth/installation_store/index.html Retrieves a custom value associated with a specific key from the installation store. Returns None if the key is not found. ```python def get_custom_value(self, name: str) -> Optional[Any]: return self.custom_values.get(name) ``` -------------------------------- ### Create Slack Project from Welcome Bot Template Source: https://docs.slack.dev/tools/deno-slack-sdk/tutorials/welcome-bot This command utilizes the Slack CLI to create a new Slack application project directly from the pre-built 'Welcome Bot' template repository. This is an alternative to starting with a blank template and manually adding files. ```bash slack create welcome-bot-app --template https://github.com/slack-samples/deno-welcome-bot ``` -------------------------------- ### Handle installation initiation Source: https://docs.slack.dev/tools/bolt-python/reference/oauth/async_oauth_flow.html Initiates the installation flow by generating an authorization URL and optionally creating a new state and cookie if state validation is enabled. ```python async def handle_installation(self, request: AsyncBoltRequest) -> BoltResponse: set_cookie_value: Optional[str] = None url = await self.build_authorize_url("", request) if self.settings.state_validation_enabled is True: state = await self.issue_new_state(request) url = await self.build_authorize_url(state, request) set_cookie_value = self.settings.state_utils.build_set_cookie_for_new_state(state) if self.settings.install_page_rendering_enabled: ``` -------------------------------- ### Start Bolt App with OAuth Source: https://docs.slack.dev/tools/bolt-python/concepts/adding-agent-features Run your Bolt for Python application using OAuth. This command starts the app, and you will be provided with an install URL to add it to your workspace. ```bash slack run app_oauth.py ``` -------------------------------- ### init() Method Source: https://docs.slack.dev/tools/python-slack-sdk/reference/oauth/installation_store/sqlite3/index.html Initializes the database by checking for the existence of the 'slack_installations' table. If the table does not exist, it calls `create_tables()`. ```APIDOC ## Method: init() ### Description Initializes the database by checking for the existence of the 'slack_installations' table. If the table does not exist, it calls `create_tables()`. ### Usage ```python store = SQLite3InstallationStore(database='my_installations.db', client_id='YOUR_CLIENT_ID') store.init() ``` ``` -------------------------------- ### app.start Source: https://docs.slack.dev/tools/bolt-python/reference/index.html Starts a web server for local development. ```APIDOC ## start ### Description Starts a web server for local development. ### Method Signature `start(self, port: int = 3000, path: str = '/slack/events', http_server_logger_enabled: bool = True) -> None` ### Parameters #### `port` - **Type**: `int` - **Description**: The port to listen on (Default: 3000) #### `path` - **Type**: `str` - **Description**: The path to handle request from Slack (Default: `/slack/events`) #### `http_server_logger_enabled` - **Type**: `bool` - **Description**: The flag to enable http.server logging if True (Default: True) ### Usage Example ```python # With the default settings, `http://localhost:3000/slack/events` # is available for handling incoming requests from Slack app.start() ``` ### Notes This method internally starts a Web server process built with the `http.server` module. For production, consider using a production-ready WSGI server such as Gunicorn. ``` -------------------------------- ### Install Requirements for Sanic Integration Source: https://docs.slack.dev/tools/bolt-python/concepts/async These commands are used to install the necessary Python packages for integrating Bolt with the Sanic web framework and to start the Sanic server. ```bash pip install slack_bolt sanic uvicorn # Save the source as async_app.py uvicorn async_app:api --reload --port 3000 --log-level debug ``` -------------------------------- ### app.start Source: https://docs.slack.dev/tools/bolt-python/reference Starts a web server for local development. ```APIDOC ## start ### Description Starts a web server for local development. ### Method Signature `def start(self, port: int = 3000, path: str = '/slack/events', http_server_logger_enabled: bool = True) -> None` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters * **port** (int) - Optional - The port to listen on (Default: 3000) * **path** (str) - Optional - The path to handle request from Slack (Default: `/slack/events`) * **http_server_logger_enabled** (bool) - Optional - The flag to enable http.server logging if True (Default: True) ### Request Example ```python # With the default settings, `http://localhost:3000/slack/events` # is available for handling incoming requests from Slack app.start() ``` ### Response #### Success Response None #### Response Example None ``` -------------------------------- ### GET /Groups/ Response Example Source: https://docs.slack.dev/reference/scim-api This is an example response for retrieving a specific group. It includes the group's ID, display name, and a list of its members. ```json { "schemas": [ "urn:ietf:params:scim:schemas:core:2.0:Group" ], "id": "S123ABC456", "meta": { "created": "2023-02-10T07:36:51-08:00", "location": "https://api.slack.com/scim/v2/Groups/S123ABC456" }, "displayName": "Applications-600", "members": [ { "value": "U123ABC456", "display": "Lexus Powlowski" }, { "value": "U123ABC456", "display": "Porter Prosacco" } ] } ``` -------------------------------- ### List Node.js Samples Source: https://docs.slack.dev/tools/slack-cli/reference/commands/slack_project_samples Use the `--list` and `--language` flags to display available sample apps for a specific runtime, like Node.js. ```bash $ slack samples --list --language node # List Bolt for JavaScript samples ``` -------------------------------- ### Maven Command to Compile and Run Example Source: https://docs.slack.dev/tools/java-slack-sdk/guides/web-api-client-setup Execute this Maven command in your terminal to compile your Java project and run the Example main class. This verifies your setup. ```bash mvn compile exec:java \ -Dexec.cleanupDaemonThreads=false \ -Dexec.mainClass="Example" ``` -------------------------------- ### Install Local Dev App to a Specific Team Source: https://docs.slack.dev/tools/slack-cli/reference/commands/slack_app_install Example of installing a local development Slack app to a specific team, specifying the team ID and the local environment. ```bash $ slack app install --team T0123456 --environment local ``` -------------------------------- ### app.start() Source: https://docs.slack.dev/tools/bolt-python/reference/app/app.html Starts the web server to handle incoming requests from Slack. It's recommended to use a production-ready WSGI server for production environments. ```APIDOC ## app.start() ### Description Starts a web server process to handle incoming requests from Slack. For production, consider using a production-ready WSGI server such as Gunicorn. ### Method POST ### Endpoint / ### Parameters #### Query Parameters - **port** (integer) - Optional - The port to listen on (Default: 3000) - **path** (string) - Optional - The path to handle request from Slack (Default: `/slack/events`) - **http_server_logger_enabled** (boolean) - Optional - Enable http.server logging if True (Default: True) ``` -------------------------------- ### Initialize and Connect to SQLite Database Source: https://docs.slack.dev/tools/python-slack-sdk/reference/oauth/installation_store/sqlite3/index.html The `init` method checks for the existence of the `slack_installations` table and creates it if it doesn't exist. The `connect` method establishes a connection to the SQLite database, ensuring initialization has occurred. ```python def init(self): try: with sqlite3.connect(database=self.database) as conn: cur = conn.execute("select count(1) from slack_installations;") row_num = cur.fetchone()[0] self.logger.debug(f"{row_num} installations are stored in {self.database}") except Exception: self.create_tables() self.init_called = True def connect(self) -> Connection: if not self.init_called: self.init() return sqlite3.connect(database=self.database) ``` -------------------------------- ### Starting the Web Server Source: https://docs.slack.dev/tools/bolt-python/reference/async_app.html This section explains how to start a web server using AIOHTTP to handle requests from Slack. ```APIDOC ## POST /slack/events (Web Server Start) ### Description Start a web server using AIOHTTP. This server will handle incoming requests from Slack. ### Method POST (Implicitly, as part of app startup) ### Endpoint `/slack/events` (or configured path) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None (This method is used in code, not directly via an HTTP request body) ### Request Example ```python app.start(port=3000, path="/slack/events", host="0.0.0.0") ``` ### Response #### Success Response (200) None (This method starts a server and does not return a value) #### Response Example None ``` -------------------------------- ### Slack App List Command Example Source: https://docs.slack.dev/tools/slack-cli/reference/commands/slack_app_list This example demonstrates how to use the `slack app list` command to display all teams where the app is currently installed. This is the most common usage scenario. ```bash $ slack app list # List all teams with the app installed ``` -------------------------------- ### fetchInstallation Source: https://docs.slack.dev/tools/node-slack-sdk/reference/oauth/classes/FileInstallationStore Fetches an installation from the store based on the provided query. This method is part of the InstallationStore interface. ```APIDOC ## fetchInstallation ```typescript fetchInstallation(query: InstallationQuery, logger?: Logger): Promise>; ``` ### Description Fetches an installation from the store based on the provided query. This method is part of the InstallationStore interface. ### Parameters #### query (InstallationQuery) An object that specifies the criteria for finding the installation to fetch. #### logger? (Logger) Optional. A logger instance for logging. ### Returns A Promise that resolves with the found Installation object. The installation can be of version "v1" or "v2". ``` -------------------------------- ### Java Example for API Client Verification Source: https://docs.slack.dev/tools/java-slack-sdk/guides/web-api-client-setup Create a Java class with a main method to test the Slack API client setup. This example makes a simple apiTest call. ```java import com.slack.api.Slack; import com.slack.api.methods.response.api.ApiTestResponse; public class Example { public static void main(String[] args) throws Exception { Slack slack = Slack.getInstance(); ApiTestResponse response = slack.methods().apiTest(r -> r.foo("bar")); System.out.println(response); } } ``` -------------------------------- ### Example: Get Trigger Details with App ID Source: https://docs.slack.dev/tools/slack-cli/reference/commands/slack_trigger_info Shows how to get trigger details by specifying both the trigger ID and the app ID using the `--trigger-id` and `--app` flags. ```bash $ slack trigger info --trigger-id Ft01234ABCD --app A0123456 ``` -------------------------------- ### Initialize FileInstallationStore Source: https://docs.slack.dev/tools/python-slack-sdk/reference/oauth/installation_store/file/index.html Instantiate FileInstallationStore with optional parameters for base directory, historical data, client ID, and logger. ```python from pathlib import Path import logging from slack_sdk.oauth.installation_store.file import FileInstallationStore installation_store = FileInstallationStore( base_dir=str(Path.home()) + "/.bolt-app-installation", historical_data_enabled=True, client_id="YOUR_CLIENT_ID", logger=logging.getLogger(__name__) ) ``` -------------------------------- ### Example: Create a new project from a template Source: https://docs.slack.dev/tools/slack-cli/reference/commands/slack_project_create Demonstrates how to create a new Slack project named 'my-project' using the default template. ```bash slack create my-project ``` -------------------------------- ### Example: Create a new AI Agent app Source: https://docs.slack.dev/tools/slack-cli/reference/commands/slack_project_create Shows how to create a new AI Agent app named 'my-agent-app' using the 'agent' shortcut. ```bash slack create agent my-agent-app ``` -------------------------------- ### Org-wide installQuery Object Source: https://docs.slack.dev/tools/bolt-js/concepts/authenticating-oauth An example of the `installQuery` object, which includes `enterpriseId` and `isEnterpriseInstall` for org-wide installations. ```json { userId: "U0000000001", isEnterpriseInstall: true, teamId: "T0000000001", enterpriseId: "E0000000001", conversationId: "D0000000001" } ``` -------------------------------- ### InstallProvider Handle Install Path Method Source: https://docs.slack.dev/tools/node-slack-sdk/reference/oauth/classes/InstallProvider Handles requests to the install path (e.g., /slack/install) from an app installer. It manages the initial steps of the installation process. ```typescript handleInstallPath( req, res, options?, installOptions?): Promise; ``` -------------------------------- ### Get an item from the datastore Source: https://docs.slack.dev/tools/slack-cli/reference/commands/slack_datastore_get Example of retrieving a specific item from the 'tasks' datastore using its ID. ```bash $ slack datastore get --datastore tasks '{"id": "42"}' ``` -------------------------------- ### GET /slack/install & /slack/oauth_redirect Source: https://docs.slack.dev/tools/bolt-python/reference/adapter/tornado/index.html Handles Slack OAuth installation flow and the subsequent callback redirect. ```APIDOC ## GET /slack/install ### Description Initiates the Slack OAuth installation flow. ### Method GET ### Endpoint /slack/install ## GET /slack/oauth_redirect ### Description Handles the callback from Slack after the user authorizes the application. ### Method GET ### Endpoint /slack/oauth_redirect ### Query Parameters - **code** (string) - Required - The authorization code provided by Slack. - **state** (string) - Required - The state parameter for CSRF protection. ``` -------------------------------- ### start Source: https://docs.slack.dev/tools/bolt-python/reference/app/index.html Starts a web server for local development, allowing you to test your Slack app locally. ```APIDOC ## start ### Description Starts a web server for local development. With the default settings, `http://localhost:3000/slack/events` is available for handling incoming requests from Slack. This method internally starts a Web server process built with the `http.server` module. For production, consider using a production-ready WSGI server such as Gunicorn. ### Method `start( port: int = 3000, path: str = "/slack/events", http_server_logger_enabled: bool = True, )` ### Parameters #### Arguments - **port** (`int`) - Optional - The port to listen on (Default: 3000) - **path** (`str`) - Optional - The path to handle request from Slack (Default: `/slack/events`) - **http_server_logger_enabled** (`bool`) - Optional - The flag to enable http.server logging if True (Default: True) ``` -------------------------------- ### Incoming Webhooks - cURL Example Source: https://docs.slack.dev/tools/java-slack-sdk/guides/incoming-webhooks This example demonstrates how to send a simple text message to a Slack channel using a cURL command and an incoming webhook URL. ```APIDOC ## POST /services/{team_id}/{channel_id}/{token} ### Description Sends a JSON payload to a Slack incoming webhook URL to post a message. ### Method POST ### Endpoint `https://hooks.slack.com/services/T1234567/AAAAAAAA/ZZZZZZ` ### Parameters #### Query Parameters None #### Request Body - **text** (string) - Required - The message text to send. ### Request Example ```bash curl -X POST \ -H 'Content-type: application/json' \ -d '{"text":"Hello, World!"}' \ https://hooks.slack.com/services/T1234567/AAAAAAAA/ZZZZZZ ``` ### Response #### Success Response (200) - **body** (string) - 'ok' #### Response Example ```json { "code": 200, "message": "OK", "body": "ok" } ``` #### Error Response (404) - **body** (string) - Error code (e.g., 'no_team') #### Error Response Example ```json { "code": 404, "message": "Not Found", "body": "no_team" } ``` ``` -------------------------------- ### Create Blank Slack Project with CLI Source: https://docs.slack.dev/tools/deno-slack-sdk/tutorials/welcome-bot This command uses the Slack CLI to create a new Slack application project from a blank template. It initializes the project structure and necessary configuration files for a Deno-based Slack app. ```bash slack create welcome-bot-app --template https://github.com/slack-samples/deno-blank-template ```