Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to URL instead of CURL #3

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions ntfy.el
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@

;; Author: Shom Bandopadhaya <[email protected]>
;; Created: 2022-04-30
;; Modified: 2022-05-04
;; Version: 0.1.2
;; Modified: 2025-01-05
;; Version: 0.2.0
;; Keywords: ntfy notification push-notification pub-sub
;; Package-Requires: ((emacs "27.2") (curl))
;; Package-Requires: ((emacs "27.2") (url "22.1"))
;; SPDX-License-Identifier: MIT

;; This file is not part of GNU Emacs.

;;; Commentary:
;; Interface to use the https://ntfy.sh service (or self-hosted version) to send notification from Emacs.
;;
;;
;;; Code:
(require 'url)

(defcustom ntfy-server nil
"Set server for ntfy service."
:group 'ntfy
:type 'string)

(defcustom ntfy-topic nil
"Set ntfy topic/channel."
:group 'ntfy
Expand Down Expand Up @@ -56,27 +57,27 @@ Custom HEADER and TAGS are set for the notification."
(ntfy--publish-message message header tags))

(defun ntfy--publish-message (message &optional header tags)
"Publish message to server with curl with MESSAGE.
"Publish message to server with Emacs Lib URL with MESSAGE.
Configured HEADER and TAGS are used unless specified."
(start-process "nfty.el" nil "curl"
"-H" (format "Title: %s" (or header ntfy-header))
"-H" (format "Tags: %s" (or tags ntfy-tags))
"-d" (format "%s" message)
(format "%s/%s" ntfy-server ntfy-topic)))
(let ((url-request-method "POST")
(url-request-data message)
(url-request-extra-headers `(("Title" . ,(or header ntfy-header))
("Tags" . ,(or tags ntfy-tags)))))
(url-retrieve-synchronously (format "%s/%s" ntfy-server ntfy-topic))))

(defun ntfy-send-url (url)
"Send URL from mini-buffer."
(interactive "sEnter URL: \n")
(ntfy--publish-url url))

(defun ntfy--publish-url (url)
"Publish URL to server with curl."
(start-process "nfty.el" nil "curl"
"-H" (format "Title: %s" "Emacs shared a URL")
"-H" (format "Tags: %s" "link")
"-H" (format "Actions: view, %s, %s" url url)
"-d" (format "%s" url)
(format "%s/%s" ntfy-server ntfy-topic)))
"Publish URL to server with Emacs Lib URL."
(let ((url-request-method "POST")
(url-request-data (concat "Click to follow the shared URL;\n" url))
(url-request-extra-headers `(("Title" . "Emacs shared a URL")
("Tags" . "link")
("Actions" . ,(format "view, View Link, %s" url url)))))
(url-retrieve-synchronously (format "%s/%s" ntfy-server ntfy-topic))))

(provide 'ntfy)
;;; ntfy.el ends here