From: Vincent Vanwaelscappel Date: Mon, 21 Nov 2022 17:03:55 +0000 (+0100) Subject: wait #5587 @4 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=1bdc7436f487b06e44e851761935330c33e000a6;p=fluidbook-toolbox.git wait #5587 @4 --- diff --git a/app/Jobs/DownloadBase.php b/app/Jobs/DownloadBase.php index 2856fda1e..030bea9e7 100644 --- a/app/Jobs/DownloadBase.php +++ b/app/Jobs/DownloadBase.php @@ -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 = []) diff --git a/app/Slack/Slack.php b/app/Slack/Slack.php index eade79785..b9890d4d2 100644 --- a/app/Slack/Slack.php +++ b/app/Slack/Slack.php @@ -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; } diff --git a/config/logging.php b/config/logging.php index a20402898..ddf84c02c 100644 --- a/config/logging.php +++ b/config/logging.php @@ -37,7 +37,7 @@ return [ 'channels' => [ 'stack' => [ 'driver' => 'stack', - 'channels' => ['daily'], + 'channels' => ['daily', 'stderr','slack'], 'ignore_exceptions' => false, ],