mirror of
https://github.com/tiennm99/coolify.git
synced 2026-10-20 02:17:09 +00:00
feat(notifications): add mattermost notifications (#7963)
This commit is contained in:
1 parent
fbacf7076e
commit
51301fd12e
1 file changed
+50
@@ -22,6 +22,36 @@ class SendMessageToSlackJob implements ShouldQueue
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function handle(): void
|
public function handle(): void
|
||||||
|
{
|
||||||
|
if ($this->isSlackWebhook()) {
|
||||||
|
$this->sendToSlack();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This works with Mattermost and as a fallback also with Slack, the notifications just look slightly different and advanced formatting for slack is not supported with Mattermost.
|
||||||
|
*
|
||||||
|
* @see https://github.com/coollabsio/coolify/pull/6139#issuecomment-3756777708
|
||||||
|
*/
|
||||||
|
$this->sendToMattermost();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function isSlackWebhook(): bool
|
||||||
|
{
|
||||||
|
$parsedUrl = parse_url($this->webhookUrl);
|
||||||
|
|
||||||
|
if ($parsedUrl === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$scheme = $parsedUrl['scheme'] ?? '';
|
||||||
|
$host = $parsedUrl['host'] ?? '';
|
||||||
|
|
||||||
|
return $scheme === 'https' && $host === 'hooks.slack.com';
|
||||||
|
}
|
||||||
|
|
||||||
|
private function sendToSlack(): void
|
||||||
{
|
{
|
||||||
Http::post($this->webhookUrl, [
|
Http::post($this->webhookUrl, [
|
||||||
'text' => $this->message->title,
|
'text' => $this->message->title,
|
||||||
@@ -57,4 +87,24 @@ class SendMessageToSlackJob implements ShouldQueue
|
|||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @todo v5 refactor: Extract this into a separate SendMessageToMattermostJob.php triggered via the "mattermost" notification channel type.
|
||||||
|
*/
|
||||||
|
private function sendToMattermost(): void
|
||||||
|
{
|
||||||
|
$username = config('app.name');
|
||||||
|
|
||||||
|
Http::post($this->webhookUrl, [
|
||||||
|
'username' => $username,
|
||||||
|
'attachments' => [
|
||||||
|
[
|
||||||
|
'title' => $this->message->title,
|
||||||
|
'color' => $this->message->color,
|
||||||
|
'text' => $this->message->description,
|
||||||
|
'footer' => $username,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user