I want to publish messages submitted on a modal view to the same channel: (https://api.slack.com/surfaces/modals/using#modal_response_url).
This is how the chatPostMessage() method looks and is invoked by the /postmessage slash command:
app.command("/postmessage", (req, ctx) -> {
ChatPostMessageResponse response = ctx.client().chatPostMessage(r -> r.channel(ctx.getChannelId()).text("Example Message"));
return ctx.ack("");
});
Output (seen in the channel where /postmessage is invoked from):
Example Message
I want to call the same chatPostMessage() method to post the modal submission data to the channel where it is launched from. How can I do this?
//When user clicks "Submit" in the modal view
app.viewSubmission("case-handoff", (req, ctx) -> {
String privateMetadata = req.getPayload().getView().getPrivateMetadata();
Map<String, Map<String, ViewState.Value>> stateValues = req.getPayload().getView().getState().getValues();
String firstName = stateValues.get("firstName").get("agenda-action1").getValue();
Map<String, String> errors = new HashMap<>();
if (caseName.length() <= 10) {
errors.put("agenda-block", "Agenda needs to be longer than 10 characters.");
}
if (!errors.isEmpty()) {
return ctx.ack(r -> r.responseAction("errors").errors(errors));
} else {
return ctx.ack("");
}
});
Example Output (John Smith is typed into the modal text-field and user presses "Submit"), seen in the channel where /launchModal is invoked from:
John Smith