Cross-platform mobile notifications for Node.js via Telegram Bot, Bark and Ntfy.
Zero runtime dependencies. One simple API. Multiple mobile notification channels.
中文:pushpal 是一个 Node-first 的轻量级 JavaScript 通知 SDK,用统一 API 向 Telegram Bot、Bark 和 Ntfy 发送移动端通知。
npm install pushpalRequirements:
- Node.js >= 18
- ESM or CommonJS
- No runtime dependencies
import { PushPal } from "pushpal";
const client = new PushPal();
const results = await client.ntfy(
{ topic: "my-alerts" },
{
title: "Deploy complete",
body: "v0.3 is live",
},
);
console.log(results);await client.telegram(
{ token: "BOT_TOKEN", chatId: "123456" },
{
title: "Server alert",
body: "CPU usage is above 90%",
url: "https://example.com/runbook",
buttonText: "View runbook",
},
);await client.bark(
{ deviceKey: "YOUR_DEVICE_KEY" },
{
title: "Reminder",
body: "Drink water",
level: "timeSensitive",
sound: "minuet",
},
);For a private Bark server:
await client.bark(
{ serverUrl: "https://bark.example.com", deviceKey: "YOUR_DEVICE_KEY" },
{ title: "Hello", body: "From pushpal" },
);await client.ntfy(
{ topic: "ops-alerts" },
{
title: "Deploy complete",
body: "v0.3 is live",
priority: 4,
tags: ["white_check_mark"],
},
);With private Ntfy auth:
await client.ntfy(
{
serverUrl: "https://ntfy.example.com",
topic: "ops",
auth: { type: "bearer", token: "tk_xxxxxxxx" },
},
{ title: "Alert", body: "Disk space is low" },
);Group sends the common message fields (title, body, url) to every configured channel.
await client.group(
{
telegram: { token: "BOT_TOKEN", chatId: "123456" },
bark: { deviceKey: "YOUR_DEVICE_KEY" },
ntfy: { topic: "ops-alerts" },
},
{
title: "Incident",
body: "Production database connection failed",
url: "https://monitor.example.com",
},
);Configure retry and timeout globally:
const client = new PushPal({
retry: 2,
timeout: 5000,
});Override them per message:
await client.ntfy(
{ topic: "ops-alerts" },
{
title: "Alert",
body: "Retry this send",
retry: 3,
timeout: 2000,
},
);retryis the number of retry attempts after the first failed request.timeoutis measured in milliseconds.- Network and timeout failures are returned as
SendResultfailures instead of being thrown.
All send methods return Promise<SendResult[]>.
interface SendResult {
channel: "telegram" | "bark" | "ntfy";
target: string;
ok: boolean;
status?: number;
data?: unknown;
error?: string;
}Target values are safe for logs:
- Telegram tokens are never returned.
- Bark device keys are masked, for example
bark:key:abcd...wxyz. - Ntfy auth credentials are never returned.
Input errors throw TypeError before sending:
- Missing
titleor invalidbody - Missing Telegram
tokenorchatId - Missing Bark
deviceKey - Missing Ntfy
topic - Invalid
retryortimeout
Send errors return SendResult objects with ok: false:
- Network failures
- Timeout failures
- HTTP non-2xx responses
- Response parsing failures
Do not expose Telegram Bot tokens, Bark device keys, or private Ntfy credentials in browser code.
For browser apps, send notifications through your own backend proxy unless the target topic is intentionally public.
中文提示:不要在前端代码中暴露 Telegram Bot Token、Bark Device Key 或私有 Ntfy 鉴权信息。浏览器应用应通过后端代理发送通知,除非目标 topic 明确是公开的。
Runnable offline examples are in examples/.
npm run build
node examples/node-esm.mjs
node examples/node-cjs.cjs
node examples/telegram.mjs
node examples/bark.mjs
node examples/ntfy.mjs
node examples/group.mjs
node examples/retry-timeout.mjsThe examples use mock fetch functions so they do not send real notifications.
import { PushPal } from "pushpal";
const client = new PushPal({
retry: 2,
timeout: 5000,
});
await client.group(
{
telegram: { token: "BOT_TOKEN", chatId: "123456" },
bark: { deviceKey: "YOUR_DEVICE_KEY" },
ntfy: { topic: "ops-alerts" },
},
{
title: "紧急通知",
body: "生产数据库连接失败,请立即处理",
url: "https://monitor.example.com",
},
);MIT