]> _ Git - fluidbook-toolbox.git/commitdiff
wait #5587 @4
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 21 Nov 2022 17:03:55 +0000 (18:03 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 21 Nov 2022 17:03:55 +0000 (18:03 +0100)
app/Jobs/DownloadBase.php
app/Slack/Slack.php
config/logging.php

index 2856fda1ef427c235566f862b2ab98d0628272c2..030bea9e7e8112867d43d97d6d104ec37130b054 100644 (file)
@@ -12,6 +12,7 @@ use Cubist\Util\Files\Files;
 use Cubist\Util\Str;
 use Cubist\Util\Zip;
 use GrahamCampbell\Markdown\Facades\Markdown;
+use Illuminate\Support\Facades\Log;
 use Illuminate\Support\Facades\Mail;
 use JoliCode\Slack\ClientFactory;
 use League\CommonMark\CommonMarkConverter;
@@ -50,15 +51,18 @@ class DownloadBase extends Base
     public function sendNotification($subject, $text, $actions = [])
     {
         if ($this->getUser()->slack) {
-            $this->sendSlack($subject, $text, $actions);
-        } else {
-            $this->sendEmail($subject, $text, $actions);
+            if ($this->sendSlack($subject, $text, $actions)) {
+                return;
+            }
         }
+
+        // Fallback email if
+        $this->sendEmail($subject, $text, $actions);
     }
 
     public function sendSlack($subject, $text, $actions = [])
     {
-        Slack::send($this->getUser()->slack, $subject, $text, $actions);
+        return Slack::send($this->getUser()->slack, $subject, $text, $actions);
     }
 
     public function sendEmail($subject, $text, $actions = [])
index eade79785935cda7353c87dc32452d1ebf2f8cfb..b9890d4d267aa2db9d5bcfef7b8ea8f3b6452204 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace App\Slack;
 
+use Illuminate\Support\Facades\Log;
 use JoliCode\Slack\ClientFactory;
 
 class Slack
@@ -44,6 +45,8 @@ class Slack
                 ]
             ];
         }
+        $actionTexts = [];
+        $actionsText = '';
         $actionsCount = count($actions);
         if ($actionsCount > 0) {
             $a = [
@@ -51,7 +54,7 @@ class Slack
                 'block_id' => 'actions',
                 'elements' => [],
             ];
-            $text = '';
+            $actionsText = '';
             $i = 0;
             foreach ($actions as $label => $data) {
                 if (is_string($data)) {
@@ -67,31 +70,43 @@ class Slack
                     ], $data);
                 }
                 if ($repeatActions) {
-                    $text .= '> ' . $label . ' : ' . $data['url'] . "\n";
+                    if (mb_strlen($actionsText) > 2800) {
+                        $actionsTexts[] = $actionsText;
+                        $actionsText = '';
+                    }
+                    $actionsText .= '> ' . $label . ' : ' . $data['url'] . "\n";
                 }
                 $i++;
             }
-            if ($text) {
+            if ($actionsText !== '') {
+                $actionsTexts[] = $actionsText;
+            }
+            foreach ($actionsTexts as $actionsText) {
                 $blocks[] = [
                     'type' => 'section',
                     'text' => [
                         'type' => 'mrkdwn',
-                        'text' => $text,
+                        'text' => $actionsText,
                     ]
                 ];
             }
             $blocks[] = $a;
         }
 
-        $response = self::_client()->chatPostMessage([
-            'username' => $from,
-            'channel' => $channel,
-            'blocks' => json_encode($blocks),
-            'text' => $subject,
-            'unfurl_links' => false,
-        ]);
-        if ($response->getOk()) {
-            return $response->getTs();
+        try {
+            $blocks = json_encode($blocks);
+            $response = self::_client()->chatPostMessage([
+                'username' => $from,
+                'channel' => $channel,
+                'blocks' => $blocks,
+                'text' => $subject,
+                'unfurl_links' => false,
+            ]);
+            if ($response->getOk()) {
+                return $response->getTs();
+            }
+        } catch (\Exception $e) {
+            Log::critical($e->getMessage() . ' // ' . $from . ' // ' . $channel . ' // ' . $text . ' // ' . $blocks);
         }
         return false;
     }
index a20402898ca79afb96916c27be61ac99b976ceb6..ddf84c02cd8b2ed98246f2ed9b4aea0d70c78f9d 100644 (file)
@@ -37,7 +37,7 @@ return [
     'channels' => [
         'stack' => [
             'driver' => 'stack',
-            'channels' => ['daily'],
+            'channels' => ['daily', 'stderr','slack'],
             'ignore_exceptions' => false,
         ],