| | 291 | |
| | 292 | sub config_notifo { |
| | 293 | my ($this, $config) = @_; |
| | 294 | |
| | 295 | require Crypt::SSLeay; # https support |
| | 296 | require MIME::Base64; |
| | 297 | |
| | 298 | return # subscribe_user is not work with user account |
| | 299 | if (!defined($config->to) || $config->user eq $config->to); |
| | 300 | my $url = "https://api.notifo.com/v1/subscribe_user"; |
| | 301 | my $runloop = $this->_runloop; |
| | 302 | Tools::HTTPClient->new( |
| | 303 | Request => POST($url, [username => $config->user], |
| | 304 | Authorization => 'Basic '. |
| | 305 | MIME::Base64::encode($config->user .':'.$config->secret, "")), |
| | 306 | )->start( |
| | 307 | Callback => sub { |
| | 308 | my $stat = shift; |
| | 309 | if (!ref($stat)) { |
| | 310 | $runloop->notify_warn(__PACKAGE__." notifo: verify failed: $stat"); |
| | 311 | } elsif ($stat->{Content} !~ /"status":\s*"success"[,}]/) { |
| | 312 | (my $content = $stat->{Content}) =~ s/\s+/ /; |
| | 313 | $runloop->notify_warn(__PACKAGE__." notifo: verify failed: $content"); |
| | 314 | } |
| | 315 | }, |
| | 316 | ); |
| | 317 | } |
| | 318 | |
| | 319 | sub send_notifo { |
| | 320 | my ($this, $config, $text, $msg, $sender, $full_ch_name) = @_; |
| | 321 | |
| | 322 | my $url = "https://api.notifo.com/v1/send_notification"; |
| | 323 | $text = $this->strip_mirc_formatting($text); |
| | 324 | my $title = Auto::AliasDB->stdreplace( |
| | 325 | $msg->prefix, |
| | 326 | $config->title_format || '#(channel):#(nick.now)', |
| | 327 | $msg, $sender, |
| | 328 | channel => $full_ch_name, |
| | 329 | raw_channel => Auto::Utils::get_raw_ch_name($msg, 0), |
| | 330 | text => $text, |
| | 331 | ); |
| | 332 | my $uri = Auto::AliasDB->stdreplace( |
| | 333 | $msg->prefix, |
| | 334 | $config->uri_format || '', |
| | 335 | $msg, $sender, |
| | 336 | channel => $full_ch_name, |
| | 337 | raw_channel => Auto::Utils::get_raw_ch_name($msg, 0), |
| | 338 | text => $text, |
| | 339 | ); |
| | 340 | $text = Auto::AliasDB->stdreplace( |
| | 341 | $msg->prefix, |
| | 342 | $config->format || $this->config->format || '#(text)', |
| | 343 | $msg, $sender, |
| | 344 | channel => $full_ch_name, |
| | 345 | raw_channel => Auto::Utils::get_raw_ch_name($msg, 0), |
| | 346 | text => $text, |
| | 347 | ); |
| | 348 | my $data = [label => $config->label || 'tiarra', |
| | 349 | title => $title, |
| | 350 | to => $config->to || $config->user, |
| | 351 | ((defined($uri) && $uri ne "") ? (uri => $uri) : ()), |
| | 352 | msg => $text]; |
| | 353 | my $runloop = $this->_runloop; |
| | 354 | Tools::HTTPClient->new( |
| | 355 | Request => POST($url, $data, Authorization => 'Basic '. |
| | 356 | MIME::Base64::encode($config->user .':'.$config->secret, "")), |
| | 357 | )->start( |
| | 358 | Callback => sub { |
| | 359 | my $stat = shift; |
| | 360 | if (!ref($stat)) { |
| | 361 | $runloop->notify_warn(__PACKAGE__." notifo: post failed: $stat"); |
| | 362 | } elsif ($stat->{Content} !~ /"status":\s*"success"[,}]/) { |
| | 363 | (my $content = $stat->{Content}) =~ s/\s+/ /; |
| | 364 | $runloop->notify_warn(__PACKAGE__." notifo: post failed: $content"); |
| | 365 | } |
| | 366 | }, |
| | 367 | ); |
| | 368 | } |
| | 369 | |
| | 370 | |