. */ declare(strict_types=1); namespace FireflyIII\Notifications\User; use FireflyIII\Support\Notifications\UrlValidator; use FireflyIII\User; use Illuminate\Bus\Queueable; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Messages\SlackMessage; use Illuminate\Notifications\Notification; /** * Class NewAccessToken */ class NewAccessToken extends Notification { use Queueable; /** * Create a new notification instance. * * @return void */ public function __construct() {} /** * Get the array representation of the notification. * * @param mixed $notifiable * * @return array */ public function toArray($notifiable) { return [ // ]; } /** * Get the mail representation of the notification. * * @param mixed $notifiable * * @return MailMessage */ public function toMail($notifiable) { return (new MailMessage()) ->markdown('emails.token-created') ->subject((string)trans('email.access_token_created_subject')); } /** * Get the Slack representation of the notification. * * @param mixed $notifiable * * @return SlackMessage */ public function toSlack($notifiable) { return (new SlackMessage())->content((string)trans('email.access_token_created_body')); } /** * Get the notification's delivery channels. * * @param mixed $notifiable * * @return array */ public function via($notifiable) { /** @var User|null $user */ $user = auth()->user(); $slackUrl = null === $user ? '' : (string)app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data; if (UrlValidator::isValidWebhookURL($slackUrl)) { return ['mail', 'slack']; } return ['mail']; } }