flarum-msteams-webhook/src/Notification/TeamsDriver.php

43 lines
1.0 KiB
PHP

<?php
declare(strict_types=1);
namespace SbpJm\FlarumMSTeamsWebhook\Notification;
use Flarum\Notification\Blueprint\BlueprintInterface;
use Flarum\Notification\DriverInterface;
use Flarum\User\User;
use SbpJm\FlarumMSTeamsWebhook\Support\TeamsNotifier;
class TeamsDriver implements DriverInterface
{
public function __construct(
protected TeamsNotifier $notifier
) {}
/**
* Send the notification via Microsoft Teams.
*/
public function send(User $recipient, BlueprintInterface $blueprint): void
{
if (!$this->supports($blueprint)) {
return;
}
$this->notifier->sendToUser($recipient, $blueprint);
}
/**
* Limit which notification types are allowed for Teams.
*/
protected function supports(BlueprintInterface $blueprint): bool
{
return in_array($blueprint::getType(), [
'newPost',
'postMentioned',
'userMentioned',
'discussionRenamed',
'postLiked',
], true);
}
}