diff --git a/lib/Controller/WebhookController.php b/lib/Controller/WebhookController.php index cccc55b..ad24c34 100644 --- a/lib/Controller/WebhookController.php +++ b/lib/Controller/WebhookController.php @@ -88,6 +88,8 @@ class WebhookController extends Controller { } $senderName = $this->talkService->getSenderName($data); + // Prepend display name since Talk doesn't support per-message avatars + $message = $this->talkService->prependDisplayName($senderName, $message); // Handle images $richObjects = []; @@ -249,8 +251,12 @@ class WebhookController extends Controller { $senderName = $mapped['senderName'] ?? $this->talkService->getSenderNameDefault(); $richObjects = $mapped['richObjects'] ?? []; + // Prepend display name since Talk doesn't support per-message avatars + $displayName = $mapped['displayName'] ?? $senderName; + $message = $this->talkService->prependDisplayName($displayName, $mapped['message']); + // Post to Talk via Chat API - $success = $this->talkService->postToRoom($roomToken, $mapped['message'], $senderName, $richObjects); + $success = $this->talkService->postToRoom($roomToken, $message, $senderName, $richObjects); if ($success) { $this->logger->info('NCdiscordhook: apprise webhook processed successfully', [ diff --git a/lib/Service/TalkService.php b/lib/Service/TalkService.php index 12423e0..852cf73 100644 --- a/lib/Service/TalkService.php +++ b/lib/Service/TalkService.php @@ -512,6 +512,18 @@ class TalkService { /** * Map Discord webhook payload to Talk message text. */ + /** + * Prepend a display name line to a message. + * Since Talk doesn't support per-message avatars, we embed the name in the message. + */ + public function prependDisplayName(string $displayName, string $message): string { + $nameLine = '🤖 **' . $displayName . '**'; + if ($message === '') { + return $nameLine; + } + return $nameLine . "\n\n" . $message; + } + public function mapPayload(array $data): string { $parts = []; @@ -575,10 +587,8 @@ class TalkService { public function mapApprisePayload(array $data, string $roomToken = ''): array { $parts = []; - // Title (if present) - if (!empty($data['title'])) { - $parts[] = '**' . $data['title'] . '**'; - } + // Display name: use Apprise title (source/app name) as the display name + $displayName = !empty($data['title']) ? $data['title'] : $this->config->getAppValue(self::APP_ID, 'sender_name', 'Webhook Bot'); // Body if (!empty($data['body'])) { @@ -604,11 +614,11 @@ class TalkService { if (!empty($imageUrls)) { // Use title as message if body is empty if (empty($data['body'])) { - $message = !empty($data['title']) ? '**' . $data['title'] . '**' : ''; + $message = !empty($data['title']) ? $data['title'] : ''; } else { $message = implode("\n\n", $parts); } - $senderName = $this->config->getAppValue(self::APP_ID, 'sender_name', 'Webhook Bot'); + $senderName = $displayName; $richObjects = []; foreach ($imageUrls as $imageUrl) { $imageData = $this->downloadImage($imageUrl); @@ -627,6 +637,7 @@ class TalkService { return [ 'message' => $message, 'senderName' => $senderName, + 'displayName' => $displayName, 'richObjects' => $richObjects, ]; } @@ -648,7 +659,7 @@ class TalkService { $message = implode("\n\n", $parts); // Sender name: use app name if available, otherwise default - $senderName = $this->config->getAppValue(self::APP_ID, 'sender_name', 'Webhook Bot'); + $senderName = $displayName; // Handle attachments: download files and upload to Talk $richObjects = []; @@ -700,6 +711,7 @@ class TalkService { return [ 'message' => $message, 'senderName' => $senderName, + 'displayName' => $displayName, 'richObjects' => $richObjects, ]; }