This commit is contained in:
JM 2026-05-05 17:33:04 +02:00
parent 685ca83aaf
commit a8cda75f03
1 changed files with 18 additions and 13 deletions

View File

@ -19,35 +19,39 @@ class NotificationPayloadFactory
/** /**
* Build the payload for Microsoft Teams Activity Feed. * Build the payload for Microsoft Teams Activity Feed.
* *
* Informational only (systemDefault). * Informational notification that opens the Teams app side pane
* No clickable navigation from the Activity Feed is expected. * and marks the activity item as read.
* *
* @return array<string, mixed> * @return array<string, mixed>
*/ */
public function make(User $recipient, BlueprintInterface $blueprint): array public function make(User $recipient, BlueprintInterface $blueprint): array
{ {
// Activity Feed is informational only // Activity Feed type (informational, but clickable via /l/entity)
$activityType = 'systemDefault'; $activityType = 'systemDefault';
$forumName = trim((string) $this->settings->get('forum_title', 'Flarum')) ?: 'Flarum'; $forumName = trim((string) $this->settings->get('forum_title', 'sbp forum')) ?: 'sbp forum';
// Resolve dynamic data // Resolve dynamic data
$discussionTitle = $this->resolveDiscussionTitle($blueprint) ?? $forumName; $discussionTitle = $this->resolveDiscussionTitle($blueprint) ?? $forumName;
$discussionUrl = $this->resolveSubjectUrl($blueprint)
?? rtrim((string) $this->settings->get('sbp-jm-msteams-webhook.forum_base_url', ''), '/');
$previewSnippet = $this->buildPreviewText($blueprint); $previewSnippet = $this->buildPreviewText($blueprint);
$reasonText = $this->buildReasonTextEn($blueprint); $reasonText = $this->buildReasonTextEn($blueprint);
// Teams requires /l/ URLs for topic.source = text // Teams App + Personal Tab (THIS is what makes it clickable & read)
// /l/browser is the official, neutral deep link for external pages $teamsAppId = 'd92b1be6-ea92-46b1-bcb0-c08ffdd1a61a';
$teamsBrowserLink = 'https://teams.microsoft.com/l/browser/' . rawurlencode($discussionUrl); $teamsEntityId = '8ffe419f-ca44-4627-a4b2-f223da2d07aa';
// Opens the app side pane and marks the activity as read
$teamsTabLink = sprintf(
'https://teams.microsoft.com/l/entity/%s/%s',
$teamsAppId,
$teamsEntityId
);
return [ return [
'topic' => [ 'topic' => [
'source' => 'text', 'source' => 'text',
'value' => $discussionTitle, 'value' => $discussionTitle,
'webUrl' => $teamsBrowserLink, 'webUrl' => $teamsTabLink,
], ],
'activityType' => $activityType, 'activityType' => $activityType,
'previewText' => [ 'previewText' => [
@ -82,6 +86,7 @@ class NotificationPayloadFactory
/** /**
* Resolve the URL to the discussion or specific post. * Resolve the URL to the discussion or specific post.
* (Not used for navigation in Teams, but kept for completeness.)
*/ */
protected function resolveSubjectUrl(BlueprintInterface $blueprint): ?string protected function resolveSubjectUrl(BlueprintInterface $blueprint): ?string
{ {
@ -113,7 +118,7 @@ class NotificationPayloadFactory
} }
/** /**
* English reason text for Activity Feed (systemDefault). * English reason text for Activity Feed.
*/ */
protected function buildReasonTextEn(BlueprintInterface $blueprint): string protected function buildReasonTextEn(BlueprintInterface $blueprint): string
{ {
@ -166,4 +171,4 @@ class NotificationPayloadFactory
return mb_substr($text, 0, 150); return mb_substr($text, 0, 150);
} }
} }