Created
September 9, 2025 14:26
-
-
Save creaktive/f79b395be2682166cda7ae7c35451d22 to your computer and use it in GitHub Desktop.
Pushsafer notifications for Convos DMs
This file contains hidden or 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
package Convos::Plugin::Pushsafer; | |
use Mojo::Base 'Convos::Plugin', -signatures; | |
sub register($self, $app, $config = {}) { | |
my $ua = $app->ua; | |
my $key = ...; | |
my $dev = ...; | |
my $prio = 0; | |
my $icon = 33; | |
$app->core->backend->on(connection => sub ($backend, $conn) { | |
$conn->on(message => sub ($conn, $conversation, $msg) { | |
return unless $msg && $msg->{type} && $msg->{type} eq 'private'; | |
my $from = $msg->{from} // ''; | |
return if lc($from) eq lc($conn->nick // ''); # ignore my own messages | |
my $chat = $conversation && $conversation->can('name') ? ($conversation->name // '') : ''; | |
return if $chat =~ /^[#&+!]/; | |
my $server = $conn->name // $conn->id // ''; | |
return if $server eq $from; | |
my $title = sprintf("New DM from %s on %s", $from, $server); | |
my $body = $msg->{message} // ''; | |
my %form = ( | |
k => $key, # required | |
d => $dev, # device | |
i => $icon, # icon | |
t => $title, # title | |
m => $body, # message | |
pr => $prio, # priority (-2..2) | |
); | |
return $ua->post_p('https://www.pushsafer.com/api' => form => \%form); | |
}); | |
}); | |
} | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment