@wrongstack/telegram 0.309.0 → 0.310.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/dist/approval-flow.d.ts +53 -0
- package/dist/bot-types.d.ts +56 -0
- package/dist/bot.d.ts +18 -159
- package/dist/inbox.d.ts +48 -0
- package/dist/index.js +425 -419
- package/dist/outbox.d.ts +41 -0
- package/dist/poller.d.ts +48 -0
- package/dist/text-format.d.ts +25 -0
- package/package.json +3 -3
package/dist/outbox.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Logger } from '@wrongstack/core/types';
|
|
2
|
+
import { type TelegramApiClient, type TelegramApiMessage } from './api-client.js';
|
|
3
|
+
import type { TelegramBotResponse } from './bot-types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Outbound Telegram API surface (card 7A-4): retry-wrapped senders and the
|
|
6
|
+
* health probe. Moved verbatim from bot.ts (the P1.3 retry/backoff policy is
|
|
7
|
+
* frozen behavior); only the state reads changed shape.
|
|
8
|
+
*/
|
|
9
|
+
export interface TelegramOutboxDeps {
|
|
10
|
+
/**
|
|
11
|
+
* Live api accessor — called at use time, NOT captured at construction
|
|
12
|
+
* (card 7A-2 lesson): tests replace `bot.api` after construction via
|
|
13
|
+
* Object.assign / property assignment, so a captured instance would never
|
|
14
|
+
* see the mock.
|
|
15
|
+
*/
|
|
16
|
+
api: () => TelegramApiClient;
|
|
17
|
+
log: Logger;
|
|
18
|
+
/** Resolved per attempt; empty string or `undefined` → plain text. */
|
|
19
|
+
getParseMode?: (() => '' | 'HTML' | 'MarkdownV2' | undefined) | undefined;
|
|
20
|
+
}
|
|
21
|
+
export declare class TelegramOutbox {
|
|
22
|
+
private readonly deps;
|
|
23
|
+
constructor(deps: TelegramOutboxDeps);
|
|
24
|
+
sendMessage(chatId: string | number, text: string, signal?: AbortSignal | undefined): Promise<TelegramBotResponse<TelegramApiMessage>>;
|
|
25
|
+
/**
|
|
26
|
+
* Send a message that has up to one row of inline buttons (Telegram's
|
|
27
|
+
* `inline_keyboard`). Used by `telegram_approve` to present a
|
|
28
|
+
* yes/no prompt. The keyboard payload is opaque to the outbox — callers
|
|
29
|
+
* pass already-encoded `callback_data` strings (≤ 64 bytes each).
|
|
30
|
+
*/
|
|
31
|
+
sendMessageWithKeyboard(chatId: string | number, text: string, buttons: Array<{
|
|
32
|
+
text: string;
|
|
33
|
+
callback_data: string;
|
|
34
|
+
}>, signal?: AbortSignal | undefined): Promise<TelegramBotResponse<TelegramApiMessage>>;
|
|
35
|
+
health(signal?: AbortSignal | undefined): Promise<{
|
|
36
|
+
ok: boolean;
|
|
37
|
+
username?: string | undefined;
|
|
38
|
+
error?: string | undefined;
|
|
39
|
+
}>;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=outbox.d.ts.map
|
package/dist/poller.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Logger } from '@wrongstack/core/types';
|
|
2
|
+
import { type TelegramApiClient } from './api-client.js';
|
|
3
|
+
import type { OffsetStore } from './offset-store.js';
|
|
4
|
+
import type { PollLock } from './poll-lock.js';
|
|
5
|
+
export declare class Poller {
|
|
6
|
+
private readonly api;
|
|
7
|
+
private readonly pollIntervalMs;
|
|
8
|
+
private readonly log;
|
|
9
|
+
private readonly controller;
|
|
10
|
+
private readonly offsetStore?;
|
|
11
|
+
private readonly lock?;
|
|
12
|
+
private readonly standbyRetryMs;
|
|
13
|
+
private pollTimer;
|
|
14
|
+
private standbyTimer;
|
|
15
|
+
private standbyAnnounced;
|
|
16
|
+
private pollActive;
|
|
17
|
+
private _startedAt;
|
|
18
|
+
private offset;
|
|
19
|
+
private _conflictStreak;
|
|
20
|
+
private static readonly CONFLICT_BACKOFF_AFTER;
|
|
21
|
+
private static readonly CONFLICT_POLL_MS;
|
|
22
|
+
private readonly onCallbackQuery;
|
|
23
|
+
private readonly onMessageUpdate;
|
|
24
|
+
constructor(deps: {
|
|
25
|
+
api: () => TelegramApiClient;
|
|
26
|
+
pollIntervalMs: number;
|
|
27
|
+
log: Logger;
|
|
28
|
+
controller: AbortController;
|
|
29
|
+
offsetStore?: OffsetStore | undefined;
|
|
30
|
+
lock?: PollLock | undefined;
|
|
31
|
+
standbyRetryMs: number;
|
|
32
|
+
onCallbackQuery: Poller['onCallbackQuery'];
|
|
33
|
+
onMessageUpdate: Poller['onMessageUpdate'];
|
|
34
|
+
});
|
|
35
|
+
get active(): boolean;
|
|
36
|
+
get startedAt(): number | null;
|
|
37
|
+
get standby(): boolean;
|
|
38
|
+
get conflictStreak(): number;
|
|
39
|
+
start(): void;
|
|
40
|
+
stop(): void;
|
|
41
|
+
acquireAndPoll(): void;
|
|
42
|
+
handleLockLost(): void;
|
|
43
|
+
schedulePoll(): void;
|
|
44
|
+
poll(): Promise<void>;
|
|
45
|
+
loadOffset(): Promise<void>;
|
|
46
|
+
saveOffset(): Promise<void>;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=poller.d.ts.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telegram platform text-formatting utilities.
|
|
3
|
+
*
|
|
4
|
+
* Extracted from bot.ts (card #7A-1) — pure string helpers bound to
|
|
5
|
+
* Telegram's message-length platform contract, with no dependency on the
|
|
6
|
+
* bot's polling, approval, or API-client machinery. Kept separate from
|
|
7
|
+
* ./format.ts (event humanizers) because that module renders host events
|
|
8
|
+
* while this one enforces platform limits.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Truncate text to fit Telegram's 4096-char message limit.
|
|
12
|
+
* Preserves semantic boundaries in this priority order:
|
|
13
|
+
* 1. Paragraph break (double newline)
|
|
14
|
+
* 2. Sentence break (. ! ? followed by space/newline)
|
|
15
|
+
* 3. Word break (space)
|
|
16
|
+
* 4. Hard cut with ellipsis
|
|
17
|
+
*
|
|
18
|
+
* When a clean boundary is found, appends "…" to signal intentional truncation.
|
|
19
|
+
*/
|
|
20
|
+
export declare function truncateForTelegram(text: string, maxLen?: number): string;
|
|
21
|
+
/**
|
|
22
|
+
* Escape HTML special chars for Telegram's HTML parse mode.
|
|
23
|
+
*/
|
|
24
|
+
export declare function escapeHtml(text: string): string;
|
|
25
|
+
//# sourceMappingURL=text-format.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wrongstack/telegram",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.310.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "WrongStack plugin — Telegram bridge: send messages, receive prompts, get notified.",
|
|
6
6
|
"repository": {
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
"!dist/**/*.map"
|
|
27
27
|
],
|
|
28
28
|
"peerDependencies": {
|
|
29
|
-
"@wrongstack/core": "0.
|
|
29
|
+
"@wrongstack/core": "0.310.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/node": "^26.2.0",
|
|
33
33
|
"typescript": "^7.0.2",
|
|
34
|
-
"@wrongstack/core": "0.
|
|
34
|
+
"@wrongstack/core": "0.310.0"
|
|
35
35
|
},
|
|
36
36
|
"publishConfig": {
|
|
37
37
|
"access": "public"
|