Skip to content

Instantly share code, notes, and snippets.

@artifactsauce
Created August 22, 2016 07:37
Show Gist options
  • Save artifactsauce/7592d290c484b896dd1b4f7b5173e071 to your computer and use it in GitHub Desktop.
Save artifactsauce/7592d290c484b896dd1b4f7b5173e071 to your computer and use it in GitHub Desktop.
Simple test script to post to slack
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use JSON;
use Data::Dumper;
use LWP::UserAgent;
my $url = $ENV{SLACK_WEBHOOK_URL};
my $channel = '#sandbox';
my $username = 'Test Agent';
my $icon = ':jack_o_lantern:';
my $message = $ARGV[0];
my $post_data = {
payload => encode_json +{
channel => $channel,
username => $username,
icon_emoji => $icon,
text => $message,
},
};
my $headers = {};
my $ua = LWP::UserAgent->new;
my $response = $ua->post($url, $post_data, %$headers);
unless ($response->is_success) {
warn $response->status_line;
}
exit;
requires 'JSON';
requires 'LWP::UserAgent';
requires 'LWP::Protocol::https';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment