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

Close Slack Modal when click on Submit Button #1218

Closed RedHoes closed 11 months ago

RedHoes commented 11 months ago

(Describe your issue and goal here)

Reproducible in:

openjdk version "11.0.20.1" 2023-08-24
OpenJDK Runtime Environment (build 11.0.20.1+1-post-Ubuntu-0ubuntu122.04)
OpenJDK 64-Bit Server VM (build 11.0.20.1+1-post-Ubuntu-0ubuntu122.04, mixed mode, sharing)

The Slack SDK version

Module Version: slack.api.model: 1.29.2

Java Runtime version

openjdk version "11.0.20.1" 2023-08-24 OpenJDK Runtime Environment (build 11.0.20.1+1-post-Ubuntu-0ubuntu122.04) OpenJDK 64-Bit Server VM (build 11.0.20.1+1-post-Ubuntu-0ubuntu122.04, mixed mode, sharing)

OS info

34~22.04.1-Ubuntu

Steps to reproduce:

(Share the commands to run, source code, and project settings (e.g., pom.xml/build.gradle))

  1. I call view.update to show a pop-up modal in slack
  2. When I click on Submit button, I want to return a slash message to channel and close the modal automatically
  3. Btw, I just can handle the first clause, I can't find out the way to close the modal without clicking on Cancel Button
  4. Here is my code:
 private fun main(payload: InteractionPayloads?, userId: String, channelName: String?) {
    if (payload is InteractionPayloads.IViewSubmissionPayload) {
      val SubmissionPayload = payload.payload
       if (blockActionPayload.view.callbackId == SlackButtonConstants.cutoffButton) {
          // return slash message -> this is not related to my question
        }
    } else {
      warn {
        "Error handling submission action due to=$payload"
      }
    }
  }
  1. Actually, I don't handle any ViewSubmission in my code, how could I do now.

  2. FYI, this is my code to handle ViewUpdateRequest:

    fun viewUpdate(id: String): ViewsUpdateRequest {
    val modalView = View.builder()
      .callbackId(myButton)
      .type("modal")
      .clearOnClose(true)
      .title(
        ViewTitle.builder()
          .type("plain_text")
          .text("Modal")
          .emoji(false)
          .build()
      )
      .submit(
        ViewSubmit.builder()
          .type("plain_text")
          .text("Submit")
          .emoji(false)
          .build()
      )
      .blocks(SlackCommonResponses("Please select an option")
      .build()
    
    return ViewsUpdateRequest.builder()
      .view(modalView)
      .viewId(id)
      .build()
    }

Expected result:

I want to close the modal before send slash message to slack

Actual result:

(Tell what actually happened with logs, screenshots)

Requirements

Please make sure if this topic is specific to this SDK. For general questions/issues about Slack API platform or its server-side, could you submit questions at https://my.slack.com/help/requests/new instead. :bow:

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you agree to those rules.

RedHoes commented 11 months ago

I hope the information I provided is enough for you to give me suggestion. Thanks so much !

seratch commented 11 months ago

Hi @RedHoes, thanks for asking the question.

Btw, I just can handle the first clause, I can't find out the way to close the modal without clicking on Cancel Button

Unfortunately, there is no way to do this. Only your end-users can close the modal by clicking either x on the top or Cancel button.

I want to close the modal before send slash message to slack

To send your message asynchronously, you can use app.executorService().submit() to run the logic. To ensure the message is sent out a while after closing the modal dialog, you may want to have Thread.sleep(ms) in the code executed by the ExecutorService. Refer to https://slack.dev/java-slack-sdk/guides/bolt-basics for the code snippets.

I hope this helps.

RedHoes commented 11 months ago

Thanks for your answer, but anytime I click on the Submit button, this message appears, how to avoid it: We had some trouble connecting. Try again?

seratch commented 11 months ago

Could you double-check if your app code has an app.viewSubmission listener for the callback_id plus you’ve set a valid Request URL in the Interactivity & Shortcuts section on your api.slack.com/apps site?

RedHoes commented 11 months ago

I haven't set up the app.viewSubmission listener yet, but I wonder if I can setup the listener through my slack bot, because all the actions I manage in Slack is from this slackbot. Below is how I setup the slack bot private val botClient: MethodsClient = Slack.getInstance().methods(config.slack.botToken)

seratch commented 11 months ago

The Slack instance provides only we api wrapper methods (e.g., chat.postMessage, views.open), so it does not support handlers for incoming requests from Slack. To handle those, you need to use App instance with valid configuration on api.slack.com site instead.

RedHoes commented 11 months ago

Thanks so much, I could resolve the issues