Skip to content

Commit

Permalink
Add support for mattermost webhook
Browse files Browse the repository at this point in the history
  • Loading branch information
Universal-Omega authored Sep 6, 2024
1 parent 24fc20e commit b330f78
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 10 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ MEDIAWIKI_BASE=https://meta.miraheze.org
ALERT_EMAIL=null

DISCORD_WEBHOOK=null
MATTERMOST_WEBHOOK=null
WEB_PROXY=null

SESSION_DRIVER=file
Expand Down
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
TSPortal follows a basic numerical increase system for releases and not Semantic Versioning.
The main reasoning behind this choice is the software is not built to be extended upon, therefore no stable public API exists.

## [Unreleased](https://github.com/miraheze/TSPortal/compare/v19...master)
## [Unreleased](https://github.com/miraheze/TSPortal/compare/v20...master)

## Version 20 (2024-09-07)

### Added

- Implement support for mattermost webhook notifications.

## Version 19 (2024-08-26)

Expand Down
2 changes: 1 addition & 1 deletion app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ class Kernel extends ConsoleKernel
*/
protected function schedule( Schedule $schedule )
{
$schedule->call( new IALScheduler() )->dailyAt( '00:00' )->description( 'Daily Discord Disgest for IAL' );
$schedule->call( new IALScheduler() )->dailyAt( '00:00' )->description( 'Daily Webhook Disgest for IAL' );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Illuminate\Support\Facades\Http;

class SendDiscordNotification
class SendWebhookNotification
{
/**
* Create the event listener.
Expand Down Expand Up @@ -38,5 +38,14 @@ public function handle( $event )
] );
}
}

if ( config( 'app.mattermosthook' ) ) {
$text = 'New ' . $event->name . ' has been ' . $event->state . '. Link: ' . config( 'app.url' ) . '/' . strtolower( $event->name ) . '/' . $event->model->id;

Http::post( config( 'app.mattermosthook' ), [
'text' => $text,
'username' => 'TSPortal',
] );
}
}
}
10 changes: 5 additions & 5 deletions app/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use App\Events\InvestigationClosed;
use App\Events\InvestigationNew;
use App\Events\ReportNew;
use App\Listeners\SendDiscordNotification;
use App\Listeners\SendWebhookNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;

class EventServiceProvider extends ServiceProvider
Expand All @@ -17,10 +17,10 @@ class EventServiceProvider extends ServiceProvider
* @var array
*/
protected $listen = [
DPANew::class => [ SendDiscordNotification::class ],
InvestigationNew::class => [ SendDiscordNotification::class ],
InvestigationClosed::class => [ SendDiscordNotification::class ],
ReportNew::class => [ SendDiscordNotification::class ]
DPANew::class => [ SendWebhookNotification::class ],
InvestigationNew::class => [ SendWebhookNotification::class ],
InvestigationClosed::class => [ SendWebhookNotification::class ],
ReportNew::class => [ SendWebhookNotification::class ]
];

/**
Expand Down
9 changes: 8 additions & 1 deletion app/Schedules/IALScheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private function getRecentIALs(): array
}

/**
* Creates a message for Discord based on recent IALs
* Creates a webhook message based on recent IALs
*
* @param array $recentIALs
*
Expand Down Expand Up @@ -119,5 +119,12 @@ public function notify( string $message )
] );
}
}

if ( config( 'app.mattermosthook' ) ) {
Http::post( config( 'app.mattermosthook' ), [
'text' => $message,
'username' => 'TSPortal',
] );
}
}
}
12 changes: 11 additions & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
|
*/

'version' => 19,
'version' => 20,

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -383,6 +383,16 @@
*/
'discordhook' => env( 'DISCORD_WEBHOOK' ),

/*
|--------------------------------------------------------------------------
| Mattermost Webhook
|--------------------------------------------------------------------------
|
| Where to send mattermost alerts for new models and major actions.
|
*/
'mattermosthook' => env( 'MATTERMOST_WEBHOOK' ),

/*
|--------------------------------------------------------------------------
| Web Proxy
Expand Down

0 comments on commit b330f78

Please sign in to comment.