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;
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 = [])
namespace App\Slack;
+use Illuminate\Support\Facades\Log;
use JoliCode\Slack\ClientFactory;
class Slack
]
];
}
+ $actionTexts = [];
+ $actionsText = '';
$actionsCount = count($actions);
if ($actionsCount > 0) {
$a = [
'block_id' => 'actions',
'elements' => [],
];
- $text = '';
+ $actionsText = '';
$i = 0;
foreach ($actions as $label => $data) {
if (is_string($data)) {
], $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;
}
'channels' => [
'stack' => [
'driver' => 'stack',
- 'channels' => ['daily'],
+ 'channels' => ['daily', 'stderr','slack'],
'ignore_exceptions' => false,
],