-
Notifications
You must be signed in to change notification settings - Fork 0
feat(methods): add chat.postMessage example #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
18a75f1
0107bef
d38a177
32ecd74
3f65113
4cce370
87756c0
941f398
465c14e
2bfe03a
8e205aa
7a775c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| .classpath | ||
| .project | ||
| .settings | ||
| target |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # Methods | ||
|
|
||
| An interface for querying information from and enacting change in a Slack workspace. | ||
|
|
||
| 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. | ||
|
|
||
| ## Making a request | ||
|
|
||
| ```sh | ||
| $ cd methods # Navigate to the project root | ||
| $ 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 | ||
| ``` | ||
|
|
||
| ## 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). | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <groupId>com.slack.api</groupId> | ||
| <artifactId>methods-examples</artifactId> | ||
| <version>0.1-SNAPSHOT</version> | ||
| <packaging>jar</packaging> | ||
| <properties> | ||
| <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| </properties> | ||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-compiler-plugin</artifactId> | ||
| <version>3.15.0</version> | ||
| <configuration> | ||
| <release>17</release> | ||
| </configuration> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.codehaus.mojo</groupId> | ||
| <artifactId>exec-maven-plugin</artifactId> | ||
| <version>3.5.1</version> | ||
| <configuration> | ||
| <cleanupDaemonThreads>false</cleanupDaemonThreads> | ||
| </configuration> | ||
| </plugin> | ||
|
Comment on lines
+22
to
+29
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👁️🗨️ note: This speeds up execution or prevents stalled waits but might not be ideal for examples. Because this is a shared configuration file for all methods I'm optimistic we can improve this without significant trouble. |
||
| <plugin> | ||
| <groupId>com.diffplug.spotless</groupId> | ||
| <artifactId>spotless-maven-plugin</artifactId> | ||
| <version>3.7.0</version> | ||
| <configuration> | ||
| <formats> | ||
| <format> | ||
| <includes> | ||
| <include>.gitignore</include> | ||
| </includes> | ||
| <trimTrailingWhitespace/> | ||
| <endWithNewline/> | ||
| <indent> | ||
| <tabs>true</tabs> | ||
| <spacesPerTab>4</spacesPerTab> | ||
| </indent> | ||
| </format> | ||
| </formats> | ||
| <java> | ||
| <palantirJavaFormat/> | ||
| </java> | ||
| <pom/> | ||
| <markdown> | ||
| <includes> | ||
| <include>**/*.md</include> | ||
| </includes> | ||
| <flexmark/> | ||
| </markdown> | ||
| </configuration> | ||
| <executions> | ||
| <execution> | ||
| <goals> | ||
| <goal>apply</goal> | ||
| </goals> | ||
| <phase>compile</phase> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>com.slack.api</groupId> | ||
| <artifactId>slack-api-client</artifactId> | ||
| <version>1.49.0</version> | ||
| </dependency> | ||
| </dependencies> | ||
|
Comment on lines
+70
to
+76
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📣 note: We keep this in 🔗 https://docs.slack.dev/tools/java-slack-sdk/guides/web-api-client-setup#build-from-source |
||
| </project> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| 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; | ||
|
|
||
| public class ChatPostMessage { | ||
|
|
||
| public static void main(String[] args) throws IOException, SlackApiException { | ||
| // Read a token from an environment variable | ||
| String token = System.getenv("SLACK_TOKEN"); | ||
|
|
||
| // Initialize | ||
| MethodsClient methods = Slack.getInstance().methods(token); | ||
|
|
||
| // Call the chat.postMessage method | ||
| ChatPostMessageRequest request = ChatPostMessageRequest.builder() | ||
| .channel("C123ABC456") | ||
| .text("Here's a message for you") | ||
| .build(); | ||
| ChatPostMessageResponse response = methods.chatPostMessage(request); | ||
|
|
||
| // Inspect the response | ||
| System.out.println(response); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🪬 note: This is vague but an included manifest can be found nested in methods.