From 5347ddcdb0ce3a443ea0c3f019cd0fb2173d75db Mon Sep 17 00:00:00 2001 From: kyle Date: Sun, 14 Jun 2026 00:21:48 -0700 Subject: [PATCH] feat(talk): replace text type prefixes with emojis in messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Extract `typeIcon` from mapped data in `WebhookController` and pass to `prependDisplayName` - Update `TalkService.prependDisplayName` to accept optional `$typeIcon` parameter and prepend it to the display name line - Remove text-based type labels (`[Info]`, `[Success]`, `[Warning]`, `[Error]`) and replace with emoji icons (`✅`, `⚠️`, `❌`) - Include `typeIcon` in the message payload array returned by `TalkService` --- lib/Controller/WebhookController.php | 3 ++- lib/Service/TalkService.php | 31 ++++++++++++++-------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/lib/Controller/WebhookController.php b/lib/Controller/WebhookController.php index c400caf..580fd1c 100644 --- a/lib/Controller/WebhookController.php +++ b/lib/Controller/WebhookController.php @@ -473,7 +473,8 @@ class WebhookController extends Controller { // Prepend display name since Talk doesn't support per-message avatars $displayName = $mapped['displayName'] ?? $senderName; - $message = $this->talkService->prependDisplayName($displayName, $mapped['message']); + $typeIcon = $mapped['typeIcon'] ?? ''; + $message = $this->talkService->prependDisplayName($displayName, $mapped['message'], $typeIcon); // Post to Talk via Chat API $success = $this->talkService->postToRoom($roomToken, $message, $senderName, $richObjects); diff --git a/lib/Service/TalkService.php b/lib/Service/TalkService.php index bdb4cf0..1894448 100644 --- a/lib/Service/TalkService.php +++ b/lib/Service/TalkService.php @@ -598,8 +598,9 @@ class TalkService { * 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 . '**'; + public function prependDisplayName(string $displayName, string $message, string $typeIcon = ''): string { + $icon = $typeIcon !== '' ? $typeIcon . ' ' : ''; + $nameLine = $icon . '🤖 **' . $displayName . '**'; if ($message === '') { return $nameLine; } @@ -752,23 +753,11 @@ class TalkService { 'senderName' => $senderName, 'displayName' => $displayName, 'richObjects' => $richObjects, + 'typeIcon' => '', ]; } } - // Type prefix for context (e.g. "[Warning]") - if (!empty($data['type'])) { - $typeLabels = [ - 'info' => '[Info]', - 'success' => '[Success]', - 'warning' => '[Warning]', - 'error' => '[Error]', - ]; - if (isset($typeLabels[$data['type']])) { - array_unshift($parts, $typeLabels[$data['type']]); - } - } - $message = implode("\n\n", $parts); // If body is empty but we have a title/subject, use it as the message @@ -882,11 +871,23 @@ class TalkService { } } + // Determine type icon for the sender line (empty for info/image) + $typeIcon = ''; + if (!empty($data['type'])) { + $typeIcons = [ + 'success' => '✅', + 'warning' => '⚠️', + 'error' => '❌', + ]; + $typeIcon = $typeIcons[$data['type']] ?? ''; + } + return [ 'message' => $message, 'senderName' => $senderName, 'displayName' => $displayName, 'richObjects' => $richObjects, + 'typeIcon' => $typeIcon, ]; }