slack
slack copied to clipboard
PushView opens a new modal and quickly closes it
Hey guys, I have a small app that OpenView ("input") to a user on Slash command, user is supposed to fill in some data and Submit which in turn should PushView another modal (a "success" message).
Thing is that everything looks to be working, I even see the "Success" modal pops up for a brief moment but then it closes immediately and I see a previous modal ("input"). 😕
I am using a mux package with /actions
route:
router.HandleFunc("/actions", ActionsHandler).Methods("POST")
which process all actions and finally comes to this part:
api := slack.New(token)
req := message.Success()
_, err = api.PushView(triggerID, req)
if err != nil {
fmt.Printf("error pushing modal: %v", err)
return
}
Adding delay up to 3 seconds freezes "success" modal for while before going back to an "input" modal again (longer than 3 seconds will result in an error).
Moreover, replying with anything except 200/OK will keep the "success" modal from closing but display an error. For example: w.WriteHeader(http.StatusFound)
I am facing this issue as well when using this library on AWS Lambda.
When the user submits one view, I want to push another view on top, but it always closes immediately. The only way I can get around this is to stop the Lambda function from sending a http.StatusOK response, but this results in a very ugly "Something went wrong" message on the view!
if err != nil {
_, _ = SlackBot.PushView(triggerid, modalViewRequest)
}
return response
I believe this might be caused by the Slack servers receiving the HTTP OK response after the pushed view has been sent, making it think that we want to close most recently pushed view rather than the original submitted view.
I have found a solution to this issue, which is to not use this package to send the pushed view at all!
if err != nil {
responseBody, _ := json.Marshal(ModalResponse{
ResponseAction: "push",
View: modalViewRequest,
})
response.StatusCode = http.StatusAccepted
response.Body = string(responseBody)
}
return response
Relevant part of the documentation is here.
As per my original comment, the problem was indeed that Slack was taking the response as a submission request from the most recently pushed view, hence it would close the pushed view rather than the original view.