slackapi / java-slack-sdk

Slack Developer Kit (including Bolt for Java) for any JVM language
https://slack.dev/java-slack-sdk/
MIT License
571 stars 212 forks source link

How to use with Scala + Http4s + Typelevel #1229

Closed bphenriques closed 10 months ago

bphenriques commented 10 months ago

[Question]

Hello,

Our team is investigating how to extend an existing http4s server to receive webhooks from Slack. Things are getting murkier as we need do some of the wiring ourselves and bridge with the Typelevel stack:

  1. Doing API requests using the Slack API SDK is smooth: IO.fromCompletableFuture(IO(client.viewsOpen(request)))
  2. Verifying requests is also doable as the algorithm is explained and the code is available.
  3. However, parsing response actions (view submissions, block actions, view closed) is not trivial and can be fragile as we are the ones doing the decoding and things may change without us realising.

Questions:

  1. Do you have guidelines for teams that are using Scala + http4s? It is the recommended http server stack within the typelevel ecosystem
  2. If not, perhaps it would be best delegating the decoding of the body to the SDK:
    1. What do you recommend?
    2. Will the proposed API remain public? Concerned that there might a breaking change making that API protected/private.

Thank you!

Edit: this code-example I found in another ticket might be a good starting point: https://github.com/seratch/bolt-dropwizard-app/blob/main/src/main/java/example/SlackBoltApplication.java

seratch commented 10 months ago

Hi @bphenriques, thanks for asking the questions!

Do you have guidelines for teams that are using Scala + http4s? It is the recommended http server stack within the typelevel ecosystem?

We currently do not have such guidelines. However, if you lean towards leveraging the typelevel ecosystem along with http4s for Slack app development, Bolt does not prevent you from doing so.

If not, perhaps it would be best delegating the decoding of the body to the SDK: What do you recommend?

Yes, we highly recommend allowing Bolt to parse the request body data, instead of doing it on your http4s code side. This is essential not only for saving your time but also for performing a valid request verification within the Bolt framework. In essence, the key points you should take note of are:

Keeping the above considerations in mind, the implementation of the adapter which bridges your http4s server code with Bolt's App instance should not be a time-consuming task (given your familiarity with http4s). As you may have discovered, there are numerous reliable code examples showcasing how to accomplish this. Examples like bolt-servlet, bolt-ktor, bolt-http4k, bot-aws-lambda, and many more can be found in this repository.

Will the proposed API remain public? Concerned that there might a breaking change making that API protected/private.

No, they certainly won't. Bolt is utilized by numerous enterprise customers and partners. We will definitely ensure the interface's stability.

I hope this clarifies your concern! Please note, however, that nobody in my team possesses familiarity with http4s and typelevel libraries. Therefore, we may not be of assistance for Scala-specific inquiries.

bphenriques commented 10 months ago

Thank you for the swift and complete response!

No, they certainly won't. Bolt is utilized by numerous enterprise customers and partners. We will definitely ensure the interface's stability.

Thank you!

Keeping the above considerations in mind, the implementation of the adapter which bridges your http4s server code with Bolt's App instance should not be a time-consuming task (given your familiarity with http4s

Following the conversation, I managed to re-use the abstractions you have and bridge between responses/requests between http4s and the slack library. It was smooth, so thank you for building exposing these building blocks! 👍

Overall:

  1. I managed to decode the http4's "request" using com.slack.api.bolt.util.SlackRequestParser and then handle the SlackRequest accordingly.
  2. Managed to translate the ack family Slack's HTTP responses to a http4s responses (http code, body and content-type). However, I am finding some trouble as modals only show "We had some trouble connecting. Try again?" with no more information - e.g., answering a view_submission with a ackWithUpdate with the same view with a new input-block. This is a separate question and it seems to be common theme. I will check again and if I keep having problems I will reach out in a different thread.

I hope this clarifies your concern! Please note, however, that nobody in my team possesses familiarity with http4s and typelevel libraries. Therefore, we may not be of assistance for Scala-specific inquiries.

That is alright 👍 If useful, I may share some of my findings in this thread.

seratch commented 10 months ago

Thanks again for posting this question! Let me close this issue for now, but whenever you have any comments, please feel to write in!