add channel gibt es erst ab version 2
This commit is contained in:
parent
c0b4908373
commit
3a6befa283
11
extend.php
11
extend.php
|
|
@ -5,25 +5,22 @@ declare(strict_types=1);
|
||||||
use Flarum\Extend;
|
use Flarum\Extend;
|
||||||
use SbpJm\FlarumMSTeamsWebhook\Console\TestTeamsUserCommand;
|
use SbpJm\FlarumMSTeamsWebhook\Console\TestTeamsUserCommand;
|
||||||
use SbpJm\FlarumMSTeamsWebhook\Listener\MirrorAlertsToTeams;
|
use SbpJm\FlarumMSTeamsWebhook\Listener\MirrorAlertsToTeams;
|
||||||
use SbpJm\FlarumMSTeamsWebhook\Notification\TeamsChannel;
|
use SbpJm\FlarumMSTeamsWebhook\Notification\TeamsDriver;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
// Localization
|
|
||||||
(new Extend\Locales(__DIR__ . '/locale')),
|
(new Extend\Locales(__DIR__ . '/locale')),
|
||||||
|
|
||||||
// Admin frontend (settings UI)
|
|
||||||
(new Extend\Frontend('admin'))
|
(new Extend\Frontend('admin'))
|
||||||
->js(__DIR__ . '/js/dist/admin.js'),
|
->js(__DIR__ . '/js/dist/admin.js'),
|
||||||
|
|
||||||
// CLI test command
|
|
||||||
(new Extend\Console())
|
(new Extend\Console())
|
||||||
->command(TestTeamsUserCommand::class),
|
->command(TestTeamsUserCommand::class),
|
||||||
|
|
||||||
// Existing hook (leave it intact)
|
// ✅ EXISTING hook (unchanged)
|
||||||
(new Extend\Notification())
|
(new Extend\Notification())
|
||||||
->beforeSending(MirrorAlertsToTeams::class),
|
->beforeSending(MirrorAlertsToTeams::class),
|
||||||
|
|
||||||
// ✅ NEW: Microsoft Teams notification channel
|
// ✅ NEW: Microsoft Teams notification driver
|
||||||
(new Extend\Notification())
|
(new Extend\Notification())
|
||||||
->addChannel(TeamsChannel::class),
|
->driver('teams', TeamsDriver::class),
|
||||||
];
|
];
|
||||||
|
|
@ -2,3 +2,6 @@ sbp-jm-msteams-webhook:
|
||||||
admin:
|
admin:
|
||||||
title: MS Teams Activity Feed
|
title: MS Teams Activity Feed
|
||||||
description: Mirror Flarum web notifications to Microsoft Teams.
|
description: Mirror Flarum web notifications to Microsoft Teams.
|
||||||
|
notification:
|
||||||
|
drivers:
|
||||||
|
teams: Microsoft Teams
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace SbpJm\FlarumMSTeamsWebhook\Notification;
|
||||||
|
|
||||||
|
use Flarum\Notification\Blueprint\BlueprintInterface;
|
||||||
|
use Flarum\Notification\Driver\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 go to Teams.
|
||||||
|
*/
|
||||||
|
protected function supports(BlueprintInterface $blueprint): bool
|
||||||
|
{
|
||||||
|
return in_array($blueprint::getType(), [
|
||||||
|
'newPost',
|
||||||
|
'postMentioned',
|
||||||
|
'userMentioned',
|
||||||
|
'discussionRenamed',
|
||||||
|
'postLiked',
|
||||||
|
], true);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue