summaryrefslogtreecommitdiff
path: root/jakob/dynamic/notify.scm
blob: cdd220920cd7a3e40491edfa4ef34e6697d4bc99 (plain)
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
30
31
32
33
;;; Copyright © 2019 - 2024 Jakob L. Kreuze <zerodaysfordays@sdf.org>
;;;
;;; This program is free software; you can redistribute it and/or
;;; modify it under the terms of the GNU General Public License as
;;; published by the Free Software Foundation; either version 3 of the
;;; License, or (at your option) any later version.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;;; General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with this program. If not, see
;;; <http://www.gnu.org/licenses/>.

(define-module (jakob dynamic notify)
  #:use-module (jakob dynamic config)
  #:use-module (json)
  #:use-module (web client)
  #:export (notify))

(define gotify-base-url (getenv "GOTIFY_URL"))
(define gotify-token (getenv "GOTIFY_TOKEN"))

(define (notify priority title message)
  "Push a notification with PRIORITY, TITLE, and MESSAGE to Gotify"
  (define url
    (format #f "https://~a/message?token=~a" gotify-base-url gotify-token))
  (define body
    (scm->json-string `((priority . ,priority) (title . ,title) (message . ,message))))
  (unless (%debug-enabled)
    (http-post url #:headers '((content-type . (application/json))) #:body body)))