für settings mit ms teams notify
This commit is contained in:
parent
e79b38442b
commit
c0b4908373
|
|
@ -5,16 +5,25 @@ declare(strict_types=1);
|
|||
use Flarum\Extend;
|
||||
use SbpJm\FlarumMSTeamsWebhook\Console\TestTeamsUserCommand;
|
||||
use SbpJm\FlarumMSTeamsWebhook\Listener\MirrorAlertsToTeams;
|
||||
use SbpJm\FlarumMSTeamsWebhook\Notification\TeamsChannel;
|
||||
|
||||
return [
|
||||
// Localization
|
||||
(new Extend\Locales(__DIR__ . '/locale')),
|
||||
|
||||
// Admin frontend (settings UI)
|
||||
(new Extend\Frontend('admin'))
|
||||
->js(__DIR__ . '/js/dist/admin.js'),
|
||||
|
||||
// CLI test command
|
||||
(new Extend\Console())
|
||||
->command(TestTeamsUserCommand::class),
|
||||
|
||||
// Existing hook (leave it intact)
|
||||
(new Extend\Notification())
|
||||
->beforeSending(MirrorAlertsToTeams::class),
|
||||
|
||||
// ✅ NEW: Microsoft Teams notification channel
|
||||
(new Extend\Notification())
|
||||
->addChannel(TeamsChannel::class),
|
||||
];
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SbpJm\FlarumMSTeamsWebhook\Notification;
|
||||
|
||||
use Flarum\Notification\Blueprint\BlueprintInterface;
|
||||
use Flarum\Notification\Channel\ChannelInterface;
|
||||
use Flarum\User\User;
|
||||
use SbpJm\FlarumMSTeamsWebhook\Support\TeamsNotifier;
|
||||
|
||||
class TeamsChannel implements ChannelInterface
|
||||
{
|
||||
public function __construct(
|
||||
protected TeamsNotifier $notifier
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Called by Flarum when the user has enabled this channel.
|
||||
*/
|
||||
public function send(User $recipient, BlueprintInterface $blueprint): void
|
||||
{
|
||||
// Defensive: only send if supported
|
||||
if (!$this->supports($blueprint)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->notifier->sendToUser($recipient, $blueprint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decide which notification types are allowed for Teams.
|
||||
*/
|
||||
public function supports(BlueprintInterface $blueprint): bool
|
||||
{
|
||||
return in_array($blueprint::getType(), [
|
||||
'newPost',
|
||||
'postMentioned',
|
||||
'userMentioned',
|
||||
'discussionRenamed',
|
||||
'postLiked',
|
||||
], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Channel identifier used internally by Flarum.
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return 'teams';
|
||||
}
|
||||
|
||||
/**
|
||||
* Label shown in the user notification settings UI.
|
||||
*/
|
||||
public function getLabel(): string
|
||||
{
|
||||
return 'Microsoft Teams';
|
||||
}
|
||||
|
||||
/**
|
||||
* Teams is opt‑in by default.
|
||||
*/
|
||||
public function isEnabledByDefault(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue