@ PostConstruct public void invokeSlackWebhook ( ) { RestTemplate restTemplate = new RestTemplate ( ) ; RichMessage richMessage = new RichMessage ( "Just to test Slack's incoming webhooks." ) ; // set attachments Attachment [ ] attachments = new Attachment [ 1 ] ; attachments [ 0 ] = new Attachment ( ) ; attachments [ 0 ] . setText ( "Some data relevant to your users." ) ; richMessage . setAttachments ( attachments ) ; // For debugging purpose only try { logger . debug ( "Reply (RichMessage): {}" , new ObjectMapper ( ) . writeValueAsString ( richMessage ) ) ; } catch ( JsonProcessingException e ) { logger . debug ( "Error parsing RichMessage: " , e ) ; } // Always remember to send the encoded message to Slack try { restTemplate . postForEntity ( slackIncomingWebhookUrl , richMessage . encodedMessage ( ) , String . class ) ; } catch ( RestClientException e ) { logger . error ( "Error posting to Slack Incoming Webhook: " , e ) ; } }
Make a POST call to the incoming webhook url .