Skip to content

Instantly share code, notes, and snippets.

@creaktive
Created September 9, 2025 14:26
Show Gist options
  • Save creaktive/f79b395be2682166cda7ae7c35451d22 to your computer and use it in GitHub Desktop.
Save creaktive/f79b395be2682166cda7ae7c35451d22 to your computer and use it in GitHub Desktop.
Pushsafer notifications for Convos DMs
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