Fix ntfy: use JSON body instead of headers to support emoji titles

Sending emoji in HTTP headers is not valid ASCII and causes errors.
Switching to ntfy's JSON body API (POST to /topic with {topic, title,
message, priority, tags}) allows full UTF-8 including emoji.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
nmemmertandClaude Sonnet 4.6 committed 2026-08-06 16:31:44 -04:00
1 parent d46a37a219
commit 279cba5115
2 files changed
+23 -25

No files matched your search

+6 -6
View File
@@ -1566,12 +1566,12 @@ app.post('/api/test-ntfy', async (req, res) => {
if (!ntfy_topic) return res.status(400).json({ error: 'ntfy topic is required' }); if (!ntfy_topic) return res.status(400).json({ error: 'ntfy topic is required' });
const base = (ntfy_url || 'https://ntfy.sh').replace(/\/$/, ''); const base = (ntfy_url || 'https://ntfy.sh').replace(/\/$/, '');
try { try {
await axios.post(`${base}/${ntfy_topic}`, 'This is a test notification from SkyWatch', { await axios.post(`${base}/`, {
headers: { topic: ntfy_topic,
Title: encodeURIComponent('SkyWatch Test'), title: '🔔 SkyWatch Test',
Priority: 'default', message: 'This is a test notification from SkyWatch',
Tags: 'white_check_mark', priority: 3,
}, tags: ['white_check_mark'],
}); });
res.json({ message: 'Test notification sent to ntfy!' }); res.json({ message: 'Test notification sent to ntfy!' });
} catch (error) { } catch (error) {
+17 -19
View File
@@ -179,15 +179,14 @@ class NotificationService {
const ntfyTopic = this.config.ntfy_topic; const ntfyTopic = this.config.ntfy_topic;
if (ntfyTopic) { if (ntfyTopic) {
try { try {
const groupedBody = pendingAlerts.map(({ resource, incident }) => await axios.post(`${ntfyUrl.replace(/\/$/, '')}/`, {
`${incident.type === 'started' ? '[DOWN]' : '[UP]'} ${resource.name}` topic: ntfyTopic,
).join('\n'); title: `⚠️ ${pendingAlerts.length} monitors changed status`,
await axios.post(`${ntfyUrl.replace(/\/$/, '')}/${ntfyTopic}`, groupedBody, { message: pendingAlerts.map(({ resource, incident }) =>
headers: { `${incident.type === 'started' ? '🔴' : '🟢'} ${resource.name}`
Title: encodeURIComponent(`${pendingAlerts.length} monitors changed status`), ).join('\n'),
Priority: 'high', priority: 4,
Tags: 'warning', tags: ['warning'],
},
}); });
} catch (_) {} } catch (_) {}
} }
@@ -454,18 +453,17 @@ class NotificationService {
const isDown = type === 'started'; const isDown = type === 'started';
const isSlow = type === 'slow'; const isSlow = type === 'slow';
const titleText = isDown ? `${resource.name} is DOWN` : isSlow ? `${resource.name} is SLOW` : `${resource.name} is UP`; const title = isDown ? `🔴 ${resource.name} is DOWN` : isSlow ? `🟡 ${resource.name} is SLOW` : `🟢 ${resource.name} is UP`;
const priority = isDown ? 'high' : isSlow ? 'default' : 'low'; const priority = isDown ? 4 : isSlow ? 3 : 2;
const tags = isDown ? 'red_circle,warning' : isSlow ? 'yellow_circle' : 'green_circle,white_check_mark'; const tags = isDown ? ['red_circle', 'warning'] : isSlow ? ['yellow_circle'] : ['green_circle', 'white_check_mark'];
const body = resource.url || resource.name;
try { try {
await axios.post(`${ntfyUrl.replace(/\/$/, '')}/${ntfyTopic}`, body, { await axios.post(`${ntfyUrl.replace(/\/$/, '')}/`, {
headers: { topic: ntfyTopic,
Title: encodeURIComponent(titleText), title,
Priority: priority, message: resource.url || resource.name,
Tags: tags, priority,
}, tags,
}); });
} catch (error) { } catch (error) {
// ntfy error handled silently // ntfy error handled silently