Giter Site home page Giter Site logo

slackapi / java-slack-sdk Goto Github PK

View Code? Open in Web Editor NEW
569.0 33.0 210.0 12.16 MB

Slack Developer Kit (including Bolt for Java) for any JVM language

Home Page: https://slack.dev/java-slack-sdk/

License: MIT License

Java 94.53% Batchfile 0.05% Shell 0.11% Kotlin 5.30% Dockerfile 0.01%
java slack slack-api slack-bot slack-app jvm-languages kotlin bolt chatbot websocket

java-slack-sdk's People

Contributors

ajurasz avatar d-subrahmanyam avatar dashorst avatar dependabot[bot] avatar domdomegg avatar eamelink avatar emanguy avatar filmaj avatar frankspitulski avatar gavinbunney avatar howyi avatar hrothwell avatar ikolomiets avatar jasonmullins avatar joeltoby avatar jongilmore avatar kingbuzzer avatar lfbrandao avatar marcwrobel avatar musketyr avatar newcron avatar ramzimaalej avatar rocketraman avatar seratch avatar slushpupie avatar stevengill avatar svc-ghe-snow avatar sylvainjuge avatar williambergamin avatar zimeg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

java-slack-sdk's Issues

Jboss Wildfly 10.0.1 NoSuchMethodException com.github.seratch.jslack.api.rtm.RTMClient.<init>()

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

No class def found during runtime.

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.

How do I mention a slack user?

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.

Allow configuring URL prefixes

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.

payload.channel() doesn't work for me

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

Bubbling up HTTP 429s (too many requests)

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?

Action button confirmation should have property name "confirm" instead of "confirmation"

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

ConfirmationMessage don't appear to work.

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

Implement `conversations` API

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?

Request to add to Message object

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

Can't post as a user

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);
    }

Library doesn't want to be compiled with 1.7 target

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'

Common interfaces for Request and Response

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:

  1. It would enable clients to decorate requests / response to add additional client data.
  2. Type erasure (and the like). The ability to do 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

RMI thread Deadlock

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

Parking threads
image

CPU Time
image

CPU samples
image

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);
        }
    }
}

Log example
image

image

session closed: 0, reason: The decoded text message was too big for the output buffer and the endpoint does not support partial messages

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
            }
  1. Is there a strategy to recover from this?
  2. Can this problem be avoided?

Proxy support for RTM Client

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..

Attachment misses author_subname field

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 is difficult to subclass

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.

Refactor all tests with Mock API calls

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.

remove extra dependencies....

non documented dependencies:
If it is "simple" why do I need to keep adding libraries.

okhttp3/RequestBody
slf4j
org.slf4j.impl.StaticLoggerBinder
lombok

Methods users.setPhoto and users.deletePhoto

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.

Few Questions on Slack

  1. How can I send a scrollable data grid to slack as an incoming webhook response? Given it supports the only image format.
  2. Can I send an image object as streaming content to incoming webhook response? or I need to publish this image object as an image in some folder and provide that URL as an attachment.
  3. Now I have an app on my slack account. How do I make it available for my client's account and their workspace?
  4. How about security. Can I put security on this slack app(which I created) so that only legitimate user, workspaces and accounts can only access this App?
    • My workflow - Every time a question is asked on Slack app, it hits my rest endpoint and once the question is processed I post the answer on incoming webhook.
      How do I put security on each such transactions? so that it is secured.

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.

Upgrade oss-parent to 9

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.

Unable to post response message back to slack channel

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.
__

Access to RTMStartResponse

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.