use of com.synopsys.integration.alert.api.channel.rest.RestChannelUtility in project hub-alert by blackducksoftware.
the class MSTeamsChannelMessageSender method sendMessages.
@Override
public MessageResult sendMessages(MSTeamsJobDetailsModel msTeamsJobDetailsModel, List<MSTeamsChannelMessageModel> channelMessages) throws AlertException {
String webhook = msTeamsJobDetailsModel.getWebhook();
Map<String, String> requestHeaders = new HashMap<>();
requestHeaders.put("Content-Type", "application/json");
IntHttpClient intHttpClient = connectionFactory.createIntHttpClient(webhook);
RestChannelUtility restChannelUtility = new RestChannelUtility(intHttpClient);
List<Request> messageRequests = channelMessages.stream().map(this::createJsonString).map(jsonString -> restChannelUtility.createPostMessageRequest(webhook, requestHeaders, jsonString)).collect(Collectors.toList());
restChannelUtility.sendMessage(messageRequests, msTeamsKey.getUniversalKey());
return new MessageResult(String.format("Successfully sent %d MSTeams message(s)", channelMessages.size()));
}
use of com.synopsys.integration.alert.api.channel.rest.RestChannelUtility in project hub-alert by blackducksoftware.
the class SlackChannelMessageSender method sendMessages.
@Override
public MessageResult sendMessages(SlackJobDetailsModel slackJobDetails, List<SlackChannelMessageModel> channelMessages) throws AlertException {
String webhook = slackJobDetails.getWebhook();
String channelName = slackJobDetails.getChannelName();
String channelUsername = Optional.ofNullable(slackJobDetails.getChannelUsername()).orElse(SLACK_DEFAULT_USERNAME);
Map<String, String> requestHeaders = new HashMap<>();
requestHeaders.put("Content-Type", "application/json");
IntHttpClient intHttpClient = connectionFactory.createIntHttpClient(webhook);
RestChannelUtility restChannelUtility = new RestChannelUtility(intHttpClient);
List<Request> requests = channelMessages.stream().map(channelMessage -> createJsonString(channelMessage.getMarkdownContent(), channelName, channelUsername)).map(jsonString -> restChannelUtility.createPostMessageRequest(webhook, requestHeaders, jsonString)).collect(Collectors.toList());
restChannelUtility.sendMessage(requests, slackChannelKey.getUniversalKey());
return new MessageResult(String.format("Successfully sent %d Slack message(s)", requests.size()));
}
Aggregations