-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
439 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace App\Jobs; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldBeEncrypted; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
use Illuminate\Support\Facades\Http; | ||
|
||
class SendMessageToSlackJob implements ShouldBeEncrypted, ShouldQueue | ||
{ | ||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
|
||
/** | ||
* The number of times the job may be attempted. | ||
* | ||
* @var int | ||
*/ | ||
public $tries = 5; | ||
|
||
public $backoff = 10; | ||
|
||
/** | ||
* The maximum number of unhandled exceptions to allow before failing. | ||
*/ | ||
public int $maxExceptions = 5; | ||
|
||
public function __construct( | ||
public string $text, | ||
public string $webhookUrl | ||
) { | ||
} | ||
|
||
/** | ||
* Execute the job. | ||
*/ | ||
public function handle(): void | ||
{ | ||
$payload = [ | ||
'text' => $this->text, | ||
]; | ||
Http::post($this->webhookUrl, $payload); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
namespace App\Livewire\Notifications; | ||
|
||
use App\Models\Team; | ||
use App\Notifications\Test; | ||
use Livewire\Component; | ||
|
||
class Slack extends Component | ||
{ | ||
public Team $team; | ||
|
||
protected $rules = [ | ||
'team.slack_enabled' => 'nullable|boolean', | ||
'team.slack_webhook_url' => 'required|url', | ||
'team.slack_notifications_test' => 'nullable|boolean', | ||
'team.slack_notifications_deployments' => 'nullable|boolean', | ||
'team.slack_notifications_status_changes' => 'nullable|boolean', | ||
'team.slack_notifications_database_backups' => 'nullable|boolean', | ||
'team.slack_notifications_scheduled_tasks' => 'nullable|boolean', | ||
]; | ||
|
||
protected $validationAttributes = [ | ||
'team.slack_webhook_url' => 'Slack Web API', | ||
]; | ||
|
||
public function mount() | ||
{ | ||
$this->team = auth()->user()->currentTeam(); | ||
} | ||
|
||
public function instantSave() | ||
{ | ||
try { | ||
$this->submit(); | ||
} catch (\Throwable $e) { | ||
ray($e->getMessage()); | ||
$this->team->slack_enabled = false; | ||
$this->validate(); | ||
} | ||
} | ||
|
||
public function submit() | ||
{ | ||
$this->resetErrorBag(); | ||
$this->validate(); | ||
$this->saveModel(); | ||
} | ||
|
||
public function saveModel() | ||
{ | ||
$this->team->save(); | ||
refreshSession(); | ||
$this->dispatch('success', 'Settings saved.'); | ||
} | ||
|
||
public function sendTestNotification() | ||
{ | ||
$this->team?->notify(new Test()); | ||
$this->dispatch('success', 'Test notification sent.'); | ||
} | ||
|
||
public function render() | ||
{ | ||
return view('livewire.notifications.slack'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace App\Notifications\Channels; | ||
|
||
interface SendsSlack | ||
{ | ||
public function routeNotificationForSlack(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace App\Notifications\Channels; | ||
|
||
use App\Jobs\SendMessageToSlackJob; | ||
use Illuminate\Notifications\Notification; | ||
|
||
class SlackChannel | ||
{ | ||
/** | ||
* Send the given notification. | ||
*/ | ||
public function send(SendsSlack $notifiable, Notification $notification): void | ||
{ | ||
$message = $notification->toSlack($notifiable); | ||
$webhookUrl = $notifiable->routeNotificationForSlack(); | ||
if (! $webhookUrl) { | ||
return; | ||
} | ||
dispatch(new SendMessageToSlackJob($message, $webhookUrl)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.