Slack integration?

Hi, all:

Has anyone set up integration with slack, perhaps via a webhook?

Best,
Konstantin Ryabitsev
Linux Foundation Collab Projects
Montréal, Québec

signature.asc (538 Bytes)

I am also curious about integrating Slack with RT. Has anyone tried to
work on this?

thanks,
JoshOn 11/11/14 2:05 PM, Konstantin Ryabitsev wrote:

Hi, all:

Has anyone set up integration with slack, perhaps via a webhook?

Best,

Hi Josh, Konstantin,

Just wondering if either of you pursued this, or possibly created your
own solution?

Nope, sorry, didn’t have enough cycles on the team to get this done.

-K

Hi Josh, Konstantin,

Just wondering if either of you pursued this, or possibly created your
own solution?

Nope, sorry, didn’t have enough cycles on the team to get this done.

I got something very basic working as a proof of concept, but I don’t
think I’ve got the interest to take it further. But for the benefit of
the list archives here it is. I put this in the cleanup code section of
a Scrip.

Tim.

use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
use JSON;

my $ticket = $self->TicketObj->id;
$ticket = “https://my.rt.url/$ticket|#$ticket”;
my $subject = $self->TicketObj->Subject;
my $description = $self->TransactionObj->Description;

my $data = { ‘text’ => “Ticket updated: $ticket - $subject\n$description.” };

my $ua = LWP::UserAgent->new;
$ua->timeout(15);

my $req = POST(“https://hooks.slack.com/services/…”, [‘payload’ => encode_json($data)]);

my $resp = $ua->request($req)->as_string;

Tim Bishop
http://www.bishnet.net/tim/
PGP Key: 0x6C226B37FDF38D55

I wrote a module for this a while back. You just need to save it as
local/lib/RT/Extension/Slack.pm and in RT_SiteConfig.pm you need to
define SlackIncomingWebhookURL and SlackIncomingWebhookToken. Then you
can simply call RT::Extension::Slack::Notify(%paramhash) wherever you
need.

For example:

 RT::Extension::Slack::Notify(username   => 'Mr. RT',
                              icon_emoji => 

‘:heavy_exclamation_mark:’,
text => $text);

Slack.pm
package RT::Extension::Slack;

use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
use JSON;

sub Notify {
my %args = @_;
my $payload = {
username => ‘Mr. RT’,
icon_emoji => ‘:ghost:’,
text => ‘I have forgotten to say something’,
};
my $service_endpoint;
my $service_token;

foreach (keys %args) {
$payload->{$} = $args{$};
}
if (!$payload->{text}) {
return;
}
my $payload_json = encode_json($payload);

$service_endpoint = RT->Config->Get(‘SlackIncomingWebhookURL’);
$service_token = RT->Config->Get(‘SlackIncomingWebhookToken’);
if (!$service_endpoint || !$service_token) {
return;
}

my $ua = LWP::UserAgent->new;
$ua->timeout(10);

$RT::Logger->info(‘Pushing notification to Slack: ‘. $payload_json);
my $r = POST($service_endpoint .’?token=’. $service_token,
[ ‘payload’ => $payload_json ]);

my $response = $ua->request($r);
if ($response->is_success) {
$RT::Logger->info(‘Successfully pushed notification to Slack’);
}
else {
$RT::Logger->error(‘Failed to push notification to Slack (’.
$response->code .’: ‘. $response->message .’)’);
}
}

1;
Slack.pm

This is an example action module that uses the Slack extension:

NotifySlackOnCreate.pm
use strict;
use warnings;

use base qw(RT::Action);

=head2 Prepare

=cut

sub Prepare {
my $self = shift;

 return 1;

}

=head2 Commit

=cut
sub Commit {
my $self = shift;
my $text;
my $requestor;
my $ticket = $self->TicketObj;
my $queue = $ticket->QueueObj;
my $url = join ‘’,
RT->Config->Get(‘WebPort’) == 443 ? ‘https’ : ‘http’,
’://’,
RT->Config->Get(‘WebDomain’),
RT->Config->Get(‘WebPath’),
’/Ticket/Display.html?id=’,
$ticket->Id;

 $requestor = $ticket->RequestorAddresses || 'unknown';
 $text = sprintf('Ticket #%d by %s has been created in %s | '.
                 '<%s|click to open>', $ticket->Id, $requestor,
                 $queue->Name, $url);

 RT::Extension::Slack::Notify(icon_emoji => 

‘:heavy_exclamation_mark:’,
text => $text);

 return 1;

}

1;
NotifySlackOnCreate.pm

Of course you can just turn the action module into a Scrip easily and
use it for any event.

Maciek

I made this one a few weeks ago that does some linkification and
displays our own custom emoji.

-AOn Fri, Jun 12, 2015 at 5:18 AM, Konstantin Ryabitsev konstantin@linuxfoundation.org wrote:

On 11/06/15 08:10 AM, Tim Bishop wrote:

Hi Josh, Konstantin,

Just wondering if either of you pursued this, or possibly created your
own solution?

Nope, sorry, didn’t have enough cycles on the team to get this done.

-K