[Bps-public-commit] rt-extension-notifyslack branch, craig, created. d1854d241dbc92d8ddc655af908077b06ad31519

Craig Kaiser craig at bestpractical.com
Fri Nov 2 17:25:57 EDT 2018


The branch, craig has been created
        at  d1854d241dbc92d8ddc655af908077b06ad31519 (commit)

- Log -----------------------------------------------------------------
commit d1854d241dbc92d8ddc655af908077b06ad31519
Author: Craig Kaiser <craig at bestpractical.com>
Date:   Thu Nov 1 17:03:21 2018 -0400

    Use templates to generate slack message
    
    Use JSON slack API format as the message template content:
    \{
        "text": "{$Transaction->BriefDescription}",
        "attachments": [
            \{
                "text": "And here’s an attachment!"
            \}
        ]
    \}

diff --git a/lib/RT/Action/NotifySlack.pm b/lib/RT/Action/NotifySlack.pm
index d694dae..d629103 100644
--- a/lib/RT/Action/NotifySlack.pm
+++ b/lib/RT/Action/NotifySlack.pm
@@ -18,6 +18,11 @@ sub Prepare  {
 
 sub Commit {
     my $self = shift;
+    # Need to create our MIMEObj
+    $self->TemplateObj->Parse(
+        TicketObj      => $self->TicketObj,
+        TransactionObj => $self->TransactionObj,
+    );
 
     my $webhook_urls = RT->Config->Get( 'SlackWebHookUrls' ) || {};
     my $channel = $self->Argument;
@@ -40,18 +45,9 @@ sub Commit {
     # prevent infinite loop between RT and Slack
     return 0 if $txn->Type eq 'SlackNotified';
 
-    # Slack uses the format <www.example.com|Example Text> to insert a link into the payload's text
-    my $slack_message = '<'.$rt_url.'|Ticket #'.$ticket->id.'>: '.$txn->BriefDescription;
+    my $payload = $self->TemplateObj->MIMEObj->as_string;
 
-    if ( $txn->Type eq 'Comment' || $txn->Type eq 'Correspond' ) {
-        $slack_message = $slack_message . ' on <'.$rt_url.'#txn-'.$txn->id.'| #txn-'.$txn->id.'>';
-    }
-
-    my $payload = {
-        text => $slack_message,
-    };
-
-    my $req = POST("$webhook_url", ['payload' => encode_json($payload)]);
+    my $req = POST("$webhook_url", ['payload' => $payload]);
 
     my $resp = $ua->request($req);
 

-----------------------------------------------------------------------


More information about the Bps-public-commit mailing list