@classytic/notifications 2.4.0 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -0
- package/README.md +20 -0
- package/dist/channels/index.d.mts +2 -2
- package/dist/channels/index.mjs +2 -2
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +28 -4
- package/dist/{status-webhook-CuCdFeVN.d.mts → status-webhook-C8WnLIMv.d.mts} +1 -1
- package/dist/{push.channel-BkgxUc82.mjs → telegram.channel-B2qKQEkV.mjs} +108 -1
- package/dist/{push.channel-1tNMyaXl.d.mts → telegram.channel-CqFwP-3Y.d.mts} +15 -2
- package/dist/{types-DkFudalo.d.mts → types-DsRpYKr-.d.mts} +18 -1
- package/dist/utils/index.d.mts +2 -2
- package/package.json +118 -117
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,42 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to `@classytic/notifications` will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [2.6.0] — 2026-10-09
|
|
6
|
+
|
|
7
|
+
### Added — `TelegramChannel`
|
|
8
|
+
|
|
9
|
+
A Bot API channel over native `fetch`, no dependency. Sends to `recipient.telegramChatId`
|
|
10
|
+
(new optional field on `Recipient`), else the channel's default `chatId`. Text comes from
|
|
11
|
+
`data.text` / `data.message` / `data.subject`, like `SmsChannel`, with the same `canSend`
|
|
12
|
+
pre-check, so a payload with no destination or no text is skipped before it spends a
|
|
13
|
+
rate-limit token.
|
|
14
|
+
|
|
15
|
+
Failures are classified: a Bot API refusal (bad token, unknown chat, bot removed) returns
|
|
16
|
+
`failed` with `retryable: false`; 429, 5xx and network errors throw a `ChannelError`, which
|
|
17
|
+
the service retries. The token is part of the request URL, so no error message includes the
|
|
18
|
+
URL. `providerMessageId` is Telegram's `message_id`.
|
|
19
|
+
|
|
20
|
+
## [2.5.0] — 2026-08-26
|
|
21
|
+
|
|
22
|
+
### Fixed — send-failure log now walks the `cause` chain
|
|
23
|
+
|
|
24
|
+
A real incident — `"Unsupported state or unable to authenticate data"` logged six
|
|
25
|
+
times per order with no frame, no layer — took an afternoon to trace because the
|
|
26
|
+
delivery log and the logger both recorded only `err.message`. Several components in
|
|
27
|
+
the path decrypt something, so the message fit all of them equally.
|
|
28
|
+
|
|
29
|
+
The fix splits the two concerns:
|
|
30
|
+
|
|
31
|
+
- **`result.error`** (persisted, operator-facing) — still the bare message. A stack
|
|
32
|
+
in an audit record is noise; raw vendor text in a persisted field violates the
|
|
33
|
+
house rule on normalised stored errors.
|
|
34
|
+
- **`logger.error`** — now walks the `cause` chain (up to depth 4) and appends the
|
|
35
|
+
first four stack frames of each `Error` node. An adapter that wraps a provider
|
|
36
|
+
error puts the real origin in `cause`; printing only the outer message hid the
|
|
37
|
+
layer you actually needed.
|
|
38
|
+
|
|
39
|
+
The split is covered by `tests/send-failure-diagnostics.test.ts`.
|
|
40
|
+
|
|
5
41
|
## [2.4.0] - 2026-08-17
|
|
6
42
|
|
|
7
43
|
### Fixed — `providerMessageId` now works the way 2.3.0 claimed
|
package/README.md
CHANGED
|
@@ -236,6 +236,26 @@ const snsSms = new SmsChannel({
|
|
|
236
236
|
});
|
|
237
237
|
```
|
|
238
238
|
|
|
239
|
+
### TelegramChannel
|
|
240
|
+
|
|
241
|
+
Bot API over `fetch`, no SDK. Messages go to `recipient.telegramChatId`, else the channel's
|
|
242
|
+
default `chatId` (usually a team group), so it suits a team's own alerts.
|
|
243
|
+
|
|
244
|
+
```typescript
|
|
245
|
+
import { TelegramChannel } from '@classytic/notifications/channels';
|
|
246
|
+
|
|
247
|
+
new TelegramChannel({
|
|
248
|
+
botToken: process.env.TELEGRAM_BOT_TOKEN!, // from @BotFather
|
|
249
|
+
chatId: process.env.TELEGRAM_CHAT_ID!, // e.g. -1001234567890 for a group
|
|
250
|
+
events: ['order.placed'],
|
|
251
|
+
parseMode: 'HTML', // optional
|
|
252
|
+
});
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
Text comes from `data.text`, `data.message` or `data.subject`. A refusal (bad token,
|
|
256
|
+
unknown chat, bot removed from the group) fails without retry; a rate limit, a server
|
|
257
|
+
error or a network failure is retried. The token never appears in an error.
|
|
258
|
+
|
|
239
259
|
### PushChannel (BYOP)
|
|
240
260
|
|
|
241
261
|
Zero dependencies — bring your own push SDK.
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
export { BaseChannel, ConsoleChannel, EmailChannel, PushChannel, SmsChannel, WebhookChannel };
|
|
1
|
+
import { a as WebhookChannel, i as ConsoleChannel, n as PushChannel, o as EmailChannel, r as SmsChannel, s as BaseChannel, t as TelegramChannel } from "../telegram.channel-CqFwP-3Y.mjs";
|
|
2
|
+
export { BaseChannel, ConsoleChannel, EmailChannel, PushChannel, SmsChannel, TelegramChannel, WebhookChannel };
|
package/dist/channels/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as WebhookChannel, i as ConsoleChannel, n as PushChannel, o as EmailChannel, r as SmsChannel, s as BaseChannel, t as TelegramChannel } from "../telegram.channel-B2qKQEkV.mjs";
|
|
2
2
|
|
|
3
|
-
export { BaseChannel, ConsoleChannel, EmailChannel, PushChannel, SmsChannel, WebhookChannel };
|
|
3
|
+
export { BaseChannel, ConsoleChannel, EmailChannel, PushChannel, SmsChannel, TelegramChannel, WebhookChannel };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
import { a as
|
|
3
|
-
import { C as resolveRetryConfig, S as calculateDelay, T as mergeHooks, _ as isQuietHours, a as createStatusHandler, b as ProviderNotInstalledError, c as InterpolateOptions, d as TemplateMap, f as createSimpleResolver, g as QuietHoursConfig, h as pMap, i as StatusUpdate, l as SimpleResolverOptions, m as PMapOptions, n as StatusHandler, o as FallbackOptions, p as interpolateHtml, r as StatusHandlerConfig, s as withFallback, t as DeliveryStatus, u as TemplateDefinition, v as ChannelError, w as withRetry, x as Emitter, y as NotificationError } from "./status-webhook-
|
|
1
|
+
import { A as TemplateResolver, B as DeliveryLogEntry, C as RetryConfig, D as SmsProvider, E as SmsChannelConfig, F as QueueEnqueueOptions, G as MemoryIdempotencyStore, H as MemoryDeliveryLog, I as QueueJob, J as RateLimitStore, K as MemoryRateLimitStore, L as QueueJobStatus, M as WebhookChannelConfig, N as MemoryQueue, O as SmtpTransportOptions, P as QueueAdapter, R as QueueProcessor, S as ResolvedRetryConfig, T as ServiceEvent, U as IDEMPOTENCY_DEFAULT_TTL, V as DeliveryLogQuery, W as IdempotencyStore, _ as NotificationServiceConfig, a as ChannelConfig, b as PushProvider, c as EmailChannelConfig, d as HookMap, f as Logger, g as NotificationPreferences, h as NotificationPayload, i as Channel, j as TemplateResult, k as TelegramChannelConfig, l as EventHandler, m as NotificationHookConfig, n as BatchProgress, o as DispatchResult, p as NodemailerTransporter, q as RateLimitConfig, r as BatchResult, s as EmailAttachment, t as BatchOptions, u as HookHandler, v as PreferenceResolver, w as SendResult, x as Recipient, y as PushChannelConfig, z as DeliveryLog } from "./types-DsRpYKr-.mjs";
|
|
2
|
+
import { a as WebhookChannel, i as ConsoleChannel, n as PushChannel, o as EmailChannel, r as SmsChannel, s as BaseChannel, t as TelegramChannel } from "./telegram.channel-CqFwP-3Y.mjs";
|
|
3
|
+
import { C as resolveRetryConfig, S as calculateDelay, T as mergeHooks, _ as isQuietHours, a as createStatusHandler, b as ProviderNotInstalledError, c as InterpolateOptions, d as TemplateMap, f as createSimpleResolver, g as QuietHoursConfig, h as pMap, i as StatusUpdate, l as SimpleResolverOptions, m as PMapOptions, n as StatusHandler, o as FallbackOptions, p as interpolateHtml, r as StatusHandlerConfig, s as withFallback, t as DeliveryStatus, u as TemplateDefinition, v as ChannelError, w as withRetry, x as Emitter, y as NotificationError } from "./status-webhook-C8WnLIMv.mjs";
|
|
4
4
|
//#region src/NotificationService.d.ts
|
|
5
5
|
declare class NotificationService {
|
|
6
6
|
private channels;
|
|
@@ -133,4 +133,4 @@ declare class NotificationService {
|
|
|
133
133
|
off(event: ServiceEvent, handler: EventHandler): this;
|
|
134
134
|
}
|
|
135
135
|
//#endregion
|
|
136
|
-
export { BaseChannel, type BatchOptions, type BatchProgress, type BatchResult, type Channel, type ChannelConfig, ChannelError, ConsoleChannel, type DeliveryLog, type DeliveryLogEntry, type DeliveryLogQuery, type DeliveryStatus, type DispatchResult, type EmailAttachment, EmailChannel, type EmailChannelConfig, Emitter, type EventHandler, type FallbackOptions, type HookHandler, type HookMap, IDEMPOTENCY_DEFAULT_TTL, type IdempotencyStore, type InterpolateOptions, type Logger, MemoryDeliveryLog, MemoryIdempotencyStore, MemoryQueue, MemoryRateLimitStore, type NodemailerTransporter, NotificationError, type NotificationHookConfig, type NotificationPayload, type NotificationPreferences, NotificationService, type NotificationServiceConfig, type PMapOptions, type PreferenceResolver, ProviderNotInstalledError, PushChannel, type PushChannelConfig, type PushProvider, type QueueAdapter, type QueueEnqueueOptions, type QueueJob, type QueueJobStatus, type QueueProcessor, type QuietHoursConfig, type RateLimitConfig, type RateLimitStore, type Recipient, type ResolvedRetryConfig, type RetryConfig, type SendResult, type ServiceEvent, type SimpleResolverOptions, SmsChannel, type SmsChannelConfig, type SmsProvider, type SmtpTransportOptions, type StatusHandler, type StatusHandlerConfig, type StatusUpdate, type TemplateDefinition, type TemplateMap, type TemplateResolver, type TemplateResult, WebhookChannel, type WebhookChannelConfig, calculateDelay, createSimpleResolver, createStatusHandler, interpolateHtml, isQuietHours, mergeHooks, pMap, resolveRetryConfig, withFallback, withRetry };
|
|
136
|
+
export { BaseChannel, type BatchOptions, type BatchProgress, type BatchResult, type Channel, type ChannelConfig, ChannelError, ConsoleChannel, type DeliveryLog, type DeliveryLogEntry, type DeliveryLogQuery, type DeliveryStatus, type DispatchResult, type EmailAttachment, EmailChannel, type EmailChannelConfig, Emitter, type EventHandler, type FallbackOptions, type HookHandler, type HookMap, IDEMPOTENCY_DEFAULT_TTL, type IdempotencyStore, type InterpolateOptions, type Logger, MemoryDeliveryLog, MemoryIdempotencyStore, MemoryQueue, MemoryRateLimitStore, type NodemailerTransporter, NotificationError, type NotificationHookConfig, type NotificationPayload, type NotificationPreferences, NotificationService, type NotificationServiceConfig, type PMapOptions, type PreferenceResolver, ProviderNotInstalledError, PushChannel, type PushChannelConfig, type PushProvider, type QueueAdapter, type QueueEnqueueOptions, type QueueJob, type QueueJobStatus, type QueueProcessor, type QuietHoursConfig, type RateLimitConfig, type RateLimitStore, type Recipient, type ResolvedRetryConfig, type RetryConfig, type SendResult, type ServiceEvent, type SimpleResolverOptions, SmsChannel, type SmsChannelConfig, type SmsProvider, type SmtpTransportOptions, type StatusHandler, type StatusHandlerConfig, type StatusUpdate, TelegramChannel, type TelegramChannelConfig, type TemplateDefinition, type TemplateMap, type TemplateResolver, type TemplateResult, WebhookChannel, type WebhookChannelConfig, calculateDelay, createSimpleResolver, createStatusHandler, interpolateHtml, isQuietHours, mergeHooks, pMap, resolveRetryConfig, withFallback, withRetry };
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as MemoryQueue, c as pMap, d as MemoryIdempotencyStore, f as isQuietHours, g as Emitter, h as withRetry, i as interpolateHtml, l as MemoryRateLimitStore, m as resolveRetryConfig, n as withFallback, o as MemoryDeliveryLog, p as calculateDelay, r as createSimpleResolver, s as mergeHooks, t as createStatusHandler, u as IDEMPOTENCY_DEFAULT_TTL } from "./status-webhook-B4Sv8X_G.mjs";
|
|
2
2
|
import { n as NotificationError, r as ProviderNotInstalledError, t as ChannelError } from "./errors-BxRjct-E.mjs";
|
|
3
|
-
import { a as
|
|
3
|
+
import { a as WebhookChannel, i as ConsoleChannel, n as PushChannel, o as EmailChannel, r as SmsChannel, s as BaseChannel, t as TelegramChannel } from "./telegram.channel-B2qKQEkV.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/NotificationService.ts
|
|
6
6
|
/**
|
|
@@ -324,7 +324,31 @@ var NotificationService = class {
|
|
|
324
324
|
duration: Date.now() - start
|
|
325
325
|
};
|
|
326
326
|
const message = err instanceof Error ? err.message : String(err);
|
|
327
|
-
|
|
327
|
+
/**
|
|
328
|
+
* Log the ORIGIN, persist only the message.
|
|
329
|
+
*
|
|
330
|
+
* The returned `error` string is what ends up in the delivery log, which
|
|
331
|
+
* is an operator-facing audit record — a raw stack there would be noise
|
|
332
|
+
* at best and leak vendor internals at worst. But a bare message is not
|
|
333
|
+
* diagnosable either: `"Unsupported state or unable to authenticate
|
|
334
|
+
* data"` (Node's AES-GCM failure) took an afternoon to trace precisely
|
|
335
|
+
* because the delivery row recorded that string and nothing else — no
|
|
336
|
+
* frame, no cause, no indication of which of several decrypting layers
|
|
337
|
+
* produced it, and the message never reached a log at all beyond this
|
|
338
|
+
* one line.
|
|
339
|
+
*
|
|
340
|
+
* So the split follows the house rule: normalise what is stored, and log
|
|
341
|
+
* the detail separately. `cause` is walked because an adapter that wraps
|
|
342
|
+
* a provider error puts the real origin there, and printing only the
|
|
343
|
+
* outer message hides exactly the layer you need.
|
|
344
|
+
*/
|
|
345
|
+
const detail = [];
|
|
346
|
+
let cursor = err;
|
|
347
|
+
for (let depth = 0; cursor instanceof Error && depth < 4; depth++) {
|
|
348
|
+
detail.push(`${depth === 0 ? "error" : `cause[${depth}]`}: ${cursor.name}: ${cursor.message}` + (cursor.stack ? `\n${cursor.stack.split("\n").slice(1, 5).join("\n")}` : ""));
|
|
349
|
+
cursor = cursor.cause;
|
|
350
|
+
}
|
|
351
|
+
this.logger.error(`[${channel.name}] Failed: ${message}\n${detail.join("\n")}`);
|
|
328
352
|
return {
|
|
329
353
|
status: "failed",
|
|
330
354
|
channel: channel.name,
|
|
@@ -484,7 +508,7 @@ var NotificationService = class {
|
|
|
484
508
|
* Zero required dependencies - bring your own providers.
|
|
485
509
|
*
|
|
486
510
|
* v2: Rate limiting, delivery tracking, queue adapter,
|
|
487
|
-
* BCC batching, template engines, SMS
|
|
511
|
+
* BCC batching, template engines, SMS, push and Telegram channels.
|
|
488
512
|
*
|
|
489
513
|
* @module @classytic/notifications
|
|
490
514
|
* @author Classytic (https://github.com/classytic)
|
|
@@ -528,4 +552,4 @@ var NotificationService = class {
|
|
|
528
552
|
*/
|
|
529
553
|
|
|
530
554
|
//#endregion
|
|
531
|
-
export { BaseChannel, ChannelError, ConsoleChannel, EmailChannel, Emitter, IDEMPOTENCY_DEFAULT_TTL, MemoryDeliveryLog, MemoryIdempotencyStore, MemoryQueue, MemoryRateLimitStore, NotificationError, NotificationService, ProviderNotInstalledError, PushChannel, SmsChannel, WebhookChannel, calculateDelay, createSimpleResolver, createStatusHandler, interpolateHtml, isQuietHours, mergeHooks, pMap, resolveRetryConfig, withFallback, withRetry };
|
|
555
|
+
export { BaseChannel, ChannelError, ConsoleChannel, EmailChannel, Emitter, IDEMPOTENCY_DEFAULT_TTL, MemoryDeliveryLog, MemoryIdempotencyStore, MemoryQueue, MemoryRateLimitStore, NotificationError, NotificationService, ProviderNotInstalledError, PushChannel, SmsChannel, TelegramChannel, WebhookChannel, calculateDelay, createSimpleResolver, createStatusHandler, interpolateHtml, isQuietHours, mergeHooks, pMap, resolveRetryConfig, withFallback, withRetry };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as RetryConfig, S as ResolvedRetryConfig, d as HookMap, h as NotificationPayload,
|
|
1
|
+
import { A as TemplateResolver, C as RetryConfig, S as ResolvedRetryConfig, d as HookMap, h as NotificationPayload, o as DispatchResult, u as HookHandler } from "./types-DsRpYKr-.mjs";
|
|
2
2
|
//#region src/utils/merge-hooks.d.ts
|
|
3
3
|
type HookInput = Record<string, HookHandler | HookHandler[]>;
|
|
4
4
|
declare function mergeHooks(...hookConfigs: (HookInput | null | undefined)[]): HookMap;
|
|
@@ -591,4 +591,111 @@ var PushChannel = class extends BaseChannel {
|
|
|
591
591
|
};
|
|
592
592
|
|
|
593
593
|
//#endregion
|
|
594
|
-
|
|
594
|
+
//#region src/channels/telegram.channel.ts
|
|
595
|
+
/**
|
|
596
|
+
* Telegram Channel
|
|
597
|
+
* @module @classytic/notifications
|
|
598
|
+
*
|
|
599
|
+
* Sends a text message through the Telegram Bot API. Zero dependencies: one
|
|
600
|
+
* `fetch` to `sendMessage`.
|
|
601
|
+
*
|
|
602
|
+
* Telegram is the simple messaging case: no template approval, no service
|
|
603
|
+
* window, no business verification. A bot may message any chat it has been
|
|
604
|
+
* added to, immediately, which makes it the natural channel for a team's own
|
|
605
|
+
* alerts ("a new order is waiting for confirmation").
|
|
606
|
+
*
|
|
607
|
+
* ## Where a message goes
|
|
608
|
+
*
|
|
609
|
+
* `recipient.telegramChatId` when the recipient has one, else the channel's
|
|
610
|
+
* default `chatId` (typically the team's group). Telegram addresses chats by
|
|
611
|
+
* numeric id or `@channelname`; there is no phone-to-chat lookup, so a phone
|
|
612
|
+
* number is never used as a destination.
|
|
613
|
+
*
|
|
614
|
+
* @example
|
|
615
|
+
* ```typescript
|
|
616
|
+
* import { TelegramChannel } from '@classytic/notifications/channels';
|
|
617
|
+
*
|
|
618
|
+
* const ops = new TelegramChannel({
|
|
619
|
+
* botToken: process.env.TELEGRAM_BOT_TOKEN!,
|
|
620
|
+
* chatId: process.env.TELEGRAM_CHAT_ID!, // the team group
|
|
621
|
+
* events: ['order.placed'],
|
|
622
|
+
* });
|
|
623
|
+
* ```
|
|
624
|
+
*/
|
|
625
|
+
const DEFAULT_API = "https://api.telegram.org";
|
|
626
|
+
var TelegramChannel = class extends BaseChannel {
|
|
627
|
+
constructor(config) {
|
|
628
|
+
if (!config.botToken) throw new ChannelError(config.name ?? "telegram", "TelegramChannel requires a botToken.");
|
|
629
|
+
super({
|
|
630
|
+
name: "telegram",
|
|
631
|
+
...config
|
|
632
|
+
});
|
|
633
|
+
}
|
|
634
|
+
destinationOf(payload) {
|
|
635
|
+
return payload.recipient.telegramChatId || this.config.chatId || void 0;
|
|
636
|
+
}
|
|
637
|
+
textOf(payload) {
|
|
638
|
+
const { data } = payload;
|
|
639
|
+
return data.text ?? data.message ?? data.subject ?? "";
|
|
640
|
+
}
|
|
641
|
+
/**
|
|
642
|
+
* Deterministic skips, checked before the service spends a rate-limit token:
|
|
643
|
+
* nowhere to send, or nothing to say.
|
|
644
|
+
*/
|
|
645
|
+
canSend(payload) {
|
|
646
|
+
if (!this.destinationOf(payload)) return {
|
|
647
|
+
status: "skipped",
|
|
648
|
+
channel: this.name,
|
|
649
|
+
error: "No Telegram chat id (recipient.telegramChatId or the channel chatId)"
|
|
650
|
+
};
|
|
651
|
+
if (!this.textOf(payload)) return {
|
|
652
|
+
status: "skipped",
|
|
653
|
+
channel: this.name,
|
|
654
|
+
error: "No message body (data.text, data.message, or data.subject)"
|
|
655
|
+
};
|
|
656
|
+
return null;
|
|
657
|
+
}
|
|
658
|
+
async send(payload) {
|
|
659
|
+
const skip = this.canSend(payload);
|
|
660
|
+
if (skip) return skip;
|
|
661
|
+
const body = {
|
|
662
|
+
chat_id: this.destinationOf(payload),
|
|
663
|
+
text: this.textOf(payload),
|
|
664
|
+
...this.config.parseMode ? { parse_mode: this.config.parseMode } : {},
|
|
665
|
+
...this.config.silent ? { disable_notification: true } : {},
|
|
666
|
+
link_preview_options: { is_disabled: true }
|
|
667
|
+
};
|
|
668
|
+
let response;
|
|
669
|
+
try {
|
|
670
|
+
response = await fetch(`${this.config.apiBaseUrl ?? DEFAULT_API}/bot${this.config.botToken}/sendMessage`, {
|
|
671
|
+
method: "POST",
|
|
672
|
+
headers: { "Content-Type": "application/json" },
|
|
673
|
+
body: JSON.stringify(body),
|
|
674
|
+
signal: AbortSignal.timeout(this.config.timeout ?? 1e4)
|
|
675
|
+
});
|
|
676
|
+
} catch (err) {
|
|
677
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
678
|
+
throw new ChannelError(this.name, `Telegram unreachable: ${message}`, err instanceof Error ? err : void 0);
|
|
679
|
+
}
|
|
680
|
+
const json = await response.json().catch(() => ({}));
|
|
681
|
+
if (response.ok && json.ok) {
|
|
682
|
+
const id = json.result?.message_id;
|
|
683
|
+
return {
|
|
684
|
+
status: "sent",
|
|
685
|
+
channel: this.name,
|
|
686
|
+
...id !== void 0 ? { providerMessageId: String(id) } : {}
|
|
687
|
+
};
|
|
688
|
+
}
|
|
689
|
+
const reason = `Telegram ${response.status}: ${json.description ?? response.statusText}`;
|
|
690
|
+
if (response.status === 429 || response.status >= 500) throw new ChannelError(this.name, reason);
|
|
691
|
+
return {
|
|
692
|
+
status: "failed",
|
|
693
|
+
channel: this.name,
|
|
694
|
+
error: reason,
|
|
695
|
+
retryable: false
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
};
|
|
699
|
+
|
|
700
|
+
//#endregion
|
|
701
|
+
export { WebhookChannel as a, ConsoleChannel as i, PushChannel as n, EmailChannel as o, SmsChannel as r, BaseChannel as s, TelegramChannel as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as RetryConfig, E as SmsChannelConfig,
|
|
1
|
+
import { C as RetryConfig, E as SmsChannelConfig, M as WebhookChannelConfig, a as ChannelConfig, c as EmailChannelConfig, h as NotificationPayload, i as Channel, k as TelegramChannelConfig, q as RateLimitConfig, w as SendResult, y as PushChannelConfig } from "./types-DsRpYKr-.mjs";
|
|
2
2
|
//#region src/channels/BaseChannel.d.ts
|
|
3
3
|
declare abstract class BaseChannel<TConfig extends ChannelConfig = ChannelConfig> implements Channel {
|
|
4
4
|
readonly name: string;
|
|
@@ -73,4 +73,17 @@ declare class PushChannel extends BaseChannel<PushChannelConfig> {
|
|
|
73
73
|
send(payload: NotificationPayload): Promise<SendResult>;
|
|
74
74
|
}
|
|
75
75
|
//#endregion
|
|
76
|
-
|
|
76
|
+
//#region src/channels/telegram.channel.d.ts
|
|
77
|
+
declare class TelegramChannel extends BaseChannel<TelegramChannelConfig> {
|
|
78
|
+
constructor(config: TelegramChannelConfig);
|
|
79
|
+
private destinationOf;
|
|
80
|
+
private textOf;
|
|
81
|
+
/**
|
|
82
|
+
* Deterministic skips, checked before the service spends a rate-limit token:
|
|
83
|
+
* nowhere to send, or nothing to say.
|
|
84
|
+
*/
|
|
85
|
+
canSend(payload: NotificationPayload): SendResult | null;
|
|
86
|
+
send(payload: NotificationPayload): Promise<SendResult>;
|
|
87
|
+
}
|
|
88
|
+
//#endregion
|
|
89
|
+
export { WebhookChannel as a, ConsoleChannel as i, PushChannel as n, EmailChannel as o, SmsChannel as r, BaseChannel as s, TelegramChannel as t };
|
|
@@ -336,6 +336,8 @@ interface Recipient {
|
|
|
336
336
|
phone?: string;
|
|
337
337
|
name?: string;
|
|
338
338
|
deviceToken?: string;
|
|
339
|
+
/** Telegram chat id (numeric, or `@channelname`) — `TelegramChannel`'s destination. */
|
|
340
|
+
telegramChatId?: string;
|
|
339
341
|
metadata?: Record<string, unknown>;
|
|
340
342
|
}
|
|
341
343
|
/** Notification payload sent through the service */
|
|
@@ -574,6 +576,21 @@ interface WebhookChannelConfig extends ChannelConfig {
|
|
|
574
576
|
/** Request timeout in ms (default: 10000) */
|
|
575
577
|
timeout?: number;
|
|
576
578
|
}
|
|
579
|
+
/** TelegramChannel configuration — Bot API, no SDK. */
|
|
580
|
+
interface TelegramChannelConfig extends ChannelConfig {
|
|
581
|
+
/** The bot's token from @BotFather. Secret: it never appears in an error. */
|
|
582
|
+
botToken: string;
|
|
583
|
+
/** Default chat (a group id like `-1001234567890`, or `@channel`) when the recipient has none. */
|
|
584
|
+
chatId?: string;
|
|
585
|
+
/** Telegram formatting for `text`. Omit for plain text. */
|
|
586
|
+
parseMode?: 'HTML' | 'MarkdownV2';
|
|
587
|
+
/** Deliver without a notification sound. */
|
|
588
|
+
silent?: boolean;
|
|
589
|
+
/** Request timeout in ms (default: 10000) */
|
|
590
|
+
timeout?: number;
|
|
591
|
+
/** Bot API origin (default `https://api.telegram.org`); for a local Bot API server or tests. */
|
|
592
|
+
apiBaseUrl?: string;
|
|
593
|
+
}
|
|
577
594
|
/** SMS provider interface (Twilio or custom) */
|
|
578
595
|
interface SmsProvider {
|
|
579
596
|
send(message: {
|
|
@@ -758,4 +775,4 @@ interface BatchResult {
|
|
|
758
775
|
results: DispatchResult[];
|
|
759
776
|
}
|
|
760
777
|
//#endregion
|
|
761
|
-
export {
|
|
778
|
+
export { TemplateResolver as A, DeliveryLogEntry as B, RetryConfig as C, SmsProvider as D, SmsChannelConfig as E, QueueEnqueueOptions as F, MemoryIdempotencyStore as G, MemoryDeliveryLog as H, QueueJob as I, RateLimitStore as J, MemoryRateLimitStore as K, QueueJobStatus as L, WebhookChannelConfig as M, MemoryQueue as N, SmtpTransportOptions as O, QueueAdapter as P, QueueProcessor as R, ResolvedRetryConfig as S, ServiceEvent as T, IDEMPOTENCY_DEFAULT_TTL as U, DeliveryLogQuery as V, IdempotencyStore as W, NotificationServiceConfig as _, ChannelConfig as a, PushProvider as b, EmailChannelConfig as c, HookMap as d, Logger as f, NotificationPreferences as g, NotificationPayload as h, Channel as i, TemplateResult as j, TelegramChannelConfig as k, EventHandler as l, NotificationHookConfig as m, BatchProgress as n, DispatchResult as o, NodemailerTransporter as p, RateLimitConfig as q, BatchResult as r, EmailAttachment as s, BatchOptions as t, HookHandler as u, PreferenceResolver as v, SendResult as w, Recipient as x, PushChannelConfig as y, DeliveryLog as z };
|
package/dist/utils/index.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { B as
|
|
2
|
-
import { C as resolveRetryConfig, S as calculateDelay, T as mergeHooks, _ as isQuietHours, a as createStatusHandler, b as ProviderNotInstalledError, c as InterpolateOptions, d as TemplateMap, f as createSimpleResolver, g as QuietHoursConfig, h as pMap, i as StatusUpdate, m as PMapOptions, n as StatusHandler, o as FallbackOptions, p as interpolateHtml, r as StatusHandlerConfig, s as withFallback, t as DeliveryStatus, u as TemplateDefinition, v as ChannelError, w as withRetry, x as Emitter, y as NotificationError } from "../status-webhook-
|
|
1
|
+
import { B as DeliveryLogEntry, F as QueueEnqueueOptions, G as MemoryIdempotencyStore, H as MemoryDeliveryLog, I as QueueJob, J as RateLimitStore, K as MemoryRateLimitStore, L as QueueJobStatus, N as MemoryQueue, P as QueueAdapter, R as QueueProcessor, U as IDEMPOTENCY_DEFAULT_TTL, V as DeliveryLogQuery, W as IdempotencyStore, q as RateLimitConfig, z as DeliveryLog } from "../types-DsRpYKr-.mjs";
|
|
2
|
+
import { C as resolveRetryConfig, S as calculateDelay, T as mergeHooks, _ as isQuietHours, a as createStatusHandler, b as ProviderNotInstalledError, c as InterpolateOptions, d as TemplateMap, f as createSimpleResolver, g as QuietHoursConfig, h as pMap, i as StatusUpdate, m as PMapOptions, n as StatusHandler, o as FallbackOptions, p as interpolateHtml, r as StatusHandlerConfig, s as withFallback, t as DeliveryStatus, u as TemplateDefinition, v as ChannelError, w as withRetry, x as Emitter, y as NotificationError } from "../status-webhook-C8WnLIMv.mjs";
|
|
3
3
|
export { ChannelError, type DeliveryLog, type DeliveryLogEntry, type DeliveryLogQuery, type DeliveryStatus, Emitter, type FallbackOptions, IDEMPOTENCY_DEFAULT_TTL, type IdempotencyStore, type InterpolateOptions, MemoryDeliveryLog, MemoryIdempotencyStore, MemoryQueue, MemoryRateLimitStore, NotificationError, type PMapOptions, ProviderNotInstalledError, type QueueAdapter, type QueueEnqueueOptions, type QueueJob, type QueueJobStatus, type QueueProcessor, type QuietHoursConfig, type RateLimitConfig, type RateLimitStore, type StatusHandler, type StatusHandlerConfig, type StatusUpdate, type TemplateDefinition, type TemplateMap, calculateDelay, createSimpleResolver, createStatusHandler, interpolateHtml, isQuietHours, mergeHooks, pMap, resolveRetryConfig, withFallback, withRetry };
|
package/package.json
CHANGED
|
@@ -1,117 +1,118 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@classytic/notifications",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "Multi-channel notifications (Email, SMS, Push, Webhook) with rate limiting, delivery tracking, queue adapters, channel fallback, templates, retry — zero required dependencies",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"sideEffects": false,
|
|
7
|
-
"main": "./dist/index.mjs",
|
|
8
|
-
"module": "./dist/index.mjs",
|
|
9
|
-
"types": "./dist/index.d.mts",
|
|
10
|
-
"exports": {
|
|
11
|
-
".": {
|
|
12
|
-
"types": "./dist/index.d.mts",
|
|
13
|
-
"default": "./dist/index.mjs"
|
|
14
|
-
},
|
|
15
|
-
"./channels": {
|
|
16
|
-
"types": "./dist/channels/index.d.mts",
|
|
17
|
-
"default": "./dist/channels/index.mjs"
|
|
18
|
-
},
|
|
19
|
-
"./providers": {
|
|
20
|
-
"types": "./dist/providers/index.d.mts",
|
|
21
|
-
"default": "./dist/providers/index.mjs"
|
|
22
|
-
},
|
|
23
|
-
"./utils": {
|
|
24
|
-
"types": "./dist/utils/index.d.mts",
|
|
25
|
-
"default": "./dist/utils/index.mjs"
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
"typesVersions": {
|
|
29
|
-
"*": {
|
|
30
|
-
"channels": ["./dist/channels/index.d.mts"],
|
|
31
|
-
"providers": ["./dist/providers/index.d.mts"],
|
|
32
|
-
"utils": ["./dist/utils/index.d.mts"]
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
"files": [
|
|
36
|
-
"dist",
|
|
37
|
-
"README.md",
|
|
38
|
-
"CHANGELOG.md",
|
|
39
|
-
"LICENSE"
|
|
40
|
-
],
|
|
41
|
-
"keywords": [
|
|
42
|
-
"notifications",
|
|
43
|
-
"multi-channel",
|
|
44
|
-
"email",
|
|
45
|
-
"sms",
|
|
46
|
-
"push-notifications",
|
|
47
|
-
"webhook",
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
"
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
"
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
"
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
"
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
"
|
|
93
|
-
"
|
|
94
|
-
"test
|
|
95
|
-
"test:
|
|
96
|
-
"test:
|
|
97
|
-
"
|
|
98
|
-
"
|
|
99
|
-
"
|
|
100
|
-
"
|
|
101
|
-
"publish:
|
|
102
|
-
"
|
|
103
|
-
"release
|
|
104
|
-
"release:
|
|
105
|
-
"release:
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
"@
|
|
110
|
-
"@types/
|
|
111
|
-
"@
|
|
112
|
-
"
|
|
113
|
-
"
|
|
114
|
-
"
|
|
115
|
-
"
|
|
116
|
-
|
|
117
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@classytic/notifications",
|
|
3
|
+
"version": "2.6.0",
|
|
4
|
+
"description": "Multi-channel notifications (Email, SMS, Push, Webhook, Telegram) with rate limiting, delivery tracking, queue adapters, channel fallback, templates, retry — zero required dependencies",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"main": "./dist/index.mjs",
|
|
8
|
+
"module": "./dist/index.mjs",
|
|
9
|
+
"types": "./dist/index.d.mts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.mts",
|
|
13
|
+
"default": "./dist/index.mjs"
|
|
14
|
+
},
|
|
15
|
+
"./channels": {
|
|
16
|
+
"types": "./dist/channels/index.d.mts",
|
|
17
|
+
"default": "./dist/channels/index.mjs"
|
|
18
|
+
},
|
|
19
|
+
"./providers": {
|
|
20
|
+
"types": "./dist/providers/index.d.mts",
|
|
21
|
+
"default": "./dist/providers/index.mjs"
|
|
22
|
+
},
|
|
23
|
+
"./utils": {
|
|
24
|
+
"types": "./dist/utils/index.d.mts",
|
|
25
|
+
"default": "./dist/utils/index.mjs"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"typesVersions": {
|
|
29
|
+
"*": {
|
|
30
|
+
"channels": ["./dist/channels/index.d.mts"],
|
|
31
|
+
"providers": ["./dist/providers/index.d.mts"],
|
|
32
|
+
"utils": ["./dist/utils/index.d.mts"]
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist",
|
|
37
|
+
"README.md",
|
|
38
|
+
"CHANGELOG.md",
|
|
39
|
+
"LICENSE"
|
|
40
|
+
],
|
|
41
|
+
"keywords": [
|
|
42
|
+
"notifications",
|
|
43
|
+
"multi-channel",
|
|
44
|
+
"email",
|
|
45
|
+
"sms",
|
|
46
|
+
"push-notifications",
|
|
47
|
+
"webhook",
|
|
48
|
+
"telegram",
|
|
49
|
+
"nodemailer",
|
|
50
|
+
"smtp",
|
|
51
|
+
"ses",
|
|
52
|
+
"rate-limiting",
|
|
53
|
+
"delivery-tracking",
|
|
54
|
+
"queue",
|
|
55
|
+
"channel-fallback",
|
|
56
|
+
"templates",
|
|
57
|
+
"retry",
|
|
58
|
+
"idempotency",
|
|
59
|
+
"pluggable",
|
|
60
|
+
"framework-agnostic",
|
|
61
|
+
"typescript",
|
|
62
|
+
"zero-dependencies"
|
|
63
|
+
],
|
|
64
|
+
"author": "Classytic <classytic.dev@gmail.com> (https://github.com/classytic)",
|
|
65
|
+
"contributors": [
|
|
66
|
+
"Sadman Chowdhury (https://github.com/siam923)"
|
|
67
|
+
],
|
|
68
|
+
"license": "MIT",
|
|
69
|
+
"publishConfig": {
|
|
70
|
+
"access": "public"
|
|
71
|
+
},
|
|
72
|
+
"repository": {
|
|
73
|
+
"type": "git",
|
|
74
|
+
"url": "git+https://github.com/classytic/notifications.git"
|
|
75
|
+
},
|
|
76
|
+
"bugs": {
|
|
77
|
+
"url": "https://github.com/classytic/notifications/issues"
|
|
78
|
+
},
|
|
79
|
+
"homepage": "https://github.com/classytic/notifications#readme",
|
|
80
|
+
"peerDependencies": {
|
|
81
|
+
"nodemailer": ">=6"
|
|
82
|
+
},
|
|
83
|
+
"peerDependenciesMeta": {
|
|
84
|
+
"nodemailer": {
|
|
85
|
+
"optional": true
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
"engines": {
|
|
89
|
+
"node": ">=18"
|
|
90
|
+
},
|
|
91
|
+
"scripts": {
|
|
92
|
+
"build": "tsdown",
|
|
93
|
+
"dev": "tsdown --watch",
|
|
94
|
+
"test": "vitest run",
|
|
95
|
+
"test:watch": "vitest",
|
|
96
|
+
"test:coverage": "vitest run --coverage",
|
|
97
|
+
"test:live": "vitest run --config vitest.live.config.ts",
|
|
98
|
+
"typecheck": "tsc --noEmit",
|
|
99
|
+
"prepublishOnly": "npm run build && npm run typecheck && npm test",
|
|
100
|
+
"push": "classytic-push",
|
|
101
|
+
"publish:dry": "npm publish --dry-run --access public",
|
|
102
|
+
"publish:npm": "npm publish --access public",
|
|
103
|
+
"release": "npm run build && npm run typecheck && npm test && npm publish --access public",
|
|
104
|
+
"release:patch": "npm version patch && npm run release",
|
|
105
|
+
"release:minor": "npm version minor && npm run release",
|
|
106
|
+
"release:major": "npm version major && npm run release"
|
|
107
|
+
},
|
|
108
|
+
"devDependencies": {
|
|
109
|
+
"@classytic/dev-tools": "^0.2.0",
|
|
110
|
+
"@types/node": "^22.0.0",
|
|
111
|
+
"@types/nodemailer": "^8.0.0",
|
|
112
|
+
"@vitest/coverage-v8": "4.1.8",
|
|
113
|
+
"nodemailer": "^8.0.10",
|
|
114
|
+
"tsdown": "^0.22.14",
|
|
115
|
+
"typescript": "^6.0.3",
|
|
116
|
+
"vitest": "^4.1.8"
|
|
117
|
+
}
|
|
118
|
+
}
|