52 lines
1.3 KiB
Bash
52 lines
1.3 KiB
Bash
handle_ntfy_events() {
|
|
while read -r data; do
|
|
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"
|
|
|
|
if [ "$type" = "NotifyTextMessage" ] && [ "$mode" != "1" ]; then
|
|
continue # Skip all messages that are not direct messages
|
|
fi
|
|
|
|
title="TS3 Event"
|
|
case $type in
|
|
"NotifyClientPoke")
|
|
title="TS3 Poke"
|
|
;;
|
|
"NotifyTextMessage")
|
|
title="TS3 Message"
|
|
;;
|
|
esac
|
|
|
|
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 "$payload" \
|
|
"$TS3_NTFY_HOST"
|
|
done
|
|
}
|
|
|
|
teamspeak-query-lib events --filter=others NotifyClientPoke NotifyTextMessage \
|
|
| handle_ntfy_events
|