ntfy
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data β all from the browser, and deployed in milliseconds.
A TypeScript library for sending push notifications via ntfy.sh from Val Town.
import { Ntfy } from "https://esm.town/v/nbbaier/ntfy/index.ts";
// Simple message
await Ntfy.publish("my-topic", "Hello from Val Town! π");
// With options
await Ntfy.publish("my-topic", {
message: "Disk usage at 95%!",
title: "Server Alert",
priority: 5,
tags: ["warning", "skull"],
click: "https://example.com/dashboard",
markdown: true,
});
- Simple API β one-liner to send notifications
- Full ntfy.sh support β title, priority, tags, actions, attachments, markdown, scheduled delivery, email forwarding
- Auth support β token auth, basic auth, or env vars
- Self-hosted support β works with any ntfy server
- TypeScript β fully typed with exported interfaces
For quick notifications to ntfy.sh with no auth:
import { Ntfy } from "https://esm.town/v/nbbaier/ntfy/index.ts";
await Ntfy.publish("my-topic", "Backup complete β
");
import { Ntfy } from "https://esm.town/v/nbbaier/ntfy/index.ts";
const ntfy = new Ntfy({
server: "https://ntfy.myserver.com",
token: "tk_abc123",
});
await ntfy.publish("alerts", {
message: "Deployment finished",
title: "CI/CD",
priority: 4,
tags: ["rocket"],
});
Set a default topic to use notify() without specifying a topic each time:
const ntfy = new Ntfy({ defaultTopic: "my-alerts" });
await ntfy.notify("Something happened!");
// Or use the NTFY_TOPIC environment variable and the static method:
await Ntfy.notify("Something happened!");
await Ntfy.publish("my-topic", {
message: "Garage door open for 15 min",
actions: [
{ action: "view", label: "Open Dashboard", url: "https://home.example.com" },
{ action: "http", label: "Close Door", url: "https://api.example.com/close", method: "PUT" },
{ action: "copy", label: "Copy Code", value: "abc123" },
],
});
import { Ntfy, PriorityName } from "https://esm.town/v/nbbaier/ntfy/index.ts";
await Ntfy.publish("my-topic", {
message: "Critical alert!",
priority: PriorityName.urgent, // 5
});
The library automatically reads these env vars as defaults:
| Variable | Description |
|---|---|
NTFY_SERVER | Server URL (default: https://ntfy.sh) |
NTFY_TOKEN | Access token for auth |
NTFY_USERNAME | Username for basic auth |
NTFY_PASSWORD | Password for basic auth |
NTFY_TOPIC | Default topic for notify() |
interface PublishOptions {
message?: string; // Notification body
title?: string; // Notification title
priority?: 1|2|3|4|5; // 1=min, 3=default, 5=urgent
tags?: string[]; // Emoji shortcodes & tags
click?: string; // URL opened on tap
attach?: string; // Attachment URL
filename?: string; // Attachment filename
delay?: string; // Scheduled delivery
email?: string; // Forward via email
markdown?: boolean; // Enable markdown
actions?: Action[]; // Action buttons
icon?: string; // Notification icon URL
}
import { Ntfy, NtfyError } from "https://esm.town/v/nbbaier/ntfy/index.ts";
try {
await Ntfy.publish("my-topic", "test");
} catch (e) {
if (e instanceof NtfyError) {
console.error(e.statusCode, e.responseBody);
}
}
Rendering mermaid diagram...