From 18a75f16e451eeb0ded8bf4d1ee264acb2f3770f Mon Sep 17 00:00:00 2001 From: Eden Zimbelman Date: Tue, 14 Jul 2026 16:45:43 -0700 Subject: [PATCH 1/4] 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 2/4] 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 3/4] 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 4/4] 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 + } +}