Files
webgui/emhttp/plugins/dynamix/include/NotificationAgents.xml
2023-10-17 11:23:28 +02:00

628 lines
26 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<Agents>
<Agent>
<Name>Boxcar</Name>
<Variables>
<Variable Help="Get your access token as explained [a href='http://help.boxcar.io/knowledgebase/articles/314474-how-to-get-my-boxcar-access-token' target='_blank'][u]here[/u].[/a]" Desc="Access Token" Default="">ACCESS_TOKEN</Variable>
<Variable Help="Specify the fields which are included in the title of the notification." Desc="Notification Title" Default="$SUBJECT">TITLE</Variable>
<Variable Help="Specify the fields which are included in the message body of the notification." Desc="Notification Message" Default="$DESCRIPTION">MESSAGE</Variable>
</Variables>
<Script>
<![CDATA[
#!/bin/bash
############
{0}
############
MESSAGE=$(echo -e "$MESSAGE")
curl -s -k \
-d "user_credentials=$ACCESS_TOKEN" \
-d "notification[title]=$TITLE" \
-d "notification[long_message]=$MESSAGE" \
-d "notification[source_name]=Unraid" \
-d "notification[sound]=bird-1" \
-d "notification[icon_url]=http://i.imgur.com/u63iSL1.png" \
https://new.boxcar.io/api/notifications 2>&1
]]>
</Script>
</Agent>
<Agent>
<Name>Discord</Name>
<Variables>
<Variable Help="Add an '#unraid-notifications' channel to your personal Discord server, then get a WebHook URL as explained [a href='https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks' target='_blank'][u]here[/u].[/a] Note that multiple Unraid servers can use the same Webhook." Desc="WebHook URL" Default="USE YOUR OWN WEBHOOK VALUE HERE">WEBH_URL</Variable>
<Variable Help="Provide the https URL to an icon representing this Unraid server (using different icons for each server can help distinguish between them in the list of notifications.) To disable this feature, specify 'none'." Desc="Server Icon" Default="https://craftassets.unraid.net/uploads/logos/un-mark-gradient@2x.png">SERVER_ICON</Variable>
<Variable Help="In Discord, right-click the '#unraid-notifications' channel and choose Notification Settings -> Only @mentions. Then to receive an @mention on 'alert' priority notifications only, provide your personal Discord ID (it is a series of numbers, not letters). To find your ID, in Discord type \@yourusername. To disable this feature, specify 'none'." Desc="Discord Tag ID" Default="none">DISCORD_TAG_ID</Variable>
</Variables>
<Script>
<![CDATA[
#!/bin/bash
############
{0}
############
############
# Quick test with default values:
# bash /boot/config/plugins/dynamix/notifications/agents/Discord.sh
# Quick test with values set through environment (all vars are optional)
# EVENT="My Event" SUBJECT="My Subject" DESCRIPTION="My Description" CONTENT="My Message" IMPORTANCE="alert" LINK="/Dashboard" bash /boot/config/plugins/dynamix/notifications/agents/Discord.sh
# Full test of notification system (at least one param is required)
# /usr/local/emhttp/webGui/scripts/notify -e "My Event" -s "My Subject" -d "My Description" -m "My Message" -i "alert" -l "/Dashboard"
#
# If a notification does not go through, check the /var/log/notify_Discord file for hints
############
############
# Discord webhooks docs: https://birdie0.github.io/discord-webhooks-guide/
#
# Available fields from notification system
# HOSTNAME
# EVENT (notify -e)
# IMPORTANCE (notify -i)
# SUBJECT (notify -s)
# DESCRIPTION (notify -d)
# CONTENT (notify -m)
# LINK (notify -l)
# TIMESTAMP (seconds from epoch)
SCRIPTNAME=$(basename "$0")
LOG="/var/log/notify_${SCRIPTNAME%.*}"
# for quick test, setup environment to mimic notify script
[[ -z "${EVENT}" ]] && EVENT='Unraid Status'
[[ -z "${SUBJECT}" ]] && SUBJECT='Notification'
[[ -z "${DESCRIPTION}" ]] && DESCRIPTION='No description'
[[ -z "${IMPORTANCE}" ]] && IMPORTANCE='normal'
[[ -z "${TIMESTAMP}" ]] && TIMESTAMP=$(date +%s)
# ensure link has a host
if [[ -n "${LINK}" ]] && [[ ${LINK} != http* ]]; then
source <(grep "NGINX_DEFAULTURL" /usr/local/emhttp/state/nginx.ini 2>/dev/null)
LINK=${NGINX_DEFAULTURL}${LINK}
fi
# Discord will not allow links with bare hostname, links must have both hostname and tld or no link at all
if [[ -n "${LINK}" ]]; then
HOST=$(echo "${LINK}" | cut -d'/' -f3)
[[ ${HOST} != *.* ]] && LINK=
fi
# note: there is no default for CONTENT
# send DESCRIPTION and/or CONTENT. Ignore the default DESCRIPTION.
[[ "${DESCRIPTION}" == 'No description' ]] && DESCRIPTION=""
if [[ -n "${DESCRIPTION}" ]] && [[ -n "${CONTENT}" ]]; then
FULL_DETAILS="${DESCRIPTION}\n\n${CONTENT}"
elif [[ -n "${DESCRIPTION}" ]]; then
FULL_DETAILS="${DESCRIPTION}"
elif [[ -n "${CONTENT}" ]]; then
FULL_DETAILS="${CONTENT}"
fi
# split into 1024 character segments
[[ -n "${FULL_DETAILS}" ]] && DESC_FIELD=$(
cat <<EOF
{
"name": "Description",
"value": "${FULL_DETAILS:0:1024}"
},
EOF
)
[[ -n "${FULL_DETAILS}" ]] && [[ ${#FULL_DETAILS} -gt 1024 ]] && DESC_FIELD=$(
cat <<EOF
${DESC_FIELD}
{
"name": "Description (cont)",
"value": "${FULL_DETAILS:1024:1024}"
},
EOF
)
[[ -n "${FULL_DETAILS}" ]] && [[ ${#FULL_DETAILS} -gt 2048 ]] && DESC_FIELD=$(
cat <<EOF
${DESC_FIELD}
{
"name": "Description (cont)",
"value": "${FULL_DETAILS:2048:1024}"
},
EOF
)
# https://birdie0.github.io/discord-webhooks-guide/structure/embed/timestamp.html
# https://www.cyberciti.biz/faq/linux-unix-formatting-dates-for-display/
FORMATTED_TIMESTAMP=$(date -u +\"%Y-%m-%dT%H:%M:%S.000Z\" -d @"${TIMESTAMP}")
# https://birdie0.github.io/discord-webhooks-guide/structure/embed/thumbnail.html
# https://birdie0.github.io/discord-webhooks-guide/structure/embed/color.html
# vary data based on IMPORTANCE
if [[ "${IMPORTANCE}" != "normal" ]] && [[ "${IMPORTANCE}" != "warning" ]] && [[ "${IMPORTANCE}" != "alert" ]]; then
IMPORTANCE="normal"
fi
case "${IMPORTANCE}" in
normal)
THUMBNAIL="https://craftassets.unraid.net/uploads/discord/notify-normal.png"
COLOR="39208"
;;
warning)
THUMBNAIL="https://craftassets.unraid.net/uploads/discord/notify-warning.png"
COLOR="16747567"
;;
alert)
THUMBNAIL="https://craftassets.unraid.net/uploads/discord/notify-alert.png"
COLOR="14821416"
[[ -n "${DISCORD_TAG_ID}" && "${DISCORD_TAG_ID}" == "none" ]] && DISCORD_TAG_ID=""
if [[ -n "${DISCORD_TAG_ID}" ]]; then
# add leading @ if needed
[[ "${DISCORD_TAG_ID:0:1}" != "@" ]] && DISCORD_TAG_ID="@${DISCORD_TAG_ID}"
# @mentions only work in the "content" area, not the "embed" area
DISCORD_CONTENT_AREA="\"content\": \"<${DISCORD_TAG_ID}>\","
fi
;;
esac
# https://birdie0.github.io/discord-webhooks-guide/structure/embed/author.html
# if SERVER_ICON is defined, use it
[[ -n "${SERVER_ICON}" && "${SERVER_ICON:0:8}" == "https://" ]] && ICON_URL="\"icon_url\": \"${SERVER_ICON}\","
# https://birdie0.github.io/discord-webhooks-guide/structure/embed/url.html
# if LINK is defined, use it
[[ -n "${LINK}" ]] && LINK_URL="\"url\": \"${LINK}\","
DATA=$(
cat <<EOF
{
${DISCORD_CONTENT_AREA}
"embeds": [
{
"title": "${EVENT:0:256}",
"description": "${SUBJECT:0:2043}",
${LINK_URL}
"timestamp": ${FORMATTED_TIMESTAMP},
"color": "${COLOR}",
"author": {
${ICON_URL}
"name": "${HOSTNAME}"
},
"thumbnail": {
"url": "${THUMBNAIL}"
},
"fields": [
${DESC_FIELD}
{
"name": "Priority",
"value": "${IMPORTANCE}",
"inline": true
}
]
}
]
}
EOF
)
# echo "${DATA}" >>"${LOG}"
# try several times in case we are being rate limited
# this is not foolproof, messages can still be rejected
MAX=4
for ((i = 1; i <= "${MAX}"; i++)); do
RET=$(
curl -s -X "POST" "$WEBH_URL" -H 'Content-Type: application/json' --data-ascii @- <<EOF
${DATA}
EOF
)
# if nothing was returned, message was successfully sent. exit loop
[[ -z "${RET}" ]] && break
# log the attempt
{
date
echo "attempt ${i} of ${MAX} failed"
echo "${RET}"
} >>"${LOG}"
# if there was an error with the submission, log details and exit loop
[[ "${RET}" != *"retry_after"* ]] && echo "${DATA}" >>"${LOG}" && logger -t "${SCRIPTNAME}" -- "Failed sending notification" && break
# if retries exhausted, log failure
[[ "${i}" -eq "${MAX}" ]] && echo "${DATA}" >>"${LOG}" && logger -t "${SCRIPTNAME}" -- "Failed sending notification - rate limited" && break
# we were rate limited, try again after a delay
sleep 1
done
]]>
</Script>
</Agent>
<Agent>
<Name>Gotify</Name>
<Variables>
<Variable Help="The full server base URL including protocol and port. eg: https://example.com:8888/" Desc="Full Server Base URL" Default="">SERVER_URL</Variable>
<Variable Help="The App Token to use." Desc="App Token" Default="">APP_TOKEN</Variable>
<Variable Help="Specify the fields which are included in the title of the notification." Desc="Notification Title" Default="$SUBJECT">TITLE</Variable>
<Variable Help="Specify the fields which are included in the message body of the notification." Desc="Notification Message" Default="$DESCRIPTION">MESSAGE</Variable>
</Variables>
<Script>
<![CDATA[
#!/bin/bash
############
{0}
############
MESSAGE=$(echo -e "$MESSAGE")
case "$IMPORTANCE" in
'normal' )
PRIORITY="3"
;;
'warning' )
PRIORITY="5"
;;
'alert' )
PRIORITY="7"
;;
esac
# Remove any trailing slash
SERVER_URL=${SERVER_URL%/}
curl -s -k -X POST \
-F "title=$TITLE" \
-F "message=$MESSAGE" \
-F "priority=$PRIORITY" \
${SERVER_URL}/message?token=$APP_TOKEN 2>&1
]]>
</Script>
</Agent>
<Agent>
<Name>Join</Name>
<Variables>
<Variable Help="The API key can be found [a href='https://joinjoaomgcd.appspot.com' target='_blank'] [u]here[/u].[/a]" Desc="API key" Default="">API_KEY</Variable>
<Variable Help="Specify the fields which are included in the title of the notification." Desc="Notification Title" Default="$SUBJECT">TITLE</Variable>
<Variable Help="Specify the fields which are included in the message body of the notification." Desc="Notification Message" Default="$DESCRIPTION">MESSAGE</Variable>
</Variables>
<Script>
<![CDATA[
#!/bin/bash
##########
{0}
##########
TITLE=$(echo -e "$TITLE")
MESSAGE=$(echo -e "$MESSAGE")
curl -s -k -G \
-d "apikey=$API_KEY" \
--data-urlencode "title=$TITLE" \
--data-urlencode "text=$MESSAGE" \
-d "deviceId=group.all" \
https://joinjoaomgcd.appspot.com/_ah/api/messaging/v1/sendPush 2>&1
]]>
</Script>
</Agent>
<Agent>
<Name>ntfy.sh</Name>
<Variables>
<Variable Help="The full server base URL including protocol and port. eg: https://ntfy.sh" Desc="Full Server Base URL" Default="FULL NTFY.SH URL">SERVER_URL</Variable>
<Variable Help="The ntfy.sh Token to use." Desc="ntfy.sh Token" Default="YOUR NTFY.SH TOKEN">NTFY_TOKEN</Variable>
<Variable Help="The ntfy.sh Topic to use." Desc="ntfy.sh Topic" Default="Unraid">TOPIC</Variable>
<Variable Help="Specify the fields which are included in the title of the notification." Desc="Notification Title" Default="$SUBJECT">TITLE</Variable>
<Variable Help="Specify the fields which are included in the message body of the notification." Desc="Notification Message" Default="$DESCRIPTION">MESSAGE</Variable>
</Variables>
<Script>
<![CDATA[
#!/bin/bash
############
{0}
############
MESSAGE=$(echo -e "$MESSAGE")
case "$IMPORTANCE" in
'normal' )
PRIORITY="default"
;;
'warning' )
PRIORITY="high"
;;
'alert' )
PRIORITY="urgent"
;;
esac
# Remove any trailing slash
SERVER_URL=${SERVER_URL%/}
curl \
-H "Priority: $PRIORITY" \
-H "Icon: https://raw.githubusercontent.com/unraid/webgui/master/emhttp/plugins/dynamix.vm.manager/templates/images/unraid.png" \
-H "Authorization: Bearer $NTFY_TOKEN" \
-H "Title: $TITLE" \
-d "$MESSAGE" \
$SERVER_URL/$TOPIC
]]>
</Script>
</Agent>
<Agent>
<Name>Prowl</Name>
<Variables>
<Variable Help="Get your api key as explained [a href='https://www.prowlapp.com/api_settings.php' target='_blank'][u]here[/u].[/a]" Desc="Api Key" Default="">API_KEY</Variable>
<Variable Help="Application name, e.g., Unraid Server." Desc="Application Name" Default="Unraid Server">APP_NAME</Variable>
<Variable Help="Specify the fields which are included in the title of the notification." Desc="Notification Title" Default="$SUBJECT">TITLE</Variable>
<Variable Help="Specify the fields which are included in the message body of the notification." Desc="Notification Message" Default="$DESCRIPTION">MESSAGE</Variable>
</Variables>
<Script>
<![CDATA[
#!/bin/bash
############
{0}
############
TITLE=$(echo -e "$TITLE")
MESSAGE=$(echo -e "$MESSAGE")
case "$IMPORTANCE" in
'normal' )
PRIORITY="0"
;;
'warning' )
PRIORITY="1"
;;
'alert' )
PRIORITY="2"
;;
esac
curl -s -k \
-F "apikey=$API_KEY" \
-F "application=$APP_NAME" \
-F "event=$TITLE" \
-F "description=$MESSAGE" \
-F "priority=$PRIORITY" \
https://api.prowlapp.com/publicapi/add 2>&1
]]>
</Script>
</Agent>
<Agent>
<Name>PushBits</Name>
<Variables>
<Variable Help="The full server base URL including protocol and port. eg: https://example.com:8080/" Desc="Full Server Base URL" Default="FULL PUSHBITS URL">SERVER_URL</Variable>
<Variable Help="The App Token to use." Desc="App Token" Default="YOUR APP TOKEN">APP_TOKEN</Variable>
<Variable Help="Specify the fields which are included in the title of the notification." Desc="Notification Title" Default="$SUBJECT">TITLE</Variable>
<Variable Help="Specify the fields which are included in the message body of the notification." Desc="Notification Message" Default="$DESCRIPTION">MESSAGE</Variable>
</Variables>
<Script>
<![CDATA[
#!/bin/bash
############
{0}
############
MESSAGE=$(echo -e "$MESSAGE")
case "$IMPORTANCE" in
'normal' )
PRIORITY="0"
;;
'warning' )
PRIORITY="5"
;;
'alert' )
PRIORITY="21"
;;
esac
# Remove any trailing slash
SERVER_URL=${SERVER_URL%/}
curl -s -k -X POST \
-F "title=$TITLE" \
-F "message=$MESSAGE" \
-F "priority=$PRIORITY" \
${SERVER_URL}/message?token=$APP_TOKEN 2>&1
]]>
</Script>
</Agent>
<Agent>
<Name>Pushbullet</Name>
<Variables>
<Variable Help="The Access Token can be found [a href='https://www.pushbullet.com/account' target='_blank'] [u]here[/u].[/a]" Desc="Access Token" Default="">TOKEN</Variable>
<Variable Help="Specify the fields which are included in the title of the notification." Desc="Notification Title" Default="$SUBJECT">TITLE</Variable>
<Variable Help="Specify the fields which are included in the message body of the notification." Desc="Notification Message" Default="$DESCRIPTION">MESSAGE</Variable>
</Variables>
<Script>
<![CDATA[
#!/bin/bash
##########
{0}
##########
MESSAGE=$(echo "$MESSAGE" | sed -e 's:<br[ /]*>:\\n:gI' -e 's/<[^>]*>//g')
curl -s -k \
-X POST --header "Authorization: Bearer $TOKEN" \
--header 'Content-Type: application/json' \
-d "{\"type\": \"note\", \"title\": \"$TITLE\", \"body\": \"$MESSAGE\"}" \
https://api.pushbullet.com/v2/pushes 2>&1
]]>
</Script>
</Agent>
<Agent>
<Name>Pushover</Name>
<Variables>
<Variable Help="The User Key can be found [a href='https://pushover.net/' target='_blank'][u]here[/u].[/a]" Desc="User Key" Default="">USER_KEY</Variable>
<Variable Help="The App Token can be found [a href='https://pushover.net/apps' target='_blank'][u]here[/u][/a]." Desc="App Token" Default="">APP_TOKEN</Variable>
<Variable Help="Specify the fields which are included in the message body of the notification." Desc="Notification Message" Default="$SUBJECT,$DESCRIPTION">MESSAGE</Variable>
</Variables>
<Script>
<![CDATA[
#!/bin/bash
############
{0}
############
MESSAGE=$(echo -e "$MESSAGE")
case "$IMPORTANCE" in
'normal' )
PRIORITY="-1"
;;
'warning' )
PRIORITY="0"
;;
'alert' )
PRIORITY="1"
;;
esac
curl -s -k \
-F "token=$APP_TOKEN" \
-F "user=$USER_KEY" \
-F "message=$MESSAGE" \
-F "timestamp=$TIMESTAMP" \
-F "priority=$PRIORITY" \
-F "html=1" \
https://api.pushover.net/1/messages.json 2>&1
]]>
</Script>
</Agent>
<Agent>
<Name>Pushplus</Name>
<Variables>
<Variable Help="Get your token from [a href='https://www.pushplus.plus/push1.html' target='_blank'][u]here[/u][/a]." Desc="Push Token" Default="FILL WITH YOUR OWN">TOKEN</Variable>
<Variable Help="Optional. Specify the group code or the 'topic' mentioned in the [a href='https://www.pushplus.plus/doc/guide/api.html' target='_blank'][u]API docs[/u][/a] used for this push. It's used to [a href='https://www.pushplus.plus/push2.html' target='_blank'][u]push to multiple people[/u][/a] instead of pushing to the owner. [b]To disable this feature, specify 'none'.[/b]" Desc="Specific Group Code" Default="none">TOPIC</Variable>
<Variable Help="Optional. Specify the message channel used for this push. [b]The default value is 'wechat'.[/b]" Desc="Specific Channel" Default="wechat">CHANNEL</Variable>
<Variable Help="Optional. Specify the webhook used for this push when the push channel is 'webhook' or 'cp'. [b]To disable this feature, specify 'none'.[/b]" Desc="Webhook" Default="none">WEBHOOK</Variable>
<Variable Help="Optional. Specify the callback url used for this push and the pushplus server will send a post request to it after each push completed. [b]To disable this feature, specify 'none'.[/b]" Desc="Callback Url" Default="none">CALLBACKURL</Variable>
<Variable Help="Specify the fields which are included in the title of the notification." Desc="Notification Title" Default="$SUBJECT">TITLE</Variable>
<Variable Help="Specify the fields which are included in the message body of the notification." Desc="Notification Message" Default="$DESCRIPTION">MESSAGE</Variable>
</Variables>
<Script>
<![CDATA[
#!/bin/bash
############
{0}
############
#Pushplus don't allow \n in title and the length limit is 100 for free accounts
TITLE=$(echo -e "$TITLE" | tr "\n" " ")
TITLE=$(echo "${TITLE:0:95}")
MESSAGE=$(echo -e "$MESSAGE")
[[ -n "${TOPIC}" && "${TOPIC}" == "none" ]] && TOPIC=""
[[ -n "${CHANNEL}" && "${CHANNEL}" == "none" ]] && CHANNEL="wechat"
[[ -n "${WEBHOOK}" && "${WEBHOOK}" == "none" ]] && WEBHOOK=""
[[ -n "${CALLBACKURL}" && "${CALLBACKURL}" == "none" ]] && CALLBACKURL=""
curl -s -k -X POST \
-F "token=$TOKEN" \
-F "title=$TITLE" \
-F "content=$MESSAGE" \
-F "topic=$TOPIC" \
-F "template=txt" \
-F "channel=$CHANNEL" \
-F "webhook=$WEBHOOK" \
-F "callbackUrl=$CALLBACKURL" \
"https://www.pushplus.plus/send" 2>&1
]]>
</Script>
</Agent>
<Agent>
<Name>ServerChan</Name>
<Variables>
<Variable Help="Get your SendKey from [a href='https://sct.ftqq.com/sendkey' target='_blank'][u]here[/u][/a]." Desc="SendKey" Default="FILL WITH YOUR OWN">SENDKEY</Variable>
<Variable Help="Optional. Specify the message channel(s) used for this push, e.g., '9' or '9|66'. [b]To disable this feature, specify 'none'.[/b]" Desc="Specific Channel" Default="none">CHANNEL</Variable>
<Variable Help="Optional. Specify the openid(s) or UID(s) used for this push, e.g., 'openid1,openid2' or 'UID1|UID2'. [b]To disable this feature, specify 'none'.[/b]" Desc="Specific Openid" Default="none">OPENID</Variable>
<Variable Help="Specify the fields which are included in the title of the notification." Desc="Notification Title" Default="$SUBJECT">TITLE</Variable>
<Variable Help="Specify the fields which are included in the message body of the notification." Desc="Notification Message" Default="$DESCRIPTION">MESSAGE</Variable>
</Variables>
<Script>
<![CDATA[
#!/bin/bash
############
{0}
############
# Markdown newline style for message content
TITLE=$(echo -e "$TITLE")
MESSAGE=$(echo -e "$MESSAGE" | sed -z 's/\n/\n\n/g')
[[ -n "${CHANNEL}" && "${CHANNEL}" == "none" ]] && CHANNEL=""
[[ -n "${OPENID}" && "${OPENID}" == "none" ]] && OPENID=""
curl -s -k -X POST \
-F "title=$TITLE" \
-F "desp=$MESSAGE" \
-F "channel=$CHANNEL" \
-F "openid=$OPENID" \
"https://sctapi.ftqq.com/$SENDKEY.send" 2>&1
]]>
</Script>
</Agent>
<Agent>
<Name>Slack</Name>
<Variables>
<Variable Help="Get your WebHook as explained [a href='https://api.slack.com/incoming-webhooks' target='_blank'][u]here[/u].[/a]" Desc="WebHook URL" Default="USE YOUR OWN WEBHOOK VALUE HERE">WEBH_URL</Variable>
<Variable Help="Application name, e.g., Unraid Server." Desc="Application Name" Default="Unraid Server">APP_NAME</Variable>
<Variable Help="Specify the fields which are included in the title of the notification." Desc="Notification Title" Default="$SUBJECT">TITLE</Variable>
<Variable Help="Specify the fields which are included in the message body of the notification." Desc="Notification Message" Default="$DESCRIPTION">MESSAGE</Variable>
</Variables>
<Script>
<![CDATA[
#!/bin/bash
############
{0}
############
TITLE=$(echo -e "$TITLE")
MESSAGE=$(echo -e "$MESSAGE")
curl -X POST --header 'Content-Type: application/json' \
-d "{\"username\": \"$APP_NAME\", \"text\": \"*$TITLE* \n $MESSAGE\"}" $WEBH_URL 2>&1
]]>
</Script>
</Agent>
<Agent>
<Name>Telegram</Name>
<Variables>
<Variable Help="[a href='https://telegram.me/botfather' target='_blank'][u]BotFather[/u][/a] is the one bot to rule them all.[br][br]
1. Make a bot using BotFather[br]
2. Paste the bot token in this field[br]
3. Message the bot via Telegram (either via a direct message or a message via a group)[br]
4. Test the bot[br][br]
* To reset the notifications receiving user or group, run [i]rm /boot/config/plugins/dynamix/telegram/chatid[/i] in the terminal and re-run steps 3. and 4.[/a]" Desc="Bot Access Token" Default="">BOT_TOKEN</Variable>
<Variable Help="Specify the fields which are included in the title of the notification." Desc="Notification Title" Default="$SUBJECT">TITLE</Variable>
<Variable Help="Specify the fields which are included in the message body of the notification." Desc="Notification Message" Default="$DESCRIPTION">MESSAGE</Variable>
</Variables>
<Script>
<![CDATA[
#!/bin/bash
############
{0}
############
LEGACY=/boot/config/telegram
TELEGRAM=/boot/config/plugins/dynamix/telegram
STORED_TOKEN=$(< $TELEGRAM/token) || "";
# move legacy folder (if existing)
[[ -d $LEGACY && ! -d $TELEGRAM ]] && mv $LEGACY $TELEGRAM
if [[ ! -f $TELEGRAM/token || "$STORED_TOKEN" != "$BOT_TOKEN" ]]; then
mkdir -p $TELEGRAM;
echo $BOT_TOKEN > $TELEGRAM/token;
fi
if [[ ! -f $TELEGRAM/chatid || "$STORED_TOKEN" != "$BOT_TOKEN" ]]; then
mkdir -p $TELEGRAM;
LASTCHATID=$(curl -s https://api.telegram.org/bot$BOT_TOKEN/getUpdates | jq ".result | last .message .chat .id");
[[ $LASTCHATID =~ ^-*[0-9]+$ ]] && echo $LASTCHATID > $TELEGRAM/chatid || exit 1
fi
CHATID=$(< $TELEGRAM/chatid);
MESSAGE=$(echo -e "$(hostname): $TITLE\n$MESSAGE");
curl -G -s "https://api.telegram.org/bot$BOT_TOKEN/sendMessage" --data-urlencode "chat_id=$CHATID" --data-urlencode "text=$MESSAGE" 2>&1;
]]>
</Script>
</Agent>
<Agent>
<Name>Bark</Name>
<Variables>
<Variable Help="Get your push url from Bark APP. [a href='https://bark.day.app/#/tutorial' target='_blank'][u]tutorial[/u][/a]." Desc="PushUrl" Default="https://api.day.app/your_key">PUSHURL</Variable>
<Variable Help="Optional. Specify the message group used for this push. [b]To disable this feature, specify 'none'.[/b]" Desc="Group" Default="Unraid">GROUP</Variable>
<Variable Help="Optional. Specify the message sound, copy the sound name from Bark APP. [b]To disable this feature, specify 'none'.[/b]" Desc="Sound" Default="none">SOUND</Variable>
<Variable Help="Specify the fields which are included in the title of the notification." Desc="Notification Title" Default="$SUBJECT">TITLE</Variable>
<Variable Help="Specify the fields which are included in the message body of the notification." Desc="Notification Message" Default="$DESCRIPTION">MESSAGE</Variable>
</Variables>
<Script>
<![CDATA[
#!/bin/bash
############
{0}
############
# Markdown newline style for message content
TITLE=$(echo -e "$TITLE")
MESSAGE=$(echo -e "$MESSAGE")
[[ -n "${GROUP}" && "${GROUP}" == "none" ]] && GROUP=""
[[ -n "${SOUND}" && "${SOUND}" == "none" ]] && SOUND=""
curl -X "POST" "$PUSHURL" \
-H 'Content-Type: application/json; charset=utf-8' \
-d "{\"body\": \"$MESSAGE\", \"title\": \"$TITLE\", \"sound\": \"$SOUND\", \"group\": \"$GROUP\"}" 2>&1
]]>
</Script>
</Agent>
</Agents>