Skip to content

Commit

Permalink
[#159] Add Slack appender (@sbelak)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbelak authored and ptaoussanis committed Mar 28, 2016
1 parent 5563bc8 commit 495dd45
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/taoensso/timbre/appenders/3rd_party/slack.clj
Original file line number Diff line number Diff line change
@@ -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))))}))

0 comments on commit 495dd45

Please sign in to comment.