secit-pl/signal-notifier-bundle

Symfony Notifier 信号支持。

1.0.1 2021-01-20 23:03 UTC

This package is not auto-updated.

Last update: 2024-09-22 01:44:05 UTC


README

Symfony Notifier 5.1+ 的信号支持。

此包将 signal-cli 包装到 symfony 通知传输中。为了使其工作,您需要能够执行 signal-cli 命令。

安装

从命令行运行

$ composer require secit-pl/signal-notifier-bundle

配置

首先,您应该正确设置 signal-cli。如果它正在运行,您就可以继续了。

config/packages/notifier.yaml

framework:
    notifier:
        texter_transports:
            signal: '%env(SIGNAL_DSN)%' # add Signal support
        channel_policy:
            urgent: ['sms/signal'] # setup it for specified channel
            high: ['email']
            medium: ['email']
            low: ['email']

.env

使用以下格式配置 Signal DSN

SIGNAL_DSN=signal://localhost?cli=SIGNAL_CLI_PATH&user=USER_NAME

请记住正确编码电话号码。加号应编码为 %2b,因此电话号码 +481234567890 应写作 %2b481234567890!

例如

SIGNAL_DSN=signal://localhost?cli=/usr/local/Cellar/signal-cli/0.6.8/bin/signal-cli&user=%2b48123456789

用法

您现在可以使用 Symfony Notifier 发送 signal 消息。

如果您想直接使用 Singal 传输发送消息,可以这样做

<?php

declare(strict_types=1);

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Component\Notifier\TexterInterface;
use Symfony\Component\Routing\Annotation\Route;

class IndexController extends AbstractController
{
    /**
     * @Route("/")
     */
    public function index(TexterInterface $texter)
    {
        $texter->send((new SmsMessage(
            '+481234567890',
            'Hello :)'
        ))->transport('signal'));

        // ...
    }
}