use of org.dbflute.mail.send.supplement.SMailPostingDiscloser in project fess by codelibs.
the class NotificationHelper method sendToGoogleChat.
protected void sendToGoogleChat(final CardView cardView, final SMailPostingDiscloser discloser) {
// https://developers.google.com/hangouts/chat/how-tos/webhooks
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final String googleChatWebhookUrls = fessConfig.getGoogleChatWebhookUrls();
if (StringUtil.isBlank(googleChatWebhookUrls)) {
return;
}
final String body = toGoogleChatMessage(discloser);
StreamUtil.split(googleChatWebhookUrls, "[,\\s]").of(stream -> stream.filter(StringUtil::isNotBlank).forEach(url -> {
try (CurlResponse response = Curl.post(url).header("Content-Type", "application/json").body(body).execute()) {
if (response.getHttpStatusCode() == 200) {
if (logger.isDebugEnabled()) {
logger.debug("Sent {} to {}.", body, url);
}
} else {
logger.warn("Failed to send {} to {}. HTTP Status is {}. {}", body, url, response.getHttpStatusCode(), response.getContentAsString());
}
} catch (final IOException e) {
logger.warn("Failed to send {} to {}.", body, url, e);
}
}));
}
use of org.dbflute.mail.send.supplement.SMailPostingDiscloser in project fess by codelibs.
the class NotificationHelper method sendToSlack.
protected void sendToSlack(final CardView cardView, final SMailPostingDiscloser discloser) {
// https://api.slack.com/messaging/webhooks#posting_with_webhooks
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final String slackWebhookUrls = fessConfig.getSlackWebhookUrls();
if (StringUtil.isBlank(slackWebhookUrls)) {
return;
}
final String body = toSlackMessage(discloser);
StreamUtil.split(slackWebhookUrls, "[,\\s]").of(stream -> stream.filter(StringUtil::isNotBlank).forEach(url -> {
try (CurlResponse response = Curl.post(url).header("Content-Type", "application/json").body(body).execute()) {
if (response.getHttpStatusCode() == 200) {
if (logger.isDebugEnabled()) {
logger.debug("Sent {} to {}.", body, url);
}
} else {
logger.warn("Failed to send {} to {}. HTTP Status is {}. {}", body, url, response.getHttpStatusCode(), response.getContentAsString());
}
} catch (final IOException e) {
logger.warn("Failed to send {} to {}.", body, url, e);
}
}));
}
Aggregations