main
1#!/usr/bin/env bash
2# Acknowledge (delete) the last ntfy notification
3# This script is called when right-clicking a notification in mako
4
5set -euo pipefail
6
7STATEFILE="/tmp/ntfy-last-message"
8LOGFILE="/tmp/ntfy-actions.log"
9
10# Log the action
11echo "[$(date '+%Y-%m-%d %H:%M:%S')] Acknowledge action triggered" >> "$LOGFILE"
12
13# Check if we have a message to acknowledge
14if [[ ! -f "$STATEFILE" ]]; then
15 echo "[$(date '+%Y-%m-%d %H:%M:%S')] ERROR: No message to acknowledge" >> "$LOGFILE"
16 notify-send -a ntfy "Error" "No message to acknowledge"
17 exit 1
18fi
19
20# Read message details
21# shellcheck source=/dev/null
22source "$STATEFILE"
23
24echo "[$(date '+%Y-%m-%d %H:%M:%S')] Acknowledging message: $TOPIC/$ID" >> "$LOGFILE"
25
26# Delete the message from ntfy server
27if curl -s -X DELETE "https://ntfy.sbr.pm/$TOPIC/$ID" \
28 -H "Authorization: Bearer $(passage show home/ntfy/token)" \
29 >> "$LOGFILE" 2>&1; then
30 echo "[$(date '+%Y-%m-%d %H:%M:%S')] Successfully deleted message" >> "$LOGFILE"
31 rm -f "$STATEFILE"
32else
33 echo "[$(date '+%Y-%m-%d %H:%M:%S')] Failed to delete message" >> "$LOGFILE"
34fi