alles mögliche verbessert
This commit is contained in:
parent
2913b64648
commit
9924f19bc3
|
|
@ -19,38 +19,39 @@ class NotificationPayloadFactory
|
|||
/**
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
public function make(User $recipient, BlueprintInterface $blueprint): array
|
||||
{
|
||||
$activityType = trim((string) $this->settings->get('sbp-jm-msteams-webhook.activity_type', 'systemDefault'));
|
||||
$forumName = trim((string) $this->settings->get('forum_title', 'Flarum')) ?: 'Flarum';
|
||||
$topicUrl = $this->resolveSubjectUrl($blueprint) ?? rtrim((string) $this->settings->get('sbp-jm-msteams-webhook.forum_base_url', ''), '/');
|
||||
$previewText = $this->buildPreviewText($blueprint);
|
||||
$teamsAppId = trim((string) $this->settings->get('sbp-jm-msteams-webhook.teams_app_id', ''));
|
||||
$iconId = trim((string) $this->settings->get('sbp-jm-msteams-webhook.icon_id', ''));
|
||||
/**
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
public function make(User $recipient, BlueprintInterface $blueprint): array
|
||||
{
|
||||
$activityType = trim((string) $this->settings->get('sbp-jm-msteams-webhook.activity_type', 'systemDefault'));
|
||||
$forumName = trim((string) $this->settings->get('forum_title', 'Flarum')) ?: 'Flarum';
|
||||
$iconId = trim((string) $this->settings->get('sbp-jm-msteams-webhook.icon_id', ''));
|
||||
|
||||
$discussionTitle = 'Backup-Strategie für Forum';
|
||||
$discussionUrl = 'https://forum.sbp.de/d/34-which-file-extensions-are-allowed-for-uploads/2';
|
||||
$previewSnippet = 'Bitte prüft, ob wir tägliche Snapshots brauchen.';
|
||||
$reasonText = 'Neue Antwort in beobachteter Diskussion';
|
||||
// Diskussionstitel + URL dynamisch aus dem Subject ziehen
|
||||
$discussionTitle = $this->resolveDiscussionTitle($blueprint) ?? $forumName;
|
||||
$discussionUrl = $this->resolveSubjectUrl($blueprint) ?? 'https://forum.sbp.de';
|
||||
$previewSnippet = $this->buildPreviewText($blueprint);
|
||||
|
||||
|
||||
$discussionTitle = 'Backup-Strategie für Forum';
|
||||
$discussionUrl = 'https://forum.sbp.de/d/34-which-file-extensions-are-allowed-for-uploads/2';
|
||||
$previewSnippet = 'Bitte prüft, ob wir tägliche Snapshots brauchen.';
|
||||
$reasonText = 'Neue Antwort in beobachteter Diskussion';
|
||||
// Freie Actor+Reason-Zeile für systemDefault
|
||||
$reasonText = match ($blueprint::getType()) {
|
||||
'newPost' => 'Neue Antwort in beobachteter Diskussion',
|
||||
'postMentioned' => 'Du wurdest in einem Beitrag erwähnt',
|
||||
'userMentioned' => 'Du wurdest erwähnt',
|
||||
'postLiked' => 'Dein Beitrag wurde geliked',
|
||||
default => 'Neue Flarum-Benachrichtigung',
|
||||
};
|
||||
|
||||
// Teams-App-/Tab-Ziel aus deinem aktuellen Manifest
|
||||
$teamsManifestAppId = 'd92b1be6-ea92-46b1-bcb0-c08ffdd1a61a';
|
||||
$teamsEntityId = '8ffe419f-ca44-4627-a4b2-f223da2d07aa';
|
||||
|
||||
// Kontext für den Tab: die Diskussion wird in subPageId transportiert.
|
||||
// Microsoft dokumentiert page.subPageId als den Kontextwert für eine Unterseite.
|
||||
// Diskussion in den Tab-Kontext schreiben
|
||||
$contextJson = json_encode([
|
||||
'subPageId' => $discussionUrl,
|
||||
], JSON_UNESCAPED_SLASHES);
|
||||
|
||||
// Deep Link auf den Personal Tab.
|
||||
// webUrl ist der Fallback (z. B. Browser-Fallback), context transportiert die Diskussion.
|
||||
// Teams-Deep-Link auf den Personal Tab
|
||||
$teamsDeepLink = sprintf(
|
||||
'https://teams.microsoft.com/l/entity/%s/%s?webUrl=%s&label=%s&context=%s',
|
||||
rawurlencode($teamsManifestAppId),
|
||||
|
|
@ -66,9 +67,9 @@ class NotificationPayloadFactory
|
|||
'value' => $discussionTitle,
|
||||
'webUrl' => $teamsDeepLink,
|
||||
],
|
||||
'activityType' => 'systemDefault',
|
||||
'activityType' => $activityType !== '' ? $activityType : 'systemDefault',
|
||||
'previewText' => [
|
||||
'content' => $previewSnippet,
|
||||
'content' => mb_substr($previewSnippet, 0, 150),
|
||||
],
|
||||
'templateParameters' => [
|
||||
[
|
||||
|
|
@ -78,28 +79,21 @@ class NotificationPayloadFactory
|
|||
],
|
||||
];
|
||||
|
||||
if ($iconId !== '') {
|
||||
$payload['iconId'] = $iconId;
|
||||
}
|
||||
|
||||
if (($payload['activityType'] ?? 'systemDefault') !== 'systemDefault') {
|
||||
$payload['templateParameters'] = [
|
||||
[
|
||||
'name' => 'notificationText',
|
||||
'value' => mb_substr($previewSnippet, 0, 150),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
// if ($teamsAppId !== '') {
|
||||
// $payload['teamsAppId'] = $teamsAppId;
|
||||
// }
|
||||
|
||||
if ($iconId !== '') {
|
||||
$payload['iconId'] = $iconId;
|
||||
}
|
||||
|
||||
if (($payload['activityType'] ?? 'systemDefault') !== 'systemDefault') {
|
||||
$payload['templateParameters'] = [
|
||||
[
|
||||
'name' => 'notificationText',
|
||||
'value' => $previewText,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
return $payload;
|
||||
}
|
||||
|
||||
return $payload;
|
||||
}
|
||||
protected function buildPreviewText(BlueprintInterface $blueprint): string
|
||||
{
|
||||
if ($blueprint::getType() === 'teamsTest') {
|
||||
|
|
@ -134,6 +128,21 @@ class NotificationPayloadFactory
|
|||
return mb_substr($text, 0, 150);
|
||||
}
|
||||
|
||||
|
||||
protected function resolveDiscussionTitle(BlueprintInterface $blueprint): ?string
|
||||
{
|
||||
$subject = $blueprint->getSubject();
|
||||
|
||||
if ($subject instanceof Discussion) {
|
||||
return (string) $subject->title;
|
||||
}
|
||||
|
||||
if ($subject instanceof Post && $subject->discussion) {
|
||||
return (string) $subject->discussion->title;
|
||||
}
|
||||
|
||||
return
|
||||
|
||||
protected function resolveSubjectUrl(BlueprintInterface $blueprint): ?string
|
||||
{
|
||||
$baseUrl = rtrim((string) $this->settings->get('sbp-jm-msteams-webhook.forum_base_url', ''), '/');
|
||||
|
|
|
|||
Loading…
Reference in New Issue