-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #596 from madman1968/update_pushover_module
Added support for html and device to API call
- Loading branch information
Showing
1 changed file
with
30 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,9 @@ Configure the required pushover settings in your mh.private.ini file: | |
Pushover_token = <API token from Pushover.net registration> | ||
Pushover_user = <User or Group ID from Pushover.net registraton> | ||
Pushover_device = <Default device or device list to sedn notifications to. List is comma-separated> | ||
Pushover_priority = [-1 | 0 | 1 | 2] Default message priority, defaults to 0. | ||
Pushover_html = [ 0 | 1 ] Support HTML messages, see https://pushover.net/api#html. Defaults to 0. | ||
Pushover_title = "MisterHouse" Default title for messages if none provided | ||
Pushover_disable = 1 Disable notifications. Messages will still be logged | ||
|
@@ -39,6 +41,9 @@ values provided on initialization. See the method documentation for below more | |
$push->notify( "Some important message", { title => 'Security Alert', priority => 2 }); | ||
Or with HTML formmatting | ||
$push->notify( "Some <b>important</b> message", { title => 'Security Alert', priority => 2, html => 1 }); | ||
=head2 DESCRIPTION | ||
The Pushover instance establishes the defaults for messages and acts as a rudimentary rate limiter for notifications. | ||
|
@@ -90,7 +95,8 @@ Creates a new Pushover object. The parameter hash is optional. Defaults will be | |
B<This must be excluded from the primary misterhouse loop, or the acknowledgment checking and duplicate message rate limiting will be lost> | ||
my $push = Pushover->new( { priority => 0, # Set default Message priority, -1, 0, 1, 2 | ||
retry => 60, # Set default retry priority 2 notification every 60 seconds | ||
html => 1, # Support HTML formatting of message ...see https://pushover.net/api#html | ||
retry => 60, # Set default retry priority 2 notification every 60 seconds | ||
expire => 3600, # Set default expration of the retry timer | ||
title => "Some title", # Set default title for messages | ||
token => "xxxx...", # Set the API Token | ||
|
@@ -122,11 +128,12 @@ sub new { | |
$params = {} unless defined $params; | ||
|
||
my $self = {}; | ||
$self->{priority} = 0; # Priority zero - honor quite times | ||
$self->{speak} = 1; # Speak notifications and acknowledgments | ||
$self->{priority} = 0; # Priority zero - honour quite times | ||
$self->{speak} = 1; # Speak notifications and acknowledgements | ||
$self->{html} = 0; # Default html off | ||
|
||
# Merge the mh.private.ini defaults into the object | ||
foreach (qw( token user priority title server retry expire speak disable)) { | ||
foreach (qw( token user priority html title device server retry expire speak disable)) { | ||
$self->{$_} = $params->{$_}; | ||
$self->{$_} = $::config_parms{"Pushover_$_"} unless defined $self->{$_}; | ||
} | ||
|
@@ -163,11 +170,13 @@ information for the notification. The list is not exclusive. Additional parame | |
in the POST to Pushover.net. This allows support of any API parameter as defined at https://pushover.net/api | ||
$push->notify("Some urgent message", { priority => 2, # Message priority, -1, 0, 1, 2 | ||
retry => 60, # Retry priority 2 notification every 60 seconds | ||
expire => 3600, # Give up if not ack of priority 2 notify after 1 hour | ||
title => "Some title", # Override title of message | ||
token => "xxxx...", # Override the API Token - probably not useful | ||
user => "xxxx...", # Override the target user/group | ||
html => 1, # HTML formatting of message 0-off, 1-on ... see https://pushover.net/api#html | ||
retry => 60, # Retry priority 2 notification every 60 seconds | ||
expire => 3600, # Give up if not ack of priority 2 notify after 1 hour | ||
title => "Some title", # Override title of message | ||
device => "nexus5,iphone" # Device or device-list | ||
token => "xxxx...", # Override the API Token - probably not useful | ||
user => "xxxx...", # Override the target user/group | ||
}); | ||
Notify will record the last message sent along with a timestamp. If the duplicate message is sent within | ||
|
@@ -210,7 +219,7 @@ sub notify { | |
} | ||
|
||
# Merge in the message defaults, They can be overridden | ||
foreach (qw( token user priority title url url_title sound retry expire )) { | ||
foreach (qw( token user priority html title device url url_title sound retry expire )) { | ||
next unless ( defined $self->{$_} ); | ||
$callparms->{$_} = $self->{$_} unless defined $callparms->{$_}; | ||
} | ||
|
@@ -225,6 +234,11 @@ sub notify { | |
$callparms->{expire} = 86400 if ( $callparms->{expire} > 86400 ); | ||
} | ||
|
||
# remove html if off | ||
if ( $callparms->{html} != 1 ) { | ||
delete $callparms->{html}; | ||
} | ||
|
||
&::print_log( | ||
"[Pushover] Notify parameters: " . Data::Dumper::Dumper( \$callparms ) ) | ||
if TRACE; | ||
|
@@ -354,6 +368,11 @@ sub _checkReceipt { | |
George Clark | ||
=head2 MODIFICATIONS | ||
2016/04/29 Marc [email protected] | ||
Added html and device support on API call | ||
=head2 SEE ALSO | ||
http://Pushover.net/ | ||
|
@@ -368,3 +387,4 @@ You should have received a copy of the GNU General Public License along with thi | |
=cut | ||
|
||
|