From 495dd453ed5ac486d0feab0b479105c64ab72691 Mon Sep 17 00:00:00 2001 From: Simon Belak Date: Mon, 28 Mar 2016 16:54:24 +0200 Subject: [PATCH] [#159] Add Slack appender (@sbelak) --- .../timbre/appenders/3rd_party/slack.clj | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/taoensso/timbre/appenders/3rd_party/slack.clj diff --git a/src/taoensso/timbre/appenders/3rd_party/slack.clj b/src/taoensso/timbre/appenders/3rd_party/slack.clj new file mode 100644 index 0000000..6518e47 --- /dev/null +++ b/src/taoensso/timbre/appenders/3rd_party/slack.clj @@ -0,0 +1,28 @@ +(ns taoensso.timbre.appenders.3rd-party.slack + {:author "Simon Belak (@sbelak)"} + (:require (taoensso [timbre :as timbre] + [encore :as encore]) + (clj-slack [chat :as slack.chat] + [core :as slack]))) + +(defn slack-appender + "Return Slack appender. + Required params: + `token` - Slack API token. See: Browse apps > Custom Integrations > Bots + `channel` - Channel ID. + + Optional params: same as clj-slack.chat/post-message `optionals`. See: http://julienblanchard.com/clj-slack/clj-slack.chat.html" + [& [opts]] + (let [{:keys [token channel]} opts + conn {:api-url "https://slack.com/api" + :token token}] + {:enabled? true + :async? true + :min-level nil + :rate-limit [[1 (encore/ms :secs 1)]] + :output-fn :inherit + :fn + (fn [data] + (let [{:keys [output-fn]} data] + (slack.chat/post-message conn channel (output-fn data) + (dissoc opts :token :channel))))}))