Skip to content

Instantly share code, notes, and snippets.

@darkpixel
Created June 12, 2015 18:53
Show Gist options
  • Save darkpixel/1effa7175d3850c5e8b5 to your computer and use it in GitHub Desktop.
Save darkpixel/1effa7175d3850c5e8b5 to your computer and use it in GitHub Desktop.
RT post to Slack
use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
use JSON;
my $webhook_url = 'your-webhook-url';
my $default_channel = '#your-channel';
my $ua = LWP::UserAgent->new;
$ua->timeout(15);
my $payload = {
channel => $default_channel // $default_channel,
username => 'RTbot',
icon_emoji => ':uit-ticket:',
text => '',
};
$payload->{text} .= "New ticket <https://my-rt-server.tld/Ticket/Display.html?id=" . $self->TicketObj->Id . "|" . $self->TicketObj->Id . "> from " . $self->TicketObj->RequestorAddresses . ": " . $self->TicketObj->Subject;
my $req = POST("$webhook_url", ['payload' => encode_json($payload)]);
my $resp = $ua->request($req);
if ($resp->is_success) {
print '';
} else {
RT->Logger->error($resp->status_line);
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment