HubSpot / slack-client

An asynchronous HTTP client for Slack's web API
Apache License 2.0
114 stars 53 forks source link

postMessage not working as Slack requires "token" be sent in body instead of the Auth header #153

Closed missingdays closed 4 years ago

missingdays commented 4 years ago

Slack Api chat.postMessage endpoint requires token parameter to be sent in body instead of Auth header. This leads to incorrect_arguments error.

To Reproduce Steps to reproduce the behavior:

  1. Send new message using standard way (see my example below)

    val client = SlackClientFactory.defaultFactory().build(
        SlackClientRuntimeConfig.builder()
            .setTokenSupplier {
                "nomnom"
            }.build()
    )
    
    val message = ChatPostMessageParams.builder()
        .setChannelId(some channel id")
        .setText("Test")
        .build()
    
    val future = client.postMessage(
        message
    )
    
    val result = future.get()
  2. See the result

Expected behavior Message is sent, ok result is returned

Actual result No messages are sent, error invalid_arguments is returned

bdros commented 4 years ago

According to Slack API:

https://api.slack.com/methods/chat.postMessage

this endpoint requires token sent in body, not in Authorization Header.

The ChannelId is properly serialized as channel field in request.

missingdays commented 4 years ago

this endpoint requires token sent in body, not in Authorization Header.

Ok, how do I provide it in body then? There is no setToken method in ChatPostMessageParams.builder()

The ChannelId is properly serialized as channel field in request.

If you debug my code and stop at SlackWebClient#executeLogged, you can inspect request and see that the parameter is called channelId

bdros commented 4 years ago

Ok, how do I provide it in body then? There is no setToken method in ChatPostMessageParams.builder()

This is an actual bug that needs to be fixed.

If you debug my code and stop at SlackWebClient#executeLogged, you can inspect request and see that the parameter is called channelId

Yes, but if you stop a debugger at NingAsyncHttpClient and look at the actual request you will see, that it has channel not channelId in a request body - because during conversion there is @JsonProperty used.

I just wrote my first response because I felt in the same error and try to figure it out by myself.

missingdays commented 4 years ago

This is an actual bug that needs to be fixed.

I see, thanks. I've updated issue description

kohsuke commented 4 years ago

I just hit the same problem that @missingdays reported in the beginning of this post -- a very simple postMessage call resulting in the invalid_arguments error.

But I don't think it's because the token has to be supplied in the body. I tracked this down and in my case it was the problem already fixed by https://github.com/HubSpot/slack-client/commit/6498a9ec56b52b7a8b8848f16b28c44887013237

Presumably that behavior changed in Slack since t he last release. I think this library just needs a new release.

szabowexler commented 4 years ago

It sounds like the underlying issue has since been fixed -- we'll keep an eye out for ways we can improve the debugging here. Going to close this, feel free to reopen if it presents again.

missingdays commented 4 years ago

It sounds like the underlying issue has since been fixed -- we'll keep an eye out for ways we can improve the debugging here. Going to close this, feel free to reopen if it presents again.

Sorry, I don't see how the underlying issue has been fixed. Could you please provide a commit that fixed this issue?