feat(talk): prepend display name to messages
- Add `prependDisplayName` method to `TalkService` to format the name line - Update `WebhookController` to prepend display name for Talk messages - Update `mapApprisePayload` to extract and pass display name from Apprise title or config - Add `displayName` to return array in `mapApprisePayload`
This commit is contained in:
@@ -88,6 +88,8 @@ class WebhookController extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$senderName = $this->talkService->getSenderName($data);
|
$senderName = $this->talkService->getSenderName($data);
|
||||||
|
// Prepend display name since Talk doesn't support per-message avatars
|
||||||
|
$message = $this->talkService->prependDisplayName($senderName, $message);
|
||||||
|
|
||||||
// Handle images
|
// Handle images
|
||||||
$richObjects = [];
|
$richObjects = [];
|
||||||
@@ -249,8 +251,12 @@ class WebhookController extends Controller {
|
|||||||
$senderName = $mapped['senderName'] ?? $this->talkService->getSenderNameDefault();
|
$senderName = $mapped['senderName'] ?? $this->talkService->getSenderNameDefault();
|
||||||
$richObjects = $mapped['richObjects'] ?? [];
|
$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
|
// 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) {
|
if ($success) {
|
||||||
$this->logger->info('NCdiscordhook: apprise webhook processed successfully', [
|
$this->logger->info('NCdiscordhook: apprise webhook processed successfully', [
|
||||||
|
|||||||
@@ -512,6 +512,18 @@ class TalkService {
|
|||||||
/**
|
/**
|
||||||
* Map Discord webhook payload to Talk message text.
|
* 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 {
|
public function mapPayload(array $data): string {
|
||||||
$parts = [];
|
$parts = [];
|
||||||
|
|
||||||
@@ -575,10 +587,8 @@ class TalkService {
|
|||||||
public function mapApprisePayload(array $data, string $roomToken = ''): array {
|
public function mapApprisePayload(array $data, string $roomToken = ''): array {
|
||||||
$parts = [];
|
$parts = [];
|
||||||
|
|
||||||
// Title (if present)
|
// Display name: use Apprise title (source/app name) as the display name
|
||||||
if (!empty($data['title'])) {
|
$displayName = !empty($data['title']) ? $data['title'] : $this->config->getAppValue(self::APP_ID, 'sender_name', 'Webhook Bot');
|
||||||
$parts[] = '**' . $data['title'] . '**';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Body
|
// Body
|
||||||
if (!empty($data['body'])) {
|
if (!empty($data['body'])) {
|
||||||
@@ -604,11 +614,11 @@ class TalkService {
|
|||||||
if (!empty($imageUrls)) {
|
if (!empty($imageUrls)) {
|
||||||
// Use title as message if body is empty
|
// Use title as message if body is empty
|
||||||
if (empty($data['body'])) {
|
if (empty($data['body'])) {
|
||||||
$message = !empty($data['title']) ? '**' . $data['title'] . '**' : '';
|
$message = !empty($data['title']) ? $data['title'] : '';
|
||||||
} else {
|
} else {
|
||||||
$message = implode("\n\n", $parts);
|
$message = implode("\n\n", $parts);
|
||||||
}
|
}
|
||||||
$senderName = $this->config->getAppValue(self::APP_ID, 'sender_name', 'Webhook Bot');
|
$senderName = $displayName;
|
||||||
$richObjects = [];
|
$richObjects = [];
|
||||||
foreach ($imageUrls as $imageUrl) {
|
foreach ($imageUrls as $imageUrl) {
|
||||||
$imageData = $this->downloadImage($imageUrl);
|
$imageData = $this->downloadImage($imageUrl);
|
||||||
@@ -627,6 +637,7 @@ class TalkService {
|
|||||||
return [
|
return [
|
||||||
'message' => $message,
|
'message' => $message,
|
||||||
'senderName' => $senderName,
|
'senderName' => $senderName,
|
||||||
|
'displayName' => $displayName,
|
||||||
'richObjects' => $richObjects,
|
'richObjects' => $richObjects,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -648,7 +659,7 @@ class TalkService {
|
|||||||
$message = implode("\n\n", $parts);
|
$message = implode("\n\n", $parts);
|
||||||
|
|
||||||
// Sender name: use app name if available, otherwise default
|
// 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
|
// Handle attachments: download files and upload to Talk
|
||||||
$richObjects = [];
|
$richObjects = [];
|
||||||
@@ -700,6 +711,7 @@ class TalkService {
|
|||||||
return [
|
return [
|
||||||
'message' => $message,
|
'message' => $message,
|
||||||
'senderName' => $senderName,
|
'senderName' => $senderName,
|
||||||
|
'displayName' => $displayName,
|
||||||
'richObjects' => $richObjects,
|
'richObjects' => $richObjects,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user