In order to use the library add the dependency to your project.clj
;; Leiningen project
[com.brunobonacci/mulog-slack "x.x.x"]
;; deps.edn format
{:deps { com.brunobonacci/mulog-slack {:mvn/version "x.x.x"}}}
The events must be serializeable in JSON format (see How to JSON encode custom Java classes for more info.)
First get an Incoming Webhook in Slack following these steps:
App Name
put something like mulog
, then select the workspace, and click in Create App
https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX
note the URL you will need it later.The available configuration options:
{:type :slack
;; Slack webhook url (REQUIRED)
:webhook-url "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"
;; a function to select and/or transform the events to send (REQUIRED)
;; Select only the events you wish to see in your Slack channel
;; A simpler way to express filter is by using [where](https://github.com/BrunoBonacci/where)
;; With where the following filter would look like:
;; :transform (partial filter (where :mulog/event-name :in? [:my-event1 :my-event2]))
:transform (partial filter #(#{:my-event1 :my-event2} (:mulog/event-name %)))
;; the maximum number of events which can be sent in a single
;; batch request Slack
;; :max-items 20
;; Interval in milliseconds between publish requests.
;; μ/log will try to send the records to Slack
;; with the interval specified.
;; :publish-delay 3000
;; You can customize the appearance of the messages by providing
;; a function which takes an event and returns one or more blocks
;; ad described here: https://api.slack.com/reference/block-kit/blocks
;; :render-message (fn [event] )
}
How to use it:
(μ/start-publisher!
{:type :slack
:webhook-url "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"
:transform (partial filter #(= :my-event1 (:mulog/event-name %)))})
Once you send a message you should get a Slack notification which looks as follow:
You can customize the look by providing a :render-message
function
which returns one or more Slack Blocks.
Can you improve this documentation? These fine people already did:
Bruno Bonacci & John PracticalliEdit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close