Use java api to send messages to slack

  slack

maven

        <dependency>
            <groupId>net.gpedro.integrations.slack</groupId>
            <artifactId>slack-webhook</artifactId>
            <version>1.2.1</version>
        </dependency>

Construct field and attachment

public static SlackAttachment newAttachment(String title, String titleLink, String text, List<SlackField> fields){
        SlackAttachment slackAttachment = new SlackAttachment();
        slackAttachment.setFallback(text);
        slackAttachment.setColor("danger");
        slackAttachment.setFields(fields);
        slackAttachment.setTitle(title);
        slackAttachment.setTitleLink(titleLink);
        slackAttachment.setText(text);
        return slackAttachment;
    }

    public static SlackField newField(String name,Object value){
        SlackField field = new SlackField();
        field.setTitle(name);
        field.setValue(Objects.toString(value));
        field.setShorten(false);
        return field;
    }

Send

public void sendWithAttachment(String title,String link,String text,SlackAttachment attachment){
        try{
            SlackMessage slackMessage = new SlackMessage("");
            slackMessage.setChannel("#" + channel);
            slackMessage.setUsername(String.format("[%s] - Bot",appId));
            slackMessage.setIcon(":exclamation:");
            slackMessage.setAttachments(Collections.singletonList(attachment));
            slackApi.call(slackMessage);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

docs