mikaelkael/ntfy-notifier

Symfony Ntfy Notifier Bridge

Installs: 145

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 0

Open Issues: 0

Type:symfony-notifier-bridge

v2.1.0 2024-08-31 15:08 UTC

This package is auto-updated.

Last update: 2024-12-01 00:11:29 UTC


README

Build Status License

Provides Ntfy integration for Symfony Notifier. The component should be introduced in Symfony 6.4 with this PR #50131. This bundle provides same functionalities for Symfony 5.4.x to 6.3.x.

DSN example

# .env
NTFY_DSN=ntfy://[USER:PASSWORD]@default[:PORT]/TOPIC?[secureHttp=[on]]

where:

  • URL is the ntfy server which you are using
    • if default is provided, this will default to the public ntfy server hosted on ntfy.sh.
  • TOPIC is the topic on this ntfy server.
  • PORT is an optional specific port.
  • USERand PASSWORD are username and password in case of access control supported by the server

In case of a non-secure server, you can disable https by setting secureHttp=off.

Enable texter

# config/packages/notifier.yaml
framework:
    notifier:
        texter_transports:
            nfty: '%env(NTFY_DSN)%'

Send push message

// src/Controller/TestController.php
namespace App\Controller;

use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Component\Notifier\TexterInterface;
use Symfony\Component\Routing\Annotation\Route;

class TestController
{
    /**
     * @Route("/test")
     */
    public function test(TexterInterface $texter)
    {
        $pushMessage = new PushMessage(
            'Title',
            'Message content',
            new NtfyOptions(['tags' => ['warning'], 'priority' => 5])
        );
        $result = $texter->send($pushMessage);

        // ...
    }
}