Selaa lähdekoodia

Merge pull request #17 from troglodyne/compact_notifications

Compact notifications for Slack
Andy Baugh 6 vuotta sitten
vanhempi
sitoutus
4aefdc74e9

+ 10 - 1
lib/Cpanel/iContact/Provider/Schema/Slack.pm

@@ -61,6 +61,10 @@ Slack Incoming Webhook URL(s): URL created for sending notifications to the dest
 <br />In order to create an incoming webhook for the channel(s)/user(s) you wish to notify, please go to 'Browse apps > Custom Integrations > Incoming WebHooks > New configuration'
 in Slack's 'App Directory' for your team.
 HALP
+    my $help2 = <<HELP;
+Slack: Use concise notifications (Subject Only) -- If true, will discard the message body before send in order to make the message a bit more compact.
+In the future this may provide a link back to WHM in order to display the full notification.
+HELP
     return {
         'CONTACTSLACK' => {
             'name'     => 'Slack',
@@ -78,7 +82,12 @@ HALP
             },
             'label' => 'Slack Incoming Webhook URL(s)',
             'help'  => $help,
-        }
+        },
+        'SLACKCOMPACT' => {
+            'type'     => 'binary',
+            'label' => 'Slack: Use concise notifications (Subject Only)',
+            'help' => $help2,
+        },
     };
 }
 

+ 5 - 6
lib/Cpanel/iContact/Provider/Slack.pm

@@ -68,12 +68,11 @@ sub send {
     my $message = ${ $args_hr->{'text_body'} };
 
     require Cpanel::AdminBin::Serializer;
-    my $message_json = Cpanel::AdminBin::Serializer::Dump(
-        {
-            'text'        => $subject,
-            'attachments' => [ { "text" => $message } ],
-        }
-    );
+    my $dump_hr = {
+        'text'        => $subject,
+    };
+    $dump_hr->{'attachments'} = [ { "text" => $message } ] if !$contact_hr->{'SLACKCOMPACT'};
+    my $message_json = Cpanel::AdminBin::Serializer::Dump($dump_hr);
 
     # Send it
     foreach my $destination ( @{ $args_hr->{'to'} } ) {

+ 1 - 1
t/Cpanel-iContact-Provider-Schema-Slack.t

@@ -13,7 +13,7 @@ use Cpanel::iContact::Provider::Schema::Slack ();
 plan tests => 2;
 
 subtest "Settings getter method performs as expected" => sub {
-    my $model = [ 'CONTACTSLACK' ];
+    my $model = [ 'CONTACTSLACK', 'SLACKCOMPACT' ];
     my $settings = Cpanel::iContact::Provider::Schema::Slack::get_settings();
     is_deeply( [ sort keys( %{$settings} ) ], $model, "Settings returned look OK so far" );
     foreach my $key (@$model) {