feat: improve Apprise notification subject/title handling and fallbacks
- lib/Controller/WebhookController.php: Extract subject/title from wrapper level and add fallback to default sender name - lib/Service/TalkService.php: Update display name logic to check subject, and use title/subject as message body when empty
This commit is contained in:
@@ -233,7 +233,20 @@ class WebhookController extends Controller {
|
||||
|
||||
// Apprise API wraps notifications in a "notifications" array
|
||||
if (isset($data['notifications']) && is_array($data['notifications']) && !empty($data['notifications'])) {
|
||||
$wrapper = $data;
|
||||
$data = $data['notifications'][0];
|
||||
// Some Apprise versions put subject/title at the wrapper level
|
||||
if (empty($data['subject']) && !empty($wrapper['subject'])) {
|
||||
$data['subject'] = $wrapper['subject'];
|
||||
}
|
||||
if (empty($data['title']) && !empty($wrapper['title'])) {
|
||||
$data['title'] = $wrapper['title'];
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: if no subject/title anywhere, use config default
|
||||
if (empty($data['subject']) && empty($data['title'])) {
|
||||
$data['subject'] = $this->talkService->getSenderNameDefault();
|
||||
}
|
||||
|
||||
// Map apprise format to our internal payload format
|
||||
|
||||
@@ -587,8 +587,10 @@ class TalkService {
|
||||
public function mapApprisePayload(array $data, string $roomToken = ''): array {
|
||||
$parts = [];
|
||||
|
||||
// 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');
|
||||
// Display name: use Apprise title/subject (source/app name) as the display name
|
||||
$displayName = !empty($data['title']) ? $data['title']
|
||||
: (!empty($data['subject']) ? $data['subject']
|
||||
: $this->config->getAppValue(self::APP_ID, 'sender_name', 'Webhook Bot'));
|
||||
|
||||
// Body
|
||||
if (!empty($data['body'])) {
|
||||
@@ -658,6 +660,16 @@ class TalkService {
|
||||
|
||||
$message = implode("\n\n", $parts);
|
||||
|
||||
// If body is empty but we have a title/subject, use it as the message
|
||||
// (handles test notifications and simple alerts with no body)
|
||||
if ($message === '') {
|
||||
if (!empty($data['title'])) {
|
||||
$message = $data['title'];
|
||||
} elseif (!empty($data['subject'])) {
|
||||
$message = $data['subject'];
|
||||
}
|
||||
}
|
||||
|
||||
// Sender name: use app name if available, otherwise default
|
||||
$senderName = $displayName;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user