From 3463907670d4bac7bab76b79e8399edef27cc0d8 Mon Sep 17 00:00:00 2001 From: Tobias Reisinger Date: Sun, 27 Oct 2024 18:55:08 +0100 Subject: [PATCH] Add response option to ntfy --- ts-control | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/ts-control b/ts-control index 4c89323..d872875 100755 --- a/ts-control +++ b/ts-control @@ -64,6 +64,7 @@ handle_ntfy_events() { msg=$(echo "$data" | jq -r --unbuffered '.message') type=$(echo "$data" | jq -r --unbuffered '.type') mode=$(echo "$data" | jq -r --unbuffered '.params.targetmode') + client_nickname=$(echo "$data" | jq -r --unbuffered '.client.client_nickname') echo "$data" @@ -71,25 +72,39 @@ handle_ntfy_events() { continue # Skip all messages that are not direct messages fi - friendly_type="Event" + title="TS3 Event" case $type in "NotifyClientPoke") - friendly_type="Poke" + title="TS3 Poke" ;; "NotifyTextMessage") - friendly_type="Message" + title="TS3 Message" ;; esac - echo "($friendly_type) $target: $msg" + echo "($title) $target: $msg" + + payload=$(jq -n \ + --arg topic "$TS3_NTFY_TOPIC" \ + --arg webhook "$TS3_NTFY_WEBHOOK&client=$client_nickname" \ + --arg msg "$msg" \ + --arg type "$title" \ + '{ + topic: $topic, + message: $msg, + title: $type, + actions: [{ + action: "http", + label: "TS response", + method: "POST", + url: $webhook, + clear: true + }] + }') curl -sSL \ -H "Authorization: Bearer $TS3_NTFY_TOKEN" \ - -d "{ - \"topic\": \"$TS3_NTFY_TOPIC\", - \"message\": \"$msg\", - \"title\": \"TS3 $friendly_type\" - }" \ + -d "$payload" \ "$TS3_NTFY_HOST" done }