App-MonM
view release on metacpan or search on metacpan
lib/App/MonM/QNotifier.pm view on Meta::CPAN
$rcpts{$it} = "user" if grep {$_ eq $it} @users;
}
}
# Get Channels
my @channels = (); # Channel config sections
foreach my $it (keys %rcpts) {
my $notat = $rcpts{$it};
if ($notat eq 'user') {
# Get User node
my $usernode = node($self->config->conf("user"), $it);
next unless is_hash($usernode) && keys %$usernode;
# Get channels
my $channels_usr = hash($usernode => "channel");
foreach my $ch_name (keys %$channels_usr) {
my $at = lvalue($channels_usr, $ch_name, "at") || lvalue($usernode, "at");
my $basedon = lvalue($channels_usr, $ch_name, "basedon") || lvalue($channels_usr, $ch_name, "baseon") || '';
my $ch = merge(
hash($self->{ch_def}, $basedon || $ch_name),
hash($channels_usr, $ch_name),
{$at ? (at => $at) : ()},
);
$ch->{chname} = $ch_name;
push @channels, $ch;
}
} elsif ($notat eq 'email') {
my $ch = merge(hash($self->{ch_def}, "SendMail"), {to => $it});
$ch->{chname} = "SendMail";
push @channels, $ch;
} elsif ($notat eq 'number') {
my $ch = merge(hash($self->{ch_def}, "SMSGW"), {to => $it});
$ch->{chname} = "SMSGW";
push @channels, $ch;
}
}
return (@channels);
}
sub notify { # send message to recipients list
my $self = shift;
my %args = @_;
$self->error("");
my $before = $args{before}; # The callback for before sending
my $after = $args{after}; # The callback for after sending
my @channels = $self->getChanelsBySendTo(array($args{to}));
# Create messages and send its
foreach my $ch (@channels) {
#print App::MonM::Util::explain($ch);
my $message = App::MonM::Message->new(
to => lvalue($ch, "to"),
cc => lvalue($ch, "cc"),
bcc => lvalue($ch, "bcc"),
from => lvalue($ch, "from"),
subject => $args{subject} // '', # Message subject
body => $args{message} // '', # Message body
headers => hash($ch, "headers"),
contenttype => lvalue($ch, "contenttype"), # optional
charset => lvalue($ch, "charset"), # optional
encoding => lvalue($ch, "encoding"), # optional
attachment => node($ch, "attachment"),
);
# Run before callback
if (ref($before) eq 'CODE') {
&$before($self, $message) or next;
}
# Send message
my $sent = $self->channel->sendmsg($message, $ch);
# Run after callback
if (ref($after) eq 'CODE') {
&$after($self, $message, $sent) or next;
}
}
# returns status of operation
return 1;
}
sub remind { # tries to send postponed messages
my $self = shift;
$self->error("");
return 1;
}
1;
__END__
( run in 1.888 second using v1.01-cache-2.11-cpan-39bf76dae61 )