-
-
Notifications
You must be signed in to change notification settings - Fork 171
/
slack.clj
29 lines (27 loc) · 986 Bytes
/
slack.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
(ns taoensso.timbre.appenders.community.slack
"Slack appender.
Requires <https://github.com/julienXX/clj-slack>."
{:author "Simon Belak (@sbelak)"}
(:require
[taoensso.timbre :as timbre]
[taoensso.encore :as enc]
[clj-slack.chat :as slack.chat]
[clj-slack.core :as slack]))
(defn slack-appender
"Returns 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`,
Ref. 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
:rate-limit [[1 (enc/ms :secs 1)]]
:fn
(fn [data]
(let [{:keys [output_]} data]
(slack.chat/post-message conn channel (force output_)
(dissoc opts :token :channel))))}))