slackapi / java-slack-sdk Goto Github PK
View Code? Open in Web Editor NEWSlack Developer Kit (including Bolt for Java) for any JVM language
Home Page: https://slack.dev/java-slack-sdk/
License: MIT License
Slack Developer Kit (including Bolt for Java) for any JVM language
Home Page: https://slack.dev/java-slack-sdk/
License: MIT License
Hello!
The Action class misses two attributes to support the dynamic menus:
private String dataSource;
private int minQueryLength;
Could you add them?
see https://api.slack.com/docs/message-menus#populate_message_menus_dynamically
I was using Spring annotation inject the Slack class, but the server failed to deploy and throws
java.lang.RuntimeException: java.lang.NoSuchMethodException: com.github.seratch.jslack.api.rtm.RTMClient.<init>()
The full stack track of exception is:
01:00:50,366 INFO [io.undertow.websockets.jsr] (ServerService Thread Pool -- 97) UT026004: Adding annotated client endpoint class com.github.seratch.jslack.api.rtm.RTMClient
01:00:50,371 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 97) MSC000001: Failed to start service jboss.undertow.deployment.default-server.default-host./axelerator: org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./project: java.lang.RuntimeException: javax.websocket.DeploymentException: UT003024: Web socket deployment failed
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:85) [wildfly-undertow-10.1.0.Final.jar:10.1.0.Final]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [rt.jar:1.8.0_191]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [rt.jar:1.8.0_191]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [rt.jar:1.8.0_191]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [rt.jar:1.8.0_191]
at java.lang.Thread.run(Thread.java:748) [rt.jar:1.8.0_191]
at org.jboss.threads.JBossThread.run(JBossThread.java:320)
Caused by: java.lang.RuntimeException: javax.websocket.DeploymentException: UT003024: Web socket deployment failed
at io.undertow.websockets.jsr.Bootstrap.handleDeployment(Bootstrap.java:101)
at io.undertow.servlet.core.DeploymentManagerImpl.handleExtensions(DeploymentManagerImpl.java:255)
at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:159)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:100) [wildfly-undertow-10.1.0.Final.jar:10.1.0.Final]
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:82) [wildfly-undertow-10.1.0.Final.jar:10.1.0.Final]
... 6 more
Caused by: javax.websocket.DeploymentException: UT003024: Web socket deployment failed
at io.undertow.websockets.jsr.ServerWebSocketContainer.addEndpointInternal(ServerWebSocketContainer.java:660)
at io.undertow.websockets.jsr.ServerWebSocketContainer.addEndpoint(ServerWebSocketContainer.java:586)
at io.undertow.websockets.jsr.Bootstrap.handleDeployment(Bootstrap.java:95)
... 10 more
Caused by: java.lang.RuntimeException: java.lang.NoSuchMethodException: com.github.seratch.jslack.api.rtm.RTMClient.<init>()
at org.jboss.as.ee.component.ReflectiveClassIntrospector.createFactory(ReflectiveClassIntrospector.java:59) [wildfly-ee-10.1.0.Final.jar:10.1.0.Final]
at org.jboss.as.ee.component.ComponentRegistry.createInstanceFactory(ComponentRegistry.java:76) [wildfly-ee-10.1.0.Final.jar:10.1.0.Final]
at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$ComponentClassIntrospector.createInstanceFactory(UndertowDeploymentInfoService.java:1444) [wildfly-undertow-10.1.0.Final.jar:10.1.0.Final]
at io.undertow.websockets.jsr.ServerWebSocketContainer.addEndpointInternal(ServerWebSocketContainer.java:654)
... 12 more
Caused by: java.lang.NoSuchMethodException: com.github.seratch.jslack.api.rtm.RTMClient.<init>()
at java.lang.Class.getConstructor0(Class.java:3082) [rt.jar:1.8.0_191]
When I deploy the project to Jboss standalone, there is no problem, any suggestion on how to fix this problem.
jslack: 1.1.6
jboss/wildfly:10.1.0.Final
I cannot find this call in the API: https://api.slack.com/scim#delete-users-id is it not implemented?
As stated in the documentation:
Messages can also include an attachments property, containing a list of attachment objects.
Here is the structure of the attachment object https://api.slack.com/docs/message-attachments#attachment_structure.
The main goal of this feature is to create new type Attachment
and add it to existing Message
type. This way when I will be doing a fetch of channel history I will be able to retrieve fo instance posted URLs.
Hi seratch !
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/slf4j/LoggerFactory;
at com.github.seratch.jslack.common.http.SlackHttpClient.(SlackHttpClient.java:12)
at com.github.seratch.jslack.Slack.(Slack.java:31)
at com.redgold.raktim.cs727.MainActivity.openSlackGame(MainActivity.java:89)
This error keeps coming. Apparently your jar in Maven repository is not dependency complete? Please tell me a correct way to include the jar. Or, please, give me a workaround. I am depending on it.
On the rest-api :
I can perform that using the below message.
{"text": "@username", "link_names": "1"}";
Just looking for the corresponding jslack code.
Thanks.
Hi, thanks for creating an awesome library. I have a question. I noticed there is more data that could be available on this method: https://api.slack.com/methods/users.identity... like avatars, team name, etc.
I was going to clone the repo and add it but I can't really get it to build. Is there something I need to do to get it to build successfully?
First, thanks for your sharing jslack ๐
I'm using the Slack Methods client and I noticed the API prefix is hardcoded in a static final
variable in MethodsClientImpl#ENDPOINT_URL_PREFIX
. It'd be very useful if we could override those prefixes from outside.
A common scenario is when you want to use something like wiremock for writing integration tests using mock calls. In those cases you need to hit the stub server instead of the real one, so you need to configure a different URL prefix. You'll need this for #36 too. I could send you a PR if you don't mind.
in your src-files' comments i found the description of the Payload's "channel()"-method
if i'm not wrong, i should be able to write to another channel, than the webhook specifies
for me that doesn't work
i created a webhook for my "#general" channel, and want to send a message to the "#random" channel
Payload payload = Payload.builder() .channel("#random")
i've used that code at payload's building, but it still sends to "#general"
is there something I'm not seeing?
thx
Hi Team,
I am trying to do pagination for few API's but the cursor response from response_metadata is missing for other api other than Conversation. Now they support few other too. Also the classic pagination option is not provided. Any idea to support that too?
Reference: https://api.slack.com/docs/pagination
Slack recently introduced a new rate-limiting system which is detailed here.
As part of this, API methods now return an HTTP 429 response (too many requests) if limits are exceeded. As is best practice, the 429 response is accompanied by a retry-after
header. This type of error is not returned as a JSON error object, but as a simple HTTP response. Example from the documentation section for 'responding to rate limit conditions':
HTTP/1.1 429 Too Many Requests
Retry-After: 30
Although it is correctly the responsibility of the client and not JSlack to implement rate limiting, the issue is that this error is not currently bubbled up to the client. There is no way for example to access the value of the Retry-After
header.
@seratch Do you have any thoughts on the best way to handle these HTTP 429 responses in JSlack? Would it make sense to add a special case to the SlackHttpClient.buildJsonResponse
method after the existing HTTP 200 handling? E.G:
if (response.code() == 200) {
...
} else if (response.code() == 429) {
...
}
I guess that would also require changes to SlackApiErrorResponse
? Is there a better design?
Current implementation of button with confirmation doesn't show the actual confirmation since uses incorrect attribute name:
Current version:
{
"name": "game",
"text": "Thermonuclear War",
"style": "danger",
"type": "button",
"value": "war",
"confirmation": {
"title": "Are you sure?",
"text": "Wouldn't you prefer a good game of chess?",
"ok_text": "Yes",
"dismiss_text": "No"
}
}
Correct version:
{
"name": "game",
"text": "Thermonuclear War",
"style": "danger",
"type": "button",
"value": "war",
"confirm": {
"title": "Are you sure?",
"text": "Wouldn't you prefer a good game of chess?",
"ok_text": "Yes",
"dismiss_text": "No"
}
}
Problem is here:
https://github.com/seratch/jslack/blob/e633154c85c2a1a5b358b41185a5c663559dd71b/src/main/java/com/github/seratch/jslack/api/model/Action.java#L45
Following the code it appears the naming convention for confirmation messages is incompatible with Slack at the moment.
I pinpointed the issue to here String json = GsonFactory.createSnakeCase().toJson(req.getAttachments());
in MethodsClientImpl.java
The outputted json includes "confirmation_message". It should be "confirm".
The primary issue is the class name from what I can tell.
ConfirmationMessage
-> Confirm
should fix the issue.
I'm not sure if the issue has arisen due to a change in Slack.
Below is the supporting documentation for the confirm button syntax (I don't know if they changed prior)
https://api.slack.com/docs/message-buttons
I Add an interactive button but I cant get the selected button with the RTM
Can you assist, please?
One important note is the changing of the message format from file -> files and some minor changes to the file object structure.
https://api.slack.com/changelog/2018-05-file-threads-soon-tread
We've experienced at least one issue with our implementation due to Slack's lack of backwards compatibility on this
Hi,
Thanks for the hard work on this, saved me a lot of time.
Can I request the addition of the groups.replies method please?
Cheers
Martin
From the docs:
The new Slack Conversations API provides your app with a unified interface to work with all the channel-like things encountered in Slack; public channels, private channels, direct messages, group direct messages, and our newest channel type, Shared Channels.The new Slack Conversations API provides your app with a unified interface to work with all the channel-like things encountered in Slack; public channels, private channels, direct messages, group direct messages, and our newest channel type, Shared Channels.
@seratch - I'm happy to do this if you agree that it adds value?
Hi,
Love this project, saving me a bunch of time and effort! Thank you!
Can you add the bot_id, username and subtype to the Message object please? If you post with a custom username it is stored in the Message username field which I can't access.
cheers
Martin
Hey ๐ @seratch If I read this code:
https://github.com/seratch/jslack/blob/master/src/main/java/com/github/seratch/jslack/shortcut/impl/ShortcutImpl.java#L122
post
and postAsBot
do exactly the same thing, for post
the call of _post()
should be _post(channel, text, Collections.emptyList(), true);
(with true
and not false
)
@Override
public ChatPostMessageResponse post(ChannelName channel, String text) throws IOException, SlackApiException {
return _post(channel, text, Collections.emptyList(), false);
}
@Override
public ChatPostMessageResponse postAsBot(ChannelName channel, String text) throws IOException, SlackApiException {
return _post(channel, text, Collections.emptyList(), false);
}
Dialogs were recently released by Slack (see here) and a dialog.open
web API has also been exposed.
Request to add support to this API in jslack.
We got Unable to find acceptable protocols error from Slack API maybe after the minor change on March 20, 2017 ( https://api.slack.com/changelog/2017-02-minor-field-changes ).
Do you have any ideas?
We got the "Unable to find acceptable protocols" error when we call doPostForm() function in the jslack/src/main/java/com/github/seratch/jslack/api/methods/impl/MethodsClientImpl.java#channelsList()
Hi, is it possible to use this library with java 1.6-1.7 in Android projects ? When i added it to our gradle build, i got this error :
Error:Execution failed for task ':sdk:transformClassesWithDexForDebugAndroidTest'.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: Unable to pre-dex '/Users/andrewzakordonets/.m2/repository/com/github/seratch/jslack/1.0.8/jslack-1.0.8.jar' to '/Users/andrewzakordonets/Work/Vimpelcom/veon-sdk/sdk/build/intermediates/transforms/dex/androidTest/debug/folders/1000/10/jslack-1.0.8_6cfaf33714fc85887f68054544efa05c861e4aee'
Hi @seratch,
Thanks for open-sourcing the great library.
What's your opinion on providing two common marker interfaces to be implemented by all request and response objects? I.E. All requests implement request
and all responses implement response
.
In my opinion it would be extremely useful for developers in a number of situations I've encountered:
Processor<Request>
would be a major plus.If you're in favour, I'd be more than happy to create a pull request. Please let me me know if you'd like me to do so.
Cheers, Joel
File upload apparently supports a thread_ts argument:
https://api.slack.com/methods/files.upload
Currently it is not part of the FilesUploadRequest
class.
It would be very useful to include this parameter. unless it is currently with jslack possible to upload a file and post it as a response to a thread in another way
Slack has some secret endpoints that are so useful, one example is the user invitation endpoint:
https://github.com/ErikKalkoken/slackApiDoc/blob/master/users.admin.invite.md
Could you add this endpoint, in order to invite people to slack via API?
I need it so I can take the response from RTMMessageHandler and turn it into the corresponding object, this seems pretty fundamental so I'm guessing I'm just missing it.
take()
is not the best solution for theBlockingQueue<Runnable>
System props
awt.toolkit=sun.lwawt.macosx.LWCToolkit
file.encoding=UTF-8
file.separator=/
gopherProxySet=false
java.awt.graphicsenv=sun.awt.CGraphicsEnvironment
java.awt.printerjob=sun.lwawt.macosx.CPrinterJob
java.class.path=target/Smoker.jar
java.class.version=55.0
java.home=/Library/Java/JavaVirtualMachines/openjdk-11.0.1.jdk/Contents/Home
java.io.tmpdir=/var/folders/2h/mjw8k1v93z9_t746q075t7j80000gp/T/
java.library.path=/Users/oshabur/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
java.rmi.server.randomIDs=true
java.runtime.name=OpenJDK Runtime Environment
java.runtime.version=11.0.1+13
java.specification.name=Java Platform API Specification
java.specification.vendor=Oracle Corporation
java.specification.version=11
java.vendor=Oracle Corporation
java.vendor.url=http://java.oracle.com/
java.vendor.url.bug=http://bugreport.java.com/bugreport/
java.vendor.version=18.9
java.version=11.0.1
java.version.date=2018-10-16
java.vm.compressedOopsMode=Zero based
java.vm.info=mixed mode
java.vm.name=OpenJDK 64-Bit Server VM
java.vm.specification.name=Java Virtual Machine Specification
java.vm.specification.vendor=Oracle Corporation
java.vm.specification.version=11
java.vm.vendor=Oracle Corporation
java.vm.version=11.0.1+13
jdk.debug=release
line.separator=\n
os.arch=x86_64
os.name=Mac OS X
os.version=10.14.1
path.separator=:
sun.arch.data.model=64
sun.boot.library.path=/Library/Java/JavaVirtualMachines/openjdk-11.0.1.jdk/Contents/Home/lib
sun.cpu.endian=little
sun.cpu.isalist=
sun.io.unicode.encoding=UnicodeBig
sun.java.command=target/Smoker.jar -Dslack.bot.access.list=oshaburov,oshaburov
sun.java.launcher=SUN_STANDARD
sun.jnu.encoding=UTF-8
sun.management.compiler=HotSpot 64-Bit Tiered Compilers
sun.os.patch.level=unknown
Full thread dump
thread_dump.txt
Code
public class Smoker {
private static boolean isRun = false;
private static final Logger LOG = LoggerFactory.getLogger(Smoker.class);
public static void main(String[] args) {
isRun = true;
String token = BaseMessageHandler.getToken();
try (RTMClient rtm = new Slack().rtm(token)) {
LOG.info("Real Time Messaging client started");
rtm.addMessageHandler(new UserMessageHandler());
rtm.addMessageHandler(new GroupMessageHandler());
rtm.addErrorHandler(new ErrorHandler());
rtm.connect();
addShutdownHook();
while (isRun) {
sleep(1000);
}
} catch (Throwable e) {
LOG.error("Unexpected exception. Service died.", e);
} finally {
Runtime.getRuntime().exit(1);
}
}
}
Long-time user, first-time reporter here. Thanks for building this library. It is great.
From time to time, my app is rendered useless with this message
2019-02-06 14:30:49.982 DEBUG [ient-SecureIO-1] c.g.s.j.a.r.RTMClient -- session closed: 0, reason: The decoded text message was too big for the output buffer and the endpoint does not support partial messages
Once that happens, the com.github.seratch.jslack.Slack
instance needs to be discarded. Since I'm creating it as a Spring Bean, and the instance is autowired, I end up restarting the application.
My current close handler only updates the health of the application and lets the unhealthy check take care of restarting the application.
rtm.addCloseHandler {
log.error("Session Closed: $it")
slackHealth.healthy = false
slackHealth.reason = it.reasonPhrase
}
Realized this when I upgraded jslack and all of a sudden my formatting stopped working unless I provided .mrkdwn(true)
. Looks like that's supposed to be the default.
Does anyone modify RTM client for proxy support. I have proxy setup between my client and slack channel. I tried to do it in RTMClient class but websocket does not have any method to handle the proxy. Please share your code..
Hey,
Could you please add author_subname in Attachment?
Would also need a new build and maven delivery :)
Thanks in advance, and again congratulations for the work done!
MethodsClientImpl
implements over 130 API methods from the MethodsClient
interface. Each of these methods in turn invokes one of three private doPost...
methods.
I would like to extend MethodsClientImpl
within my project to add some custom rate limiting, but this would require overriding each of the 130+ methods (as the private doPost...
methods cannot be overridden).
Changing the access modifiers on the three doPost
methods from private
to protected
would make it much easier for clients to write custom MethodsClient implementations.
At the first line in the .send(url, payload)
the httpclient is created again every time, even though the instance has a slackhttpclient in its member variables.
https://github.com/seratch/jslack/blob/c5c2a1ff42cad3297694055306da1255fda2411a/src/main/java/com/github/seratch/jslack/Slack.java#L50
Should this rather be this.httpClient
?
The https://api.slack.com/methods/rtm.start method has additional fields like:
self
team
ims
channels
users
groups
It would be useful if those were available in the RTMStartResponse for use when starting up an RTM connection.
Mocking Slack API requests instead of making real calls will improve the tests and enable us to test calls that cannot be tested in an automated fashion without mocks such as dialog.open
requests.
Slack's API team recently released Steno:
Slack app testing companion - Record and Replay your HTTP requests, both incoming and outgoing
I would like to integrate Steno into JSlack and replace all existing tests with Steno mock scenarios.
non documented dependencies:
If it is "simple" why do I need to keep adding libraries.
okhttp3/RequestBody
slf4j
org.slf4j.impl.StaticLoggerBinder
lombok
ConversationRepliesResponse doesn't implement SlackApiResponse, and it should.
"User.name" no longer contains "display name"
(https://api.slack.com/changelog/2017-09-the-one-about-usernames)
Hello guys! I'm really enjoying using this library, congratulations.
I did not find the implementation for the "users.setPhoto" and "users.deletePhoto" methods.
Is there any future plan to be implemented? Thank you.
I am little confused in terms of where and all security is required. I did go through manage distribution and OAuth sections in Slack doc but couldn't completely comprehend. Where to start, etc.
Appreciate, if you can answer my queries. I am simultaneously checking with Slack Team as well.
The latest version of the oss-parent POM is 9. jslack currently uses version 7.
I'll craft a PR for this, but need to reference an issue nr in it.
The new API for workspace app for posting chat messages does not allow as_user been set. It is noted in the API page: https://api.slack.com/methods/chat.postMessage
In jSlack's implementation, as_user is always set to either true or false. However, slack API requires the as_user field to be left unset. If it is set to either true or false, the endpoint returns:
{
"ok": false,
"error": "as_user_not_supported"
}
Hi this might be a bit noddy so forgive me if I'm missing something, I've worked off your docs and have produced this section of code to post a response back as a bot user to the originating channel.
Slack slack = Slack.getInstance();
ApiToken token = ApiToken.of("TOKEN");
if(message.event.text.contains("test")) {
ChatPostMessageResponse postResponse = slack.methods().chatPostMessage(
ChatPostMessageRequest.builder()
.token(token.getValue())
.channel("")
.text("Hello from bot")
.asUser(false)
.username("@abot")
.build());
assert postResponse.isOk();
}
There seems to be an issue and I'm not sure if its the code or outside of that.
The exception that I'm getting is connect timed out.
I'm using ngrok to handle the tunnelling between slack and my local machine and have worked with it well enough over the last few days to handle communication between a service and a slash command, with the system set up in the same way I'm not having any issues.
I am unable to get the connection between my local machine and slack to work correctly. Am I missing something.
__
I want access to RTMStartResponse
. Unfortunately RTMClient rtm = new Slack().rtm(token)
(as suggested in the README) doesn't facilitate that.
After looking at https://github.com/seratch/jslack/blob/master/src/main/java/com/github/seratch/jslack/Slack.java#L66 I went for something like this.
Slack slack = Slack.getInstance();
RTMStartResponse rtmStartResponse = slack.methods()
.rtmStart(RTMStartRequest.builder().token(token).build());
RTMClient rtmClient = new RTMClient(rtmStartResponse.getUrl());
System.out.println(rtmStartResponse.getTeam().getName());
System.out.println(rtmStartResponse.getUsers().size());
And I have the access that I'm after.
Although I'm only using public methods, I'm wondering if this is likely to be safe going forward. Am I using anything that not intended to be part of the public API?
Hi,
There is any way to mock Jslack or TestKit for testing?
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.