Code: Select all
:global urlEncode do={
:local output ""
:local input [:toarray $1]
:if ([:len $input] > 0) do={
:local input1 [:tostr [:pick $input 0]]
:local conversion {" "="%20";"!"="%21";"\""="%22";"#"="%23";"\$"="%24";"%"="%25";"&"="%26";"'"="%27";"-"="%2D";"("="%28";")"="%29";"*"="%2A";"+"="%2B";","="%2C";"/"="%2F";":"="%3A";";"="%3B";"<"="%3C";">"="%3E";"="="%3D";"?"="%3F";"@"="%40";"["="%5B";"]"="%5D";"{"="%7B";"}"="%7D"};
:for i from=0 to=([:len $input1] - 1) do={
:local char [:pick $input1 $i]
:if ([:typeof ($conversion->[:tostr $char])]!="nothing") do={:set $char ($conversion->[:tostr $char]);}
:set output ($output . $char)
}
:set output [:tostr $output]
:set output [:toarray $output]
}
:return $output
}
:global pushover do={
:global urlEncode;
:if ([:typeof $message]!="nothing") do={
:local api "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
:local user "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
:local urlmessage [$urlEncode $message];
:local string "token=$api&user=$user&message=$urlmessage";
:if ([:typeof $title]!="nothing") do={:set $string ($string . "&title=$[$urlEncode $title]");}
:if ([:typeof $priority]!="nothing") do={:set $string ($string . "&priority=$priority");}
:if ([:typeof $sound]!="nothing") do={:set $string ($string . "&sound=$sound");}
/tool fetch mode=https url="https://api.pushover.net/1/messages.json" http-method=post http-data="$string";
}
}
Code: Select all
$pushover message="This is a simple Pushover message."
Code: Select all
:local title "Important message from router $[/system identity get name]";
:local message "Just writing to inform you that my temperature is $[/system health get temperature] degrees Celsius!"
$pushover title=$title message=$message priority=1 sound="tugboat"