komujohn/google-chat-notifier

Symfony Google Chat Notifier 桥接器

安装: 40

依赖者: 0

建议者: 0

安全性: 0

星星: 0

关注者: 0

分支: 5

类型:symfony-bridge

v5.2.4 2021-01-15 08:35 UTC

README

为 Symfony Notifier 提供 Google Chat 集成。允许在通知时设置线程键。

DSN 示例

GOOGLE_CHAT_DSN=googlechat://ACCESS_KEY:ACCESS_TOKEN@default/SPACE?thread_key=THREAD_KEY

其中

  • ACCESS_KEY 是您的 Google Chat 访问密钥
  • ACCESS_TOKEN 是您的 Google Chat 访问令牌
  • SPACE 是 Google Chat 空间
  • THREAD_KEY 是将消息分组到单个消息线程的 Google Chat 消息线程(可选)

代码示例

<?php
namespace App\Service;

use Symfony\Component\Notifier\Bridge\GoogleChat\ThreadNotification;
use Symfony\Component\Notifier\Notification\Notification;
use Symfony\Component\Notifier\NotifierInterface;
use Symfony\Component\Notifier\Recipient\NoRecipient;


class NotificationHelper {

    private NotifierInterface $notifier;

    public function __construct( NotifierInterface $notifier ) {
        $this->notifier    = $notifier;
    }
    public function sendNotification($subject,$message,$thread_key='general5'){
        $notification = (new ThreadNotification())
            ->subject($subject)
            ->content($message)
            ->thread($thread_key)
            ->importance(Notification::IMPORTANCE_HIGH);

        $this->notifier->send($notification, new NoRecipient());
    }

}

资源