From 18a75f16e451eeb0ded8bf4d1ee264acb2f3770f Mon Sep 17 00:00:00 2001 From: Eden Zimbelman Date: Tue, 14 Jul 2026 16:45:43 -0700 Subject: [PATCH 01/11] feat(methods): add chat.postMessage example (compile-only) Add a methods/ chat.postMessage example verified by compilation alone, with no MockWebServer test. Because chatPostMessage and its request builder are strongly typed, javac catches wrong or misspelled arguments (e.g. .chnnel(...) -> cannot find symbol) at compile time without a mock server. This is an alternative to the MockWebServer runtime-test approach for side-by-side comparison. Co-Authored-By: Claude --- methods/.gitignore | 4 ++ methods/README.md | 21 ++++++ methods/pom.xml | 69 +++++++++++++++++++ .../src/main/java/chat/ChatPostMessage.java | 38 ++++++++++ 4 files changed, 132 insertions(+) create mode 100644 methods/.gitignore create mode 100644 methods/README.md create mode 100644 methods/pom.xml create mode 100644 methods/src/main/java/chat/ChatPostMessage.java diff --git a/methods/.gitignore b/methods/.gitignore new file mode 100644 index 0000000..beef00d --- /dev/null +++ b/methods/.gitignore @@ -0,0 +1,4 @@ +.classpath +.project +.settings +target diff --git a/methods/README.md b/methods/README.md new file mode 100644 index 0000000..ac32962 --- /dev/null +++ b/methods/README.md @@ -0,0 +1,21 @@ +# Methods + +Individual Slack Web API method calls with the `slack-api-client`. + +Read the [docs](https://docs.slack.dev/reference/methods) to explore every method, or explore implementations of specific families. + +## What's on display + +### chat + +- **[chat.postMessage](https://docs.slack.dev/reference/methods/chat.postmessage)**: Sends a message to a channel. [Implementation](./src/main/java/chat/ChatPostMessage.java). Scopes: `chat:write`. + +## Running an example + +Set a bot token and run an example class directly: + +```sh +export SLACK_TOKEN="xoxb-your-token" +mvn compile exec:java -Dexec.mainClass=chat.ChatPostMessage +``` + diff --git a/methods/pom.xml b/methods/pom.xml new file mode 100644 index 0000000..7938b8e --- /dev/null +++ b/methods/pom.xml @@ -0,0 +1,69 @@ + + 4.0.0 + com.slack.api + methods-examples + 0.1-SNAPSHOT + jar + + UTF-8 + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.15.0 + + 17 + + + + com.diffplug.spotless + spotless-maven-plugin + 3.7.0 + + + + + .gitignore + + + + + true + 4 + + + + + + + + + + **/*.md + + + + + + + + apply + + compile + + + + + + + + com.slack.api + slack-api-client + 1.49.0 + + + diff --git a/methods/src/main/java/chat/ChatPostMessage.java b/methods/src/main/java/chat/ChatPostMessage.java new file mode 100644 index 0000000..4a25283 --- /dev/null +++ b/methods/src/main/java/chat/ChatPostMessage.java @@ -0,0 +1,38 @@ +package chat; + +import com.slack.api.Slack; +import com.slack.api.methods.MethodsClient; +import com.slack.api.methods.SlackApiException; +import com.slack.api.methods.request.chat.ChatPostMessageRequest; +import com.slack.api.methods.response.chat.ChatPostMessageResponse; +import java.io.IOException; + +/** + * Sends a message to a channel with the chat.postMessage method. + * {@link https://docs.slack.dev/reference/methods/chat.postmessage} + */ +public class ChatPostMessage { + + public static ChatPostMessageResponse example01(Slack slack) throws IOException, SlackApiException { + // Read a token from the environment variables + String token = System.getenv("SLACK_TOKEN"); + + // Initialize an API Methods client with the given token + MethodsClient methods = slack.methods(token); + + // Build a request object + ChatPostMessageRequest request = ChatPostMessageRequest.builder() + .channel("C123ABC456") + .text("Here's a message for you") + .build(); + + // Get a response as a Java object + ChatPostMessageResponse response = methods.chatPostMessage(request); + + return response; + } + + public static void main(String[] args) throws IOException, SlackApiException { + System.out.println(example01(Slack.getInstance())); + } +} From 0107befae39d86fc089bffdd549adb41a246dd90 Mon Sep 17 00:00:00 2001 From: Eden Zimbelman Date: Tue, 14 Jul 2026 16:46:09 -0700 Subject: [PATCH 02/11] docs: list methods example set in README Co-Authored-By: Claude --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 18d2e26..725365d 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,4 @@ This collections of examples highlights features of a Slack app in the language ## Available demonstration - **[Block Kit](./block-kit)**: The framework of visual components arranged to create app layouts. +- **[Methods](./methods)**: Individual Slack Web API method calls with the `slack-api-client`. From d38a177b437b8f664802fd97fbaf7a3ec3d450d1 Mon Sep 17 00:00:00 2001 From: Eden Zimbelman Date: Tue, 14 Jul 2026 16:55:26 -0700 Subject: [PATCH 03/11] ci: run methods showcase in CI Add the methods example module to the CI matrix. The compile-only example has no test class; `mvn test` compiles it and runs zero tests, so CI verifies it builds and passes spotless. Co-Authored-By: Claude --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2167c77..c639a83 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,6 +12,7 @@ jobs: matrix: showcase: - "block-kit" + - "methods" steps: - name: Checkout code uses: actions/checkout@v7 From 32ecd742580d8702ceb09c83de5bde492883ef94 Mon Sep 17 00:00:00 2001 From: Eden Zimbelman Date: Wed, 15 Jul 2026 00:19:59 -0700 Subject: [PATCH 04/11] feat(methods): add per-family manifest; align README copy Match the runtime branch: add a chat manifest.json requesting only chat:write, move the scope out of the README into the manifest, and use the method's exact docs description. Co-Authored-By: Claude --- methods/README.md | 4 ++-- methods/src/main/java/chat/manifest.json | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 methods/src/main/java/chat/manifest.json diff --git a/methods/README.md b/methods/README.md index ac32962..4749cee 100644 --- a/methods/README.md +++ b/methods/README.md @@ -8,11 +8,11 @@ Read the [docs](https://docs.slack.dev/reference/methods) to explore every metho ### chat -- **[chat.postMessage](https://docs.slack.dev/reference/methods/chat.postmessage)**: Sends a message to a channel. [Implementation](./src/main/java/chat/ChatPostMessage.java). Scopes: `chat:write`. +- **[chat.postMessage](https://docs.slack.dev/reference/methods/chat.postmessage)**: Sends a message to a channel. [Implementation](./src/main/java/chat/ChatPostMessage.java). ## Running an example -Set a bot token and run an example class directly: +Each family ships a [`manifest.json`](./src/main/java/chat/manifest.json) requesting only the scopes it needs (`chat` → `chat:write`). Create an app from it, then set a bot token and run an example class directly: ```sh export SLACK_TOKEN="xoxb-your-token" diff --git a/methods/src/main/java/chat/manifest.json b/methods/src/main/java/chat/manifest.json new file mode 100644 index 0000000..ad13ee2 --- /dev/null +++ b/methods/src/main/java/chat/manifest.json @@ -0,0 +1,22 @@ +{ + "display_information": { + "name": "Slack API Methods", + "description": "Example implementations to call \"chat\" methods" + }, + "features": { + "bot_user": { + "display_name": "Slack API Methods", + "always_online": true + } + }, + "oauth_config": { + "scopes": { + "bot": ["chat:write"] + } + }, + "settings": { + "org_deploy_enabled": true, + "socket_mode_enabled": false, + "token_rotation_enabled": false + } +} From 3f65113a7b86a886d3be1194e8610d352b1a91ee Mon Sep 17 00:00:00 2001 From: Eden Zimbelman Date: Tue, 11 Aug 2026 20:34:03 -0700 Subject: [PATCH 05/11] docs(methods): align README with the shared examples pattern MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mirror the bolt-js-examples methods README: tighten the intro, add a 'Making a request' walkthrough, and rename 'What's on display' to 'What's on call'. Keep the Maven layout and run command intact — the walkthrough runs from the project root (cd methods) where 'mvn compile exec:java' resolves. --- methods/README.md | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/methods/README.md b/methods/README.md index 4749cee..93e5c17 100644 --- a/methods/README.md +++ b/methods/README.md @@ -1,21 +1,21 @@ # Methods -Individual Slack Web API method calls with the `slack-api-client`. +An interface for querying information from and enacting change in a Slack workspace. -Read the [docs](https://docs.slack.dev/reference/methods) to explore every method, or explore implementations of specific families. +Read the [docs](https://docs.slack.dev/apis/web-api/) for explanations of concepts, or explore [reference](https://docs.slack.dev/reference/methods) pages for specific functionalities. -## What's on display - -### chat - -- **[chat.postMessage](https://docs.slack.dev/reference/methods/chat.postmessage)**: Sends a message to a channel. [Implementation](./src/main/java/chat/ChatPostMessage.java). - -## Running an example - -Each family ships a [`manifest.json`](./src/main/java/chat/manifest.json) requesting only the scopes it needs (`chat` → `chat:write`). Create an app from it, then set a bot token and run an example class directly: +## Making a request ```sh -export SLACK_TOKEN="xoxb-your-token" -mvn compile exec:java -Dexec.mainClass=chat.ChatPostMessage +$ cd methods # Navigate to the project root +$ slack install --environment local # Create an app +$ vim src/main/java/chat/ChatPostMessage.java # Edit arguments +$ export SLACK_TOKEN=xoxb-example # Set if unchanged +$ mvn compile exec:java -Dexec.mainClass=chat.ChatPostMessage # Make the request ``` +## What's on call + +### chat + +- **[chat.postMessage](https://docs.slack.dev/reference/methods/chat.postmessage)**: Sends a message to a channel. [Implementation](./src/main/java/chat/ChatPostMessage.java). From 4cce3705802f2b2a4d278e50efad17d9373bd4b2 Mon Sep 17 00:00:00 2001 From: Eden Zimbelman Date: Tue, 11 Aug 2026 20:38:05 -0700 Subject: [PATCH 06/11] docs(methods): end README with a trailing blank line for Spotless The flexmark markdown formatter (spotless-maven-plugin) requires the file to end with a blank line; the mirrored README ended on the content line, failing 'spotless:check' in CI. --- methods/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/methods/README.md b/methods/README.md index 93e5c17..0e5f0de 100644 --- a/methods/README.md +++ b/methods/README.md @@ -19,3 +19,4 @@ $ mvn compile exec:java -Dexec.mainClass=chat.ChatPostMessage # Make the reques ### chat - **[chat.postMessage](https://docs.slack.dev/reference/methods/chat.postmessage)**: Sends a message to a channel. [Implementation](./src/main/java/chat/ChatPostMessage.java). + From 87756c0deabb56faba49de119b83136a7f83c071 Mon Sep 17 00:00:00 2001 From: Eden Zimbelman Date: Tue, 11 Aug 2026 20:56:32 -0700 Subject: [PATCH 07/11] refactor(methods): inline the chat.postMessage example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Flatten the example to mirror the bolt-js counterpart: perform the call flow directly in main() rather than delegating to example01(). Java still requires the class and main shell, but the body now reads top-to-bottom — read the token, initialize the client, call the method. Drops the now-unused ChatPostMessageResponse import. --- .../src/main/java/chat/ChatPostMessage.java | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/methods/src/main/java/chat/ChatPostMessage.java b/methods/src/main/java/chat/ChatPostMessage.java index 4a25283..299f236 100644 --- a/methods/src/main/java/chat/ChatPostMessage.java +++ b/methods/src/main/java/chat/ChatPostMessage.java @@ -4,7 +4,6 @@ import com.slack.api.methods.MethodsClient; import com.slack.api.methods.SlackApiException; import com.slack.api.methods.request.chat.ChatPostMessageRequest; -import com.slack.api.methods.response.chat.ChatPostMessageResponse; import java.io.IOException; /** @@ -13,26 +12,18 @@ */ public class ChatPostMessage { - public static ChatPostMessageResponse example01(Slack slack) throws IOException, SlackApiException { + public static void main(String[] args) throws IOException, SlackApiException { // Read a token from the environment variables String token = System.getenv("SLACK_TOKEN"); - // Initialize an API Methods client with the given token - MethodsClient methods = slack.methods(token); + // Initialize + MethodsClient methods = Slack.getInstance().methods(token); - // Build a request object + // Call the chat.postMessage method ChatPostMessageRequest request = ChatPostMessageRequest.builder() .channel("C123ABC456") .text("Here's a message for you") .build(); - - // Get a response as a Java object - ChatPostMessageResponse response = methods.chatPostMessage(request); - - return response; - } - - public static void main(String[] args) throws IOException, SlackApiException { - System.out.println(example01(Slack.getInstance())); + methods.chatPostMessage(request); } } From 941f3980b7ccb2b081ad0da6cf345a6761e015a0 Mon Sep 17 00:00:00 2001 From: Eden Zimbelman Date: Tue, 11 Aug 2026 22:19:14 -0700 Subject: [PATCH 08/11] docs: align methods description in the examples list Match the methods entry to its README: 'An interface for querying information from and enacting change in a Slack workspace' rather than the outdated 'Individual Slack Web API method calls' phrasing. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 725365d..bc305e3 100644 --- a/README.md +++ b/README.md @@ -5,4 +5,4 @@ This collections of examples highlights features of a Slack app in the language ## Available demonstration - **[Block Kit](./block-kit)**: The framework of visual components arranged to create app layouts. -- **[Methods](./methods)**: Individual Slack Web API method calls with the `slack-api-client`. +- **[Methods](./methods)**: An interface for querying information from and enacting change in a Slack workspace. From 465c14e7e5d231f11eb44203d53e4f5120716702 Mon Sep 17 00:00:00 2001 From: Eden Zimbelman Date: Tue, 11 Aug 2026 22:31:15 -0700 Subject: [PATCH 09/11] docs(methods): correct token comment to singular The example reads one variable (SLACK_TOKEN), so 'an environment variable' is more accurate than the plural. --- methods/src/main/java/chat/ChatPostMessage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/methods/src/main/java/chat/ChatPostMessage.java b/methods/src/main/java/chat/ChatPostMessage.java index 299f236..b9abd30 100644 --- a/methods/src/main/java/chat/ChatPostMessage.java +++ b/methods/src/main/java/chat/ChatPostMessage.java @@ -13,7 +13,7 @@ public class ChatPostMessage { public static void main(String[] args) throws IOException, SlackApiException { - // Read a token from the environment variables + // Read a token from an environment variable String token = System.getenv("SLACK_TOKEN"); // Initialize From 2bfe03a2b710f92de760751bd2062df04250100f Mon Sep 17 00:00:00 2001 From: Eden Zimbelman Date: Fri, 14 Aug 2026 16:10:46 -0700 Subject: [PATCH 10/11] feat(methods): run the chat.postMessage example and print its response Add the exec-maven-plugin so `mvn exec:java` actually runs the class, and disable cleanupDaemonThreads so the run exits promptly instead of hanging on the SDK's background threads. Capture and print the response so a run shows its outcome. Co-Authored-By: Claude --- methods/README.md | 2 +- methods/pom.xml | 8 ++++++++ methods/src/main/java/chat/ChatPostMessage.java | 6 +++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/methods/README.md b/methods/README.md index 0e5f0de..1bd5d8e 100644 --- a/methods/README.md +++ b/methods/README.md @@ -8,7 +8,7 @@ Read the [docs](https://docs.slack.dev/apis/web-api/) for explanations of concep ```sh $ cd methods # Navigate to the project root -$ slack install --environment local # Create an app +$ slack app settings # Create an app $ vim src/main/java/chat/ChatPostMessage.java # Edit arguments $ export SLACK_TOKEN=xoxb-example # Set if unchanged $ mvn compile exec:java -Dexec.mainClass=chat.ChatPostMessage # Make the request diff --git a/methods/pom.xml b/methods/pom.xml index 7938b8e..845188c 100644 --- a/methods/pom.xml +++ b/methods/pom.xml @@ -19,6 +19,14 @@ 17 + + org.codehaus.mojo + exec-maven-plugin + 3.5.1 + + false + + com.diffplug.spotless spotless-maven-plugin diff --git a/methods/src/main/java/chat/ChatPostMessage.java b/methods/src/main/java/chat/ChatPostMessage.java index b9abd30..12436c9 100644 --- a/methods/src/main/java/chat/ChatPostMessage.java +++ b/methods/src/main/java/chat/ChatPostMessage.java @@ -4,6 +4,7 @@ import com.slack.api.methods.MethodsClient; import com.slack.api.methods.SlackApiException; import com.slack.api.methods.request.chat.ChatPostMessageRequest; +import com.slack.api.methods.response.chat.ChatPostMessageResponse; import java.io.IOException; /** @@ -24,6 +25,9 @@ public static void main(String[] args) throws IOException, SlackApiException { .channel("C123ABC456") .text("Here's a message for you") .build(); - methods.chatPostMessage(request); + ChatPostMessageResponse response = methods.chatPostMessage(request); + + // Inspect the response + System.out.println(response); } } From 8e205aa726c1b15adc0d5ec94eaa1cd74f373074 Mon Sep 17 00:00:00 2001 From: Eden Zimbelman Date: Fri, 14 Aug 2026 16:37:43 -0700 Subject: [PATCH 11/11] docs: drop class Javadoc from ChatPostMessage example The docs link lives in the methods README (source of truth); the per-file class comment was redundant and used a malformed {@link URL}. Removing it keeps the example set uniform (no per-class doc comments). Co-Authored-By: Claude --- methods/src/main/java/chat/ChatPostMessage.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/methods/src/main/java/chat/ChatPostMessage.java b/methods/src/main/java/chat/ChatPostMessage.java index 12436c9..9ad984d 100644 --- a/methods/src/main/java/chat/ChatPostMessage.java +++ b/methods/src/main/java/chat/ChatPostMessage.java @@ -7,10 +7,6 @@ import com.slack.api.methods.response.chat.ChatPostMessageResponse; import java.io.IOException; -/** - * Sends a message to a channel with the chat.postMessage method. - * {@link https://docs.slack.dev/reference/methods/chat.postmessage} - */ public class ChatPostMessage { public static void main(String[] args) throws IOException, SlackApiException {