Skip to content

Instantly share code, notes, and snippets.

@nqounet
Created June 11, 2015 12:42
Show Gist options
  • Save nqounet/f6177ba152cfad2a72fa to your computer and use it in GitHub Desktop.
Save nqounet/f6177ba152cfad2a72fa to your computer and use it in GitHub Desktop.
Slack::IncomingWebHooks
package Slack::IncomingWebHooks;
use utf8;
use Moo;
use HTTP::Tiny;
use JSON::MaybeXS qw(JSON);
has url => (is => 'ro');
has channel => (is => 'ro');
has username => (is => 'ro');
has icon_url => (is => 'ro');
has icon_emoji => (is => 'ro');
has _json => (
is => 'ro',
default => sub { JSON->new }
);
sub send {
my $self = shift;
my $text = shift;
my $params = +{text => $text};
my $json_text = $self->_json->encode($params);
return HTTP::Tiny->new->post_form($self->url, +{payload => $json_text});
}
1;
__END__
## synopsis
use Slack::IncomingWebHooks;
my $hook = Slack::IncomingWebHooks->new(url => 'https://slack.com/hogehoge');
my $res = $hook->send('Hello World');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment