Search in sources :

Example 1 with CardView

use of org.dbflute.mail.CardView 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);
        }
    }));
}
Also used : FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) Logger(org.apache.logging.log4j.Logger) StreamUtil(org.codelibs.core.stream.StreamUtil) ComponentUtil(org.codelibs.fess.util.ComponentUtil) CardView(org.dbflute.mail.CardView) SMailPostingDiscloser(org.dbflute.mail.send.supplement.SMailPostingDiscloser) StringUtil(org.codelibs.core.lang.StringUtil) IOException(java.io.IOException) StringEscapeUtils(org.apache.commons.text.StringEscapeUtils) LogManager(org.apache.logging.log4j.LogManager) CurlResponse(org.codelibs.curl.CurlResponse) Curl(org.codelibs.curl.Curl) CurlResponse(org.codelibs.curl.CurlResponse) IOException(java.io.IOException) StringUtil(org.codelibs.core.lang.StringUtil) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig)

Example 2 with CardView

use of org.dbflute.mail.CardView 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);
        }
    }));
}
Also used : FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) Logger(org.apache.logging.log4j.Logger) StreamUtil(org.codelibs.core.stream.StreamUtil) ComponentUtil(org.codelibs.fess.util.ComponentUtil) CardView(org.dbflute.mail.CardView) SMailPostingDiscloser(org.dbflute.mail.send.supplement.SMailPostingDiscloser) StringUtil(org.codelibs.core.lang.StringUtil) IOException(java.io.IOException) StringEscapeUtils(org.apache.commons.text.StringEscapeUtils) LogManager(org.apache.logging.log4j.LogManager) CurlResponse(org.codelibs.curl.CurlResponse) Curl(org.codelibs.curl.Curl) CurlResponse(org.codelibs.curl.CurlResponse) IOException(java.io.IOException) StringUtil(org.codelibs.core.lang.StringUtil) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig)

Aggregations

IOException (java.io.IOException)2 StringEscapeUtils (org.apache.commons.text.StringEscapeUtils)2 LogManager (org.apache.logging.log4j.LogManager)2 Logger (org.apache.logging.log4j.Logger)2 StringUtil (org.codelibs.core.lang.StringUtil)2 StreamUtil (org.codelibs.core.stream.StreamUtil)2 Curl (org.codelibs.curl.Curl)2 CurlResponse (org.codelibs.curl.CurlResponse)2 FessConfig (org.codelibs.fess.mylasta.direction.FessConfig)2 ComponentUtil (org.codelibs.fess.util.ComponentUtil)2 CardView (org.dbflute.mail.CardView)2 SMailPostingDiscloser (org.dbflute.mail.send.supplement.SMailPostingDiscloser)2