mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-12 09:52:20 +00:00
Add config for ntfy
This commit is contained in:
@@ -27,11 +27,11 @@ use FireflyIII\Events\Admin\InvitationCreated;
|
||||
use FireflyIII\Events\AdminRequestedTestMessage;
|
||||
use FireflyIII\Events\NewVersionAvailable;
|
||||
use FireflyIII\Events\Test\TestNotificationChannel;
|
||||
use FireflyIII\Notifications\Admin\TestNotification;
|
||||
use FireflyIII\Notifications\Admin\UserInvitation;
|
||||
use FireflyIII\Notifications\Admin\VersionCheckResult;
|
||||
use FireflyIII\Notifications\Test\TestNotificationDiscord;
|
||||
use FireflyIII\Notifications\Test\TestNotificationEmail;
|
||||
use FireflyIII\Notifications\Test\TestNotificationNtfy;
|
||||
use FireflyIII\Notifications\Test\TestNotificationSlack;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
@@ -131,8 +131,8 @@ class AdminEventHandler
|
||||
case 'slack':
|
||||
$class = TestNotificationSlack::class;
|
||||
break;
|
||||
case 'discord':
|
||||
$class = TestNotificationDiscord::class;
|
||||
case 'ntfy':
|
||||
$class = TestNotificationNtfy::class;
|
||||
break;
|
||||
default:
|
||||
app('log')->error(sprintf('Unknown channel "%s" in sendTestNotification method.', $event->channel));
|
||||
|
||||
@@ -42,6 +42,8 @@ class NotificationController extends Controller
|
||||
$subTitleIcon = 'envelope-o';
|
||||
$slackUrl = app('fireflyconfig')->get('slack_webhook_url', '')->data;
|
||||
$channels = config('notifications.channels');
|
||||
$forcedAvailability = [];
|
||||
|
||||
|
||||
|
||||
// admin notification settings:
|
||||
@@ -52,8 +54,18 @@ class NotificationController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
// loop all channels
|
||||
foreach ($channels as $channel => $info) {
|
||||
$forcedAvailability[$channel] = true;
|
||||
}
|
||||
|
||||
return view('admin.notifications.index', compact('title', 'subTitle', 'mainTitleIcon', 'subTitleIcon', 'channels', 'slackUrl', 'notifications'));
|
||||
// validate presence of of Ntfy settings.
|
||||
if('' === (string)config('ntfy-notification-channel.topic')) {
|
||||
Log::warning('No topic name for Ntfy, channel is disabled.');
|
||||
$forcedAvailability['ntfy'] = false;
|
||||
}
|
||||
|
||||
return view('admin.notifications.index', compact('title', 'subTitle', 'forcedAvailability', 'mainTitleIcon', 'subTitleIcon', 'channels', 'slackUrl', 'notifications'));
|
||||
}
|
||||
|
||||
public function postIndex(NotificationRequest $request): RedirectResponse
|
||||
@@ -89,6 +101,7 @@ class NotificationController extends Controller
|
||||
break;
|
||||
case 'email':
|
||||
case 'slack':
|
||||
case 'ntfy':
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
app('log')->debug(sprintf('Now in testNotification("%s") controller.', $channel));
|
||||
|
||||
@@ -1,114 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* TestNotification.php
|
||||
* Copyright (c) 2022 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Notifications\Admin;
|
||||
|
||||
use FireflyIII\Support\Notifications\UrlValidator;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Messages\SlackMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
/**
|
||||
* Class TestNotification
|
||||
*/
|
||||
class TestNotification extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
private string $address;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*/
|
||||
public function __construct(string $address)
|
||||
{
|
||||
$this->address = $address;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($notifiable)
|
||||
{
|
||||
return [
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*
|
||||
* @return MailMessage
|
||||
*/
|
||||
public function toMail($notifiable)
|
||||
{
|
||||
return (new MailMessage())
|
||||
->markdown('emails.admin-test', ['email' => $this->address])
|
||||
->subject((string)trans('email.admin_test_subject'))
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Slack representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*
|
||||
* @return SlackMessage
|
||||
*/
|
||||
public function toSlack($notifiable)
|
||||
{
|
||||
return (new SlackMessage())->content((string)trans('email.admin_test_subject'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function via($notifiable)
|
||||
{
|
||||
$slackUrl = app('fireflyconfig')->get('slack_webhook_url', '')->data;
|
||||
if (UrlValidator::isValidWebhookURL($slackUrl)) {
|
||||
return ['mail', 'slack'];
|
||||
}
|
||||
|
||||
return ['mail'];
|
||||
}
|
||||
}
|
||||
@@ -28,11 +28,15 @@ use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Messages\SlackMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Ntfy\Message;
|
||||
use Wijourdil\NtfyNotificationChannel\Channels\NtfyChannel;
|
||||
|
||||
//use Illuminate\Notifications\Slack\SlackMessage;
|
||||
|
||||
/**
|
||||
* Class TestNotification
|
||||
*/
|
||||
class TestNotificationDiscord extends Notification
|
||||
class TestNotificationNtfy extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
@@ -61,6 +65,18 @@ class TestNotificationDiscord extends Notification
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function toNtfy(mixed $notifiable): Message
|
||||
{
|
||||
$message = new Message();
|
||||
$message->topic(config('ntfy-notification-channel.topic'));
|
||||
$message->title((string)trans('email.admin_test_subject'));
|
||||
$message->body((string)trans('email.admin_test_message', ['channel' => 'ntfy']));
|
||||
$message->tags(['white_check_mark', 'ok_hand']);
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*
|
||||
@@ -83,13 +99,6 @@ class TestNotificationDiscord extends Notification
|
||||
*
|
||||
*/
|
||||
public function toSlack($notifiable) {
|
||||
|
||||
// since it's an admin notificaiton, grab the URL from fireflyconfig
|
||||
$url = app('fireflyconfig')->get('discord_webhook_url', '')->data;
|
||||
|
||||
return (new SlackMessage())
|
||||
->content((string)trans('email.admin_test_subject'))
|
||||
->to($url);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -103,6 +112,6 @@ class TestNotificationDiscord extends Notification
|
||||
*/
|
||||
public function via($notifiable)
|
||||
{
|
||||
return ['slack'];
|
||||
return [NtfyChannel::class];
|
||||
}
|
||||
}
|
||||
@@ -50,7 +50,6 @@ use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\UserGroup;
|
||||
use FireflyIII\Models\UserRole;
|
||||
use FireflyIII\Models\Webhook;
|
||||
use FireflyIII\Notifications\Admin\TestNotification;
|
||||
use FireflyIII\Notifications\Admin\UserInvitation;
|
||||
use FireflyIII\Notifications\Admin\UserRegistration;
|
||||
use FireflyIII\Notifications\Admin\VersionCheckResult;
|
||||
|
||||
Reference in New Issue
Block a user