stitchkit 0.123.5 → 0.123.6
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 +26 -0
- package/dist/entrypoints/telegram/grammy.d.ts +1 -0
- package/dist/entrypoints/telegram/grammy.d.ts.map +1 -1
- package/dist/entrypoints/telegram/grammy.js +81 -3
- package/dist/entrypoints/telegram/screens.js +1 -1
- package/dist/entrypoints/telegram.d.ts +1 -0
- package/dist/entrypoints/telegram.d.ts.map +1 -1
- package/dist/entrypoints/telegram.js +17 -5
- package/dist/index-bgj9hbm3.js +93 -0
- package/dist/{index-303qne11.js → index-f56ct5gb.js} +27 -4
- package/dist/telegram/send-failure.d.ts +2 -2
- package/dist/telegram/send-failure.d.ts.map +1 -1
- package/dist/telegram/widget-api.d.ts +106 -0
- package/dist/telegram/widget-api.d.ts.map +1 -0
- package/dist/telegram/widget.d.ts +121 -0
- package/dist/telegram/widget.d.ts.map +1 -0
- package/llms/stitchkit.txt +2 -2
- package/llms/telegram-grammy.txt +10 -3
- package/llms/telegram.2.txt +5 -0
- package/llms/telegram.txt +70 -0
- package/llms-full.txt +84 -5
- package/llms.txt +4 -4
- package/package.json +1 -1
- package/dist/index-6j725ez5.js +0 -25
package/CHANGELOG.md
CHANGED
|
@@ -15,6 +15,32 @@ additive**; the first breaking change landed in 0.10.0. Grep the file for
|
|
|
15
15
|
|
|
16
16
|
## [Unreleased]
|
|
17
17
|
|
|
18
|
+
## [0.123.6] - 2026-11-16
|
|
19
|
+
|
|
20
|
+
### Added
|
|
21
|
+
|
|
22
|
+
- `stitchkit/telegram/grammy` — **`telegramWidgetApi(api)`: the Bot API 10.4 widget methods over
|
|
23
|
+
the client a bot already has.** `sendWidget`, `editMessageWidgetData` and `answerWidgetQuery`
|
|
24
|
+
take their Bot API parameters and `{ signal }`, and go through the client's `api.raw`, so every
|
|
25
|
+
transformer of that client runs them: with `telegramBudgetTransformer` installed a send or an edit
|
|
26
|
+
spends one message of the token's budget and an answer waits for none. No second client, limiter
|
|
27
|
+
or retry. Input over Telegram's byte limits throws `ZodError` before any request; an already
|
|
28
|
+
aborted signal throws `TelegramNotDispatchedError`; a request is handed on once; `message is not
|
|
29
|
+
modified` on an edit is success; an unexpected successful answer is an error whose outcome is
|
|
30
|
+
unknown. The public surface ceiling of `stitchkit/telegram/grammy` moves from 1 to 7 names for
|
|
31
|
+
the function, its interface, the three parameter types and the call options.
|
|
32
|
+
[guide](docs/guide/telegram.md#widgets)
|
|
33
|
+
|
|
34
|
+
- `stitchkit/telegram` — **Widget limits and shapes.** `TELEGRAM_WIDGET_LIMITS`, the byte-counted
|
|
35
|
+
`TelegramWidgetHtmlSchema` (1–32768 bytes, at most 4096 after the runtime's zlib at level 9 — an
|
|
36
|
+
estimate of Telegram's, so keep a margin) and
|
|
37
|
+
`TelegramWidgetDataSchema` (0–1024 bytes; NUL and unpaired surrogates refused, `''` is a value),
|
|
38
|
+
`TelegramWidgetMessageSchema` for the sent message and `TelegramWidgetQuerySchema` for
|
|
39
|
+
`Update.widget_query`, both parsed loosely so fields Telegram adds pass through.
|
|
40
|
+
`parseTelegramWidgetQuery` returns the id of a query that does not parse, so it can be refused
|
|
41
|
+
instead of left to time out. The public surface ceiling of `stitchkit/telegram` moves from 107 to
|
|
42
|
+
116 names for the limits, four schemas, their three types and the parser.
|
|
43
|
+
|
|
18
44
|
## [0.123.5] - 2026-11-13
|
|
19
45
|
|
|
20
46
|
### Fixed
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export { telegramBudgetTransformer } from '../../telegram/budget-transformer.js';
|
|
2
|
+
export { type TelegramAnswerWidgetQueryParams, type TelegramEditMessageWidgetDataParams, type TelegramSendWidgetParams, type TelegramWidgetApi, type TelegramWidgetCallOptions, telegramWidgetApi, } from '../../telegram/widget-api.js';
|
|
2
3
|
//# sourceMappingURL=grammy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grammy.d.ts","sourceRoot":"","sources":["../../../src/entrypoints/telegram/grammy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC"}
|
|
1
|
+
{"version":3,"file":"grammy.d.ts","sourceRoot":"","sources":["../../../src/entrypoints/telegram/grammy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EACL,KAAK,+BAA+B,EACpC,KAAK,mCAAmC,EACxC,KAAK,wBAAwB,EAC7B,KAAK,iBAAiB,EACtB,KAAK,yBAAyB,EAC9B,iBAAiB,GAClB,MAAM,2BAA2B,CAAC"}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
TelegramWidgetHtmlSchema2,
|
|
3
|
+
TelegramWidgetDataSchema2,
|
|
4
|
+
TelegramWidgetMessageSchema2
|
|
5
|
+
} from "../../index-bgj9hbm3.js";
|
|
6
|
+
import {
|
|
7
|
+
TelegramNotDispatchedError2,
|
|
8
|
+
classifyTelegramEditRefusal
|
|
9
|
+
} from "../../index-f56ct5gb.js";
|
|
4
10
|
|
|
5
11
|
// src/telegram/budget-transformer.ts
|
|
6
12
|
function platformSignal(signal) {
|
|
@@ -45,6 +51,78 @@ function telegramBudgetTransformer(budget, options) {
|
|
|
45
51
|
}
|
|
46
52
|
};
|
|
47
53
|
}
|
|
54
|
+
// src/telegram/widget-api.ts
|
|
55
|
+
import { z } from "zod";
|
|
56
|
+
var ChatIdSchema = z.union([z.int(), z.string().min(1)]);
|
|
57
|
+
var SendInputSchema = z.object({
|
|
58
|
+
chat_id: ChatIdSchema,
|
|
59
|
+
html: TelegramWidgetHtmlSchema2,
|
|
60
|
+
public_data: TelegramWidgetDataSchema2.optional(),
|
|
61
|
+
chat_data: TelegramWidgetDataSchema2.optional()
|
|
62
|
+
});
|
|
63
|
+
var EditInputSchema = z.object({
|
|
64
|
+
chat_id: ChatIdSchema.optional(),
|
|
65
|
+
message_id: z.int().optional(),
|
|
66
|
+
inline_message_id: z.string().min(1).optional(),
|
|
67
|
+
public_data: TelegramWidgetDataSchema2.optional(),
|
|
68
|
+
chat_data: TelegramWidgetDataSchema2.optional()
|
|
69
|
+
}).refine((edit) => edit.inline_message_id === undefined ? edit.chat_id !== undefined && edit.message_id !== undefined : edit.chat_id === undefined && edit.message_id === undefined, { message: "Pass chat_id with message_id, or inline_message_id alone" }).refine((edit) => edit.chat_data !== undefined || edit.public_data !== undefined, {
|
|
70
|
+
message: "Pass chat_data or public_data to change"
|
|
71
|
+
});
|
|
72
|
+
var AnswerInputSchema = z.object({
|
|
73
|
+
widget_query_id: z.string().min(1),
|
|
74
|
+
data: TelegramWidgetDataSchema2.optional()
|
|
75
|
+
});
|
|
76
|
+
var TrueSchema = z.literal(true);
|
|
77
|
+
function payloadOf(params) {
|
|
78
|
+
return Object.fromEntries(Object.entries(params).filter(([, value]) => value !== undefined));
|
|
79
|
+
}
|
|
80
|
+
async function dispatch(api, method, payload, signal) {
|
|
81
|
+
if (signal?.aborted) {
|
|
82
|
+
throw new TelegramNotDispatchedError2("request", `the Telegram ${method} request was cancelled before it was sent`, { cause: signal.reason });
|
|
83
|
+
}
|
|
84
|
+
const call = Reflect.get(api.raw, method);
|
|
85
|
+
if (typeof call !== "function") {
|
|
86
|
+
throw new TypeError(`This grammY client has no ${method} method`);
|
|
87
|
+
}
|
|
88
|
+
return await Reflect.apply(call, api.raw, [payload, signal]);
|
|
89
|
+
}
|
|
90
|
+
function answered(method, schema, value) {
|
|
91
|
+
const parsed = schema.safeParse(value);
|
|
92
|
+
if (parsed.success)
|
|
93
|
+
return parsed.data;
|
|
94
|
+
throw new Error(`Telegram answered ${method} with an unexpected result; the request was sent and its outcome is unknown`, { cause: parsed.error });
|
|
95
|
+
}
|
|
96
|
+
function telegramWidgetApi(api) {
|
|
97
|
+
return {
|
|
98
|
+
async sendWidget(params, options) {
|
|
99
|
+
const payload = payloadOf(params);
|
|
100
|
+
SendInputSchema.parse(payload);
|
|
101
|
+
const value = await dispatch(api, "sendWidget", payload, options?.signal);
|
|
102
|
+
return answered("sendWidget", TelegramWidgetMessageSchema2, value);
|
|
103
|
+
},
|
|
104
|
+
async editMessageWidgetData(params, options) {
|
|
105
|
+
const payload = payloadOf(params);
|
|
106
|
+
EditInputSchema.parse(payload);
|
|
107
|
+
let value;
|
|
108
|
+
try {
|
|
109
|
+
value = await dispatch(api, "editMessageWidgetData", payload, options?.signal);
|
|
110
|
+
} catch (error) {
|
|
111
|
+
if (classifyTelegramEditRefusal(error) === "not-modified")
|
|
112
|
+
return;
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
115
|
+
answered("editMessageWidgetData", TrueSchema, value);
|
|
116
|
+
},
|
|
117
|
+
async answerWidgetQuery(params, options) {
|
|
118
|
+
const payload = payloadOf(params);
|
|
119
|
+
AnswerInputSchema.parse(payload);
|
|
120
|
+
const value = await dispatch(api, "answerWidgetQuery", payload, options?.signal);
|
|
121
|
+
answered("answerWidgetQuery", TrueSchema, value);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
48
125
|
export {
|
|
49
|
-
telegramBudgetTransformer
|
|
126
|
+
telegramBudgetTransformer,
|
|
127
|
+
telegramWidgetApi
|
|
50
128
|
};
|
|
@@ -17,4 +17,5 @@ export { type SqliteTelegramUpdateStoreConfig, sqliteTelegramUpdateStore, type T
|
|
|
17
17
|
export { parseTelegramUser, type TelegramUser } from '../telegram/user.js';
|
|
18
18
|
export { type ReadTelegramVoiceWaveformOptions, readTelegramVoiceWaveform, } from '../telegram/voice-waveform-pcm.js';
|
|
19
19
|
export { type ClaimTelegramWebhookConfig, checkTelegramWebhook, claimTelegramWebhook, type ReceiveTelegramWebhookOptions, receiveTelegramWebhook, TELEGRAM_WEBHOOK_NONE, type TelegramUpdateAcceptance, type TelegramWebhookClaim, TelegramWebhookClaimError, type TelegramWebhookConfig, type TelegramWebhookRefusal, type TelegramWebhookState, telegramWebhookUrl, } from '../telegram/webhook.js';
|
|
20
|
+
export { parseTelegramWidgetQuery, TELEGRAM_WIDGET_LIMITS, TelegramWidgetDataSchema, TelegramWidgetHtmlSchema, type TelegramWidgetMessage, TelegramWidgetMessageSchema, type TelegramWidgetQuery, type TelegramWidgetQueryParse, TelegramWidgetQuerySchema, } from '../telegram/widget.js';
|
|
20
21
|
//# sourceMappingURL=telegram.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telegram.d.ts","sourceRoot":"","sources":["../../src/entrypoints/telegram.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EACtB,0BAA0B,EAC1B,KAAK,kBAAkB,EACvB,mBAAmB,GACpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,oBAAoB,EACpB,KAAK,uBAAuB,EAC5B,KAAK,wBAAwB,EAC7B,KAAK,wBAAwB,EAC7B,KAAK,0BAA0B,EAC/B,KAAK,uBAAuB,EAC5B,KAAK,2BAA2B,EAChC,KAAK,qBAAqB,EAC1B,KAAK,6BAA6B,EAClC,uBAAuB,GACxB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,KAAK,wBAAwB,EAC7B,8BAA8B,GAC/B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,EAC5B,KAAK,4BAA4B,EACjC,KAAK,6BAA6B,EAClC,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,wBAAwB,EACxB,sBAAsB,EACtB,KAAK,wBAAwB,EAC7B,KAAK,kBAAkB,EACvB,KAAK,uBAAuB,EAC5B,KAAK,wBAAwB,GAC9B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,0BAA0B,EAC1B,KAAK,0BAA0B,GAChC,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,6BAA6B,EAC7B,KAAK,cAAc,EACnB,KAAK,uBAAuB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CAAC"}
|
|
@@ -6,19 +6,25 @@ import"../index-bqzgaj57.js";
|
|
|
6
6
|
import {
|
|
7
7
|
attemptExclusiveLock
|
|
8
8
|
} from "../index-chz7c830.js";
|
|
9
|
+
import {
|
|
10
|
+
TELEGRAM_WIDGET_LIMITS2,
|
|
11
|
+
TelegramWidgetHtmlSchema2,
|
|
12
|
+
TelegramWidgetDataSchema2,
|
|
13
|
+
TelegramWidgetMessageSchema2,
|
|
14
|
+
TelegramWidgetQuerySchema2,
|
|
15
|
+
parseTelegramWidgetQuery2
|
|
16
|
+
} from "../index-bgj9hbm3.js";
|
|
9
17
|
import {
|
|
10
18
|
TELEGRAM_VOICE_WAVEFORM_SAMPLES2,
|
|
11
19
|
TelegramVoiceWaveformError2,
|
|
12
20
|
packTelegramVoiceWaveform2
|
|
13
21
|
} from "../index-0jdempdr.js";
|
|
14
22
|
import {
|
|
23
|
+
TelegramNotDispatchedError2,
|
|
24
|
+
isTelegramNotDispatchedError,
|
|
15
25
|
TELEGRAM_SEND_FAILURE_REASONS2,
|
|
16
26
|
classifyTelegramSendFailure2
|
|
17
|
-
} from "../index-
|
|
18
|
-
import {
|
|
19
|
-
TelegramNotDispatchedError2,
|
|
20
|
-
isTelegramNotDispatchedError
|
|
21
|
-
} from "../index-6j725ez5.js";
|
|
27
|
+
} from "../index-f56ct5gb.js";
|
|
22
28
|
import {
|
|
23
29
|
TELEGRAM_TEXT_LIMIT2,
|
|
24
30
|
truncateTelegramHtml2
|
|
@@ -3104,12 +3110,17 @@ export {
|
|
|
3104
3110
|
TELEGRAM_BOT_TOKEN_PATTERN,
|
|
3105
3111
|
TELEGRAM_SEND_FAILURE_REASONS2 as TELEGRAM_SEND_FAILURE_REASONS,
|
|
3106
3112
|
TELEGRAM_WEBHOOK_NONE,
|
|
3113
|
+
TELEGRAM_WIDGET_LIMITS2 as TELEGRAM_WIDGET_LIMITS,
|
|
3107
3114
|
TelegramBotApiError,
|
|
3108
3115
|
TelegramBroadcastFailureSchema,
|
|
3109
3116
|
TelegramLocalFileError,
|
|
3110
3117
|
TelegramNotDispatchedError2 as TelegramNotDispatchedError,
|
|
3111
3118
|
TelegramUpdateOwnershipLostError,
|
|
3112
3119
|
TelegramWebhookClaimError,
|
|
3120
|
+
TelegramWidgetDataSchema2 as TelegramWidgetDataSchema,
|
|
3121
|
+
TelegramWidgetHtmlSchema2 as TelegramWidgetHtmlSchema,
|
|
3122
|
+
TelegramWidgetMessageSchema2 as TelegramWidgetMessageSchema,
|
|
3123
|
+
TelegramWidgetQuerySchema2 as TelegramWidgetQuerySchema,
|
|
3113
3124
|
callTelegramBotApi,
|
|
3114
3125
|
checkTelegramUpdateStore,
|
|
3115
3126
|
checkTelegramWebhook,
|
|
@@ -3122,6 +3133,7 @@ export {
|
|
|
3122
3133
|
createTelegramUpdateIntake,
|
|
3123
3134
|
memoryTelegramUpdateStore,
|
|
3124
3135
|
parseTelegramUser,
|
|
3136
|
+
parseTelegramWidgetQuery2 as parseTelegramWidgetQuery,
|
|
3125
3137
|
postgresTelegramUpdateStore,
|
|
3126
3138
|
postgresTelegramUpdateStoreSchema,
|
|
3127
3139
|
readTelegramVoiceWaveform,
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// src/telegram/widget.ts
|
|
2
|
+
import { deflateSync } from "node:zlib";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
var TELEGRAM_WIDGET_LIMITS2 = Object.freeze({
|
|
5
|
+
htmlBytes: 32768,
|
|
6
|
+
compressedHtmlBytes: 4096,
|
|
7
|
+
dataBytes: 1024,
|
|
8
|
+
queryDataBytes: 64,
|
|
9
|
+
answerWindowMs: 15000
|
|
10
|
+
});
|
|
11
|
+
var encoder = new TextEncoder;
|
|
12
|
+
var decoder = new TextDecoder("utf-8", { ignoreBOM: true });
|
|
13
|
+
function textProblem(value, max, min = 0) {
|
|
14
|
+
if (value.includes("\x00"))
|
|
15
|
+
return "contains NUL";
|
|
16
|
+
const encoded = encoder.encode(value);
|
|
17
|
+
if (decoder.decode(encoded) !== value)
|
|
18
|
+
return "contains an unpaired surrogate";
|
|
19
|
+
const bytes = encoded.length;
|
|
20
|
+
if (bytes < min)
|
|
21
|
+
return `is ${bytes} UTF-8 bytes, at least ${min} required`;
|
|
22
|
+
if (bytes > max)
|
|
23
|
+
return `is ${bytes} UTF-8 bytes, at most ${max} allowed`;
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
function htmlProblem(html) {
|
|
27
|
+
const problem = textProblem(html, TELEGRAM_WIDGET_LIMITS2.htmlBytes, 1);
|
|
28
|
+
if (problem !== undefined)
|
|
29
|
+
return problem;
|
|
30
|
+
const compressed = deflateSync(html, { level: 9 }).byteLength;
|
|
31
|
+
return compressed > TELEGRAM_WIDGET_LIMITS2.compressedHtmlBytes ? `compresses to ${compressed} bytes, at most ${TELEGRAM_WIDGET_LIMITS2.compressedHtmlBytes} allowed` : undefined;
|
|
32
|
+
}
|
|
33
|
+
function widgetText(problemOf) {
|
|
34
|
+
return z.string().superRefine((value, context) => {
|
|
35
|
+
const problem = problemOf(value);
|
|
36
|
+
if (problem !== undefined)
|
|
37
|
+
context.addIssue({ code: "custom", message: `Text ${problem}` });
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
var TelegramWidgetHtmlSchema2 = widgetText(htmlProblem);
|
|
41
|
+
var TelegramWidgetDataSchema2 = widgetText((value) => textProblem(value, TELEGRAM_WIDGET_LIMITS2.dataBytes));
|
|
42
|
+
var QueryDataSchema = widgetText((value) => textProblem(value, TELEGRAM_WIDGET_LIMITS2.queryDataBytes, 1));
|
|
43
|
+
var WalletSchema = z.looseObject({
|
|
44
|
+
address: z.string(),
|
|
45
|
+
amount: z.string(),
|
|
46
|
+
public_key: z.string().optional(),
|
|
47
|
+
state_init: z.string().optional()
|
|
48
|
+
});
|
|
49
|
+
var TelegramWidgetMessageSchema2 = z.looseObject({
|
|
50
|
+
message_id: z.int().nonnegative(),
|
|
51
|
+
chat: z.looseObject({ id: z.int(), type: z.string() }),
|
|
52
|
+
widget: z.looseObject({
|
|
53
|
+
html: z.string(),
|
|
54
|
+
id: z.string().optional(),
|
|
55
|
+
width: z.int().optional(),
|
|
56
|
+
height: z.int().optional(),
|
|
57
|
+
public_data: z.string().optional(),
|
|
58
|
+
chat_data: z.string().optional()
|
|
59
|
+
})
|
|
60
|
+
});
|
|
61
|
+
var TelegramWidgetQuerySchema2 = z.looseObject({
|
|
62
|
+
id: z.string().min(1),
|
|
63
|
+
from: z.looseObject({ id: z.int() }),
|
|
64
|
+
chat: z.looseObject({ id: z.int(), type: z.string() }).optional(),
|
|
65
|
+
message_id: z.int().optional(),
|
|
66
|
+
inline_message_id: z.string().optional(),
|
|
67
|
+
chat_instance: z.string(),
|
|
68
|
+
chat_type: z.string().optional(),
|
|
69
|
+
type: z.discriminatedUnion("type", [
|
|
70
|
+
z.looseObject({ type: z.literal("data"), wallet_card: z.looseObject({}).optional() }),
|
|
71
|
+
z.looseObject({
|
|
72
|
+
type: z.literal("sign_data"),
|
|
73
|
+
wallet: WalletSchema,
|
|
74
|
+
sign_data: z.string()
|
|
75
|
+
}),
|
|
76
|
+
z.looseObject({
|
|
77
|
+
type: z.literal("sent_transaction"),
|
|
78
|
+
wallet: WalletSchema,
|
|
79
|
+
msg_hash: z.string()
|
|
80
|
+
})
|
|
81
|
+
]),
|
|
82
|
+
data: QueryDataSchema,
|
|
83
|
+
widget_id: z.string().optional()
|
|
84
|
+
});
|
|
85
|
+
function parseTelegramWidgetQuery2(value) {
|
|
86
|
+
const parsed = TelegramWidgetQuerySchema2.safeParse(value);
|
|
87
|
+
if (parsed.success)
|
|
88
|
+
return { query: parsed.data };
|
|
89
|
+
const id = typeof value === "object" && value !== null ? Reflect.get(value, "id") : undefined;
|
|
90
|
+
return typeof id === "string" && id.length > 0 ? { id, error: parsed.error } : undefined;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export { TELEGRAM_WIDGET_LIMITS2, TelegramWidgetHtmlSchema2, TelegramWidgetDataSchema2, TelegramWidgetMessageSchema2, TelegramWidgetQuerySchema2, parseTelegramWidgetQuery2 };
|
|
@@ -1,10 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
isTelegramNotDispatched
|
|
3
|
-
} from "./index-6j725ez5.js";
|
|
4
1
|
import {
|
|
5
2
|
isRecord
|
|
6
3
|
} from "./index-hkxgennw.js";
|
|
7
4
|
|
|
5
|
+
// src/telegram/not-dispatched.ts
|
|
6
|
+
class TelegramNotDispatchedError2 extends Error {
|
|
7
|
+
stage;
|
|
8
|
+
name = "TelegramNotDispatchedError";
|
|
9
|
+
code = "TELEGRAM_NOT_DISPATCHED";
|
|
10
|
+
constructor(stage, message, options) {
|
|
11
|
+
super(message, options);
|
|
12
|
+
this.stage = stage;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function isTelegramNotDispatchedError(error) {
|
|
16
|
+
return error instanceof TelegramNotDispatchedError2 || error instanceof Error && error.name === "TelegramNotDispatchedError" && Reflect.get(error, "code") === "TELEGRAM_NOT_DISPATCHED";
|
|
17
|
+
}
|
|
18
|
+
function isTelegramNotDispatched(error, depth = 0) {
|
|
19
|
+
if (error instanceof TelegramNotDispatchedError2)
|
|
20
|
+
return true;
|
|
21
|
+
if (typeof error !== "object" || error === null || depth > 4)
|
|
22
|
+
return false;
|
|
23
|
+
if (Reflect.get(error, "code") === "TELEGRAM_NOT_DISPATCHED")
|
|
24
|
+
return true;
|
|
25
|
+
const nested = Reflect.get(error, "cause") ?? Reflect.get(error, "error");
|
|
26
|
+
return nested !== error && isTelegramNotDispatched(nested, depth + 1);
|
|
27
|
+
}
|
|
28
|
+
|
|
8
29
|
// src/telegram/send-failure.ts
|
|
9
30
|
var BY_DESCRIPTION = [
|
|
10
31
|
[/bot was blocked by the user|bot was kicked/i, "blocked-by-user"],
|
|
@@ -147,6 +168,8 @@ var EDIT_REFUSALS = [
|
|
|
147
168
|
[/query is too old|query id is invalid/i, "query-expired"]
|
|
148
169
|
];
|
|
149
170
|
function classifyTelegramEditRefusal(error) {
|
|
171
|
+
if (isTelegramNotDispatched(error))
|
|
172
|
+
return "other";
|
|
150
173
|
const description = descriptionOf(error);
|
|
151
174
|
for (const [pattern, refusal] of EDIT_REFUSALS) {
|
|
152
175
|
if (pattern.test(description))
|
|
@@ -155,4 +178,4 @@ function classifyTelegramEditRefusal(error) {
|
|
|
155
178
|
return "other";
|
|
156
179
|
}
|
|
157
180
|
|
|
158
|
-
export { TELEGRAM_SEND_FAILURE_REASONS2, classifyTelegramSendFailure2, classifyTelegramEditRefusal };
|
|
181
|
+
export { TelegramNotDispatchedError2, isTelegramNotDispatchedError, TELEGRAM_SEND_FAILURE_REASONS2, classifyTelegramSendFailure2, classifyTelegramEditRefusal };
|
|
@@ -96,8 +96,8 @@ export declare function classifyTelegramSendFailure(error: unknown): TelegramSen
|
|
|
96
96
|
* - `other`: everything else, including a malformed payload — the caller's to
|
|
97
97
|
* raise.
|
|
98
98
|
*
|
|
99
|
-
* Internal to the screens: it reads Telegram's prose the
|
|
100
|
-
* {@link classifyTelegramSendFailure} does and is not a public vocabulary.
|
|
99
|
+
* Internal to the screens and the widget edit: it reads Telegram's prose the
|
|
100
|
+
* same way {@link classifyTelegramSendFailure} does and is not a public vocabulary.
|
|
101
101
|
*/
|
|
102
102
|
export type TelegramEditRefusal = 'not-modified' | 'message-gone' | 'message-locked' | 'query-expired' | 'other';
|
|
103
103
|
export declare function classifyTelegramEditRefusal(error: unknown): TelegramEditRefusal;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"send-failure.d.ts","sourceRoot":"","sources":["../../src/telegram/send-failure.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAKH;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,yBAAyB,GACjC,iBAAiB,GACjB,kBAAkB,GAClB,gBAAgB,GAChB,aAAa,GACb,qBAAqB,GACrB,cAAc,GACd,iBAAiB,GACjB,cAAc,GACd,gB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AwD;IACxD,SAAS,EAAE,OAAO,CAAC;IACnB;;;;;;;;OAQG;IACH,oBAAoB,EAAE,OAAO,CAAC;IAC9B;;;;;OAKG;IACH,QAAQ,EAAE,YAAY,GAAG,QAAQ,GAAG,aAAa,GAAG,WAAW,GAAG,MAAM,CAAC;CAC1E;AAoDD;;;;GAIG;AACH,eAAO,MAAM,6BAA6B,EAAE,SAAS,yBAAyB,EAC7B,CAAC;AA4ClD;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,OAAO,GAAG,mBAAmB,CA4D/E;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,mBAAmB,GAC3B,cAAc,GACd,cAAc,GACd,gBAAgB,GAChB,eAAe,GACf,OAAO,CAAC;AAeZ,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,OAAO,GAAG,mBAAmB,CAQ/E"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The three Bot API 10.4 widget methods over a grammY client the bot already has.
|
|
3
|
+
*
|
|
4
|
+
* grammY 1.46 does not type `sendWidget`, `editMessageWidgetData` or
|
|
5
|
+
* `answerWidgetQuery`, and a bot that reaches for them builds a second client
|
|
6
|
+
* or a second token reader, and with it a second limiter. `api.raw` needs none:
|
|
7
|
+
* grammY's proxy sends any method name through the client's own transformers —
|
|
8
|
+
* the outbound budget, a sandbox, error capture — so a widget send waits for
|
|
9
|
+
* the same slot as every other message of the token and an answer, which costs
|
|
10
|
+
* no message, does not.
|
|
11
|
+
*
|
|
12
|
+
* The methods keep the Bot API's names and parameters, so the call reads as the
|
|
13
|
+
* grammY call it will become once grammY types it, and a new Telegram parameter
|
|
14
|
+
* needs no second name here. Each call:
|
|
15
|
+
*
|
|
16
|
+
* 1. checks its input against Telegram's limits and throws `ZodError` — nothing
|
|
17
|
+
* was sent, and the same input will be refused again;
|
|
18
|
+
* 2. throws `TelegramNotDispatchedError` when the signal is already aborted —
|
|
19
|
+
* nothing was sent, and it is safe to send again;
|
|
20
|
+
* 3. hands the request to the client once. It never repeats it: a failure after
|
|
21
|
+
* this point may have been delivered, and a send whose outcome is unknown is
|
|
22
|
+
* the caller's to settle;
|
|
23
|
+
* 4. parses Telegram's answer. An unexpected successful answer is an ordinary
|
|
24
|
+
* error with the parse failure as its `cause` — the request was sent.
|
|
25
|
+
*
|
|
26
|
+
* grammY is named in the declarations and never imported at run time.
|
|
27
|
+
*/
|
|
28
|
+
import type { Api, RawApi } from 'grammy';
|
|
29
|
+
import type { ForceReply, InlineKeyboardMarkup, MessageEntity, ParseMode, ReplyKeyboardMarkup, ReplyKeyboardRemove, ReplyParameters } from 'grammy/types';
|
|
30
|
+
import { type TelegramWidgetMessage } from './widget.js';
|
|
31
|
+
/** `sendWidget` parameters, as the Bot API names them. */
|
|
32
|
+
export interface TelegramSendWidgetParams {
|
|
33
|
+
readonly chat_id: number | string;
|
|
34
|
+
/** The forum topic, for forum supergroups and private chats with topics. */
|
|
35
|
+
readonly message_thread_id?: number;
|
|
36
|
+
/** 1–32768 UTF-8 bytes, at most 4096 once compressed by zlib level 9. */
|
|
37
|
+
readonly html: string;
|
|
38
|
+
/** Logical pixels; omitted, the widget takes the bubble's width. */
|
|
39
|
+
readonly width?: number;
|
|
40
|
+
/** Logical pixels; omitted, the height is not fixed. */
|
|
41
|
+
readonly height?: number;
|
|
42
|
+
/** 0–1024 UTF-8 bytes, visible wherever the widget is shown. */
|
|
43
|
+
readonly public_data?: string;
|
|
44
|
+
/** 0–1024 UTF-8 bytes, specific to this message. */
|
|
45
|
+
readonly chat_data?: string;
|
|
46
|
+
/** Shown by an app that cannot draw the widget too; 0–1024 characters. */
|
|
47
|
+
readonly caption?: string;
|
|
48
|
+
readonly parse_mode?: ParseMode;
|
|
49
|
+
readonly caption_entities?: readonly MessageEntity[];
|
|
50
|
+
readonly show_caption_above_media?: boolean;
|
|
51
|
+
/** Let the widget send queries to the bot. */
|
|
52
|
+
readonly allow_queries?: boolean;
|
|
53
|
+
readonly disable_notification?: boolean;
|
|
54
|
+
readonly protect_content?: boolean;
|
|
55
|
+
readonly allow_paid_broadcast?: boolean;
|
|
56
|
+
readonly message_effect_id?: string;
|
|
57
|
+
readonly reply_parameters?: ReplyParameters;
|
|
58
|
+
readonly reply_markup?: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* `editMessageWidgetData` parameters, as the Bot API names them: a chat message
|
|
62
|
+
* (`chat_id` with `message_id`) or an inline one, and the data that changes —
|
|
63
|
+
* an empty string removes it, an omitted field keeps it.
|
|
64
|
+
*/
|
|
65
|
+
export type TelegramEditMessageWidgetDataParams = ({
|
|
66
|
+
readonly chat_id: number | string;
|
|
67
|
+
readonly message_id: number;
|
|
68
|
+
readonly inline_message_id?: never;
|
|
69
|
+
} | {
|
|
70
|
+
readonly inline_message_id: string;
|
|
71
|
+
readonly chat_id?: never;
|
|
72
|
+
readonly message_id?: never;
|
|
73
|
+
}) & ({
|
|
74
|
+
readonly chat_data: string;
|
|
75
|
+
readonly public_data?: string;
|
|
76
|
+
} | {
|
|
77
|
+
readonly public_data: string;
|
|
78
|
+
readonly chat_data?: string;
|
|
79
|
+
});
|
|
80
|
+
/** `answerWidgetQuery` parameters, as the Bot API names them. */
|
|
81
|
+
export interface TelegramAnswerWidgetQueryParams {
|
|
82
|
+
readonly widget_query_id: string;
|
|
83
|
+
/** 0–1024 UTF-8 bytes; the widget that asked receives it, its data does not change. */
|
|
84
|
+
readonly data?: string;
|
|
85
|
+
}
|
|
86
|
+
/** Per-call options of {@link TelegramWidgetApi}. */
|
|
87
|
+
export interface TelegramWidgetCallOptions {
|
|
88
|
+
/** Cancels the call; before the request leaves, it fails as not dispatched. */
|
|
89
|
+
readonly signal?: AbortSignal;
|
|
90
|
+
}
|
|
91
|
+
/** The widget methods of one grammY client. */
|
|
92
|
+
export interface TelegramWidgetApi {
|
|
93
|
+
/** Send a widget message. Resolves to the sent message with its widget. */
|
|
94
|
+
sendWidget(params: TelegramSendWidgetParams, options?: TelegramWidgetCallOptions): Promise<TelegramWidgetMessage>;
|
|
95
|
+
/** Change a widget's data. Data already as asked (`message is not modified`) is success. */
|
|
96
|
+
editMessageWidgetData(params: TelegramEditMessageWidgetDataParams, options?: TelegramWidgetCallOptions): Promise<void>;
|
|
97
|
+
/** Answer a widget query; costs no message and waits for no outbound budget. */
|
|
98
|
+
answerWidgetQuery(params: TelegramAnswerWidgetQueryParams, options?: TelegramWidgetCallOptions): Promise<void>;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The widget methods of `api`, run through its transformers: install
|
|
102
|
+
* `telegramBudgetTransformer` on the client and widget sends share the token's
|
|
103
|
+
* budget.
|
|
104
|
+
*/
|
|
105
|
+
export declare function telegramWidgetApi(api: Pick<Api<RawApi>, 'raw'>): TelegramWidgetApi;
|
|
106
|
+
//# sourceMappingURL=widget-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widget-api.d.ts","sourceRoot":"","sources":["../../src/telegram/widget-api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,KAAK,EACV,UAAU,EACV,oBAAoB,EACpB,aAAa,EACb,SAAS,EACT,mBAAmB,EACnB,mBAAmB,EACnB,eAAe,EAChB,MAAM,cAAc,CAAC;AAItB,OAAO,EAGL,KAAK,qBAAqB,EAE3B,MAAM,UAAU,CAAC;AAElB,0DAA0D;AAC1D,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IAClC,4EAA4E;IAC5E,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IACpC,yEAAyE;IACzE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;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CAAC,UAAU,CAAC,EAAE,KAAK,CAAC;CAC7B,CACJ,GACC,CACI;IAAE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,GAC7D;IAAE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,CAChE,CAAC;AAEJ,iEAAiE;AACjE,MAAM,WAAW,+BAA+B;IAC9C,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,uFAAuF;IACvF,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,qDAAqD;AACrD,MAAM,WAAW,yBAAyB;IACxC,+EAA+E;IAC/E,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC/B;AAED,+CAA+C;AAC/C,MAAM,WAAW,iBAAiB;IAChC,2EAA2E;IAC3E,UAAU,CACR,MAAM,EAAE,wBAAwB,EAChC,OAAO,CAAC,EAAE,yBAAyB,GAClC,OAAO,CAAC,qBAAqB,CAAC,CAAC;IAClC,4FAA4F;IAC5F,qBAAqB,CACnB,MAAM,EAAE,mCAAmC,EAC3C,OAAO,CAAC,EAAE,yBAAyB,GAClC,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,gFAAgF;IAChF,iBAAiB,CACf,MAAM,EAAE,+BAA+B,EACvC,OAAO,CAAC,EAAE,yBAAyB,GAClC,OAAO,CAAC,IAAI,CAAC,CAAC;CAClB;AA4ED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,GAAG,iBAAiB,CA2BlF"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telegram widgets (Bot API 10.4): the limits a widget message must keep and
|
|
3
|
+
* the shapes Telegram sends back, for both sides of a bot.
|
|
4
|
+
*
|
|
5
|
+
* A widget is HTML that the Telegram app runs and draws inside a message. Every
|
|
6
|
+
* limit is counted in UTF-8 bytes, not in JavaScript characters, so a string
|
|
7
|
+
* that looks short in an editor can still be refused: one emoji is four bytes,
|
|
8
|
+
* one Cyrillic letter two. The schemas here check a value before any request,
|
|
9
|
+
* so a refusal names its field and size instead of coming back as a 400.
|
|
10
|
+
*
|
|
11
|
+
* What Telegram sends is parsed loosely: only the fields used here are checked,
|
|
12
|
+
* and the rest pass through, because every Bot API release adds fields to a
|
|
13
|
+
* message, a user and a chat, and a strict parse of a successful send would
|
|
14
|
+
* turn a delivered widget into an unknown outcome.
|
|
15
|
+
*/
|
|
16
|
+
import { z } from 'zod';
|
|
17
|
+
/** The widget limits Telegram states, in UTF-8 bytes unless named otherwise. */
|
|
18
|
+
export declare const TELEGRAM_WIDGET_LIMITS: Readonly<{
|
|
19
|
+
/** Widget HTML, 1 to 32768 bytes. */
|
|
20
|
+
htmlBytes: 32768;
|
|
21
|
+
/** Widget HTML after zlib at the maximum compression level. */
|
|
22
|
+
compressedHtmlBytes: 4096;
|
|
23
|
+
/** `chat_data`, `public_data` and a query answer, 0 to 1024 bytes each. */
|
|
24
|
+
dataBytes: 1024;
|
|
25
|
+
/** The data a widget sends with a query, 1 to 64 bytes. */
|
|
26
|
+
queryDataBytes: 64;
|
|
27
|
+
/** How long Telegram waits for the answer to a widget query. */
|
|
28
|
+
answerWindowMs: 15000;
|
|
29
|
+
}>;
|
|
30
|
+
/**
|
|
31
|
+
* Widget HTML: 1–32768 UTF-8 bytes, no NUL, and at most 4096 once compressed by
|
|
32
|
+
* this runtime's zlib at level 9 — an estimate of Telegram's, so keep a margin.
|
|
33
|
+
*/
|
|
34
|
+
export declare const TelegramWidgetHtmlSchema: z.ZodString;
|
|
35
|
+
/** `chat_data`, `public_data` or a query answer: 0–1024 UTF-8 bytes, no NUL. */
|
|
36
|
+
export declare const TelegramWidgetDataSchema: z.ZodString;
|
|
37
|
+
/**
|
|
38
|
+
* Telegram's widget message: the sent `Message` with its `widget`. Only the
|
|
39
|
+
* fields a sender needs are checked — where the message is and what it holds.
|
|
40
|
+
*/
|
|
41
|
+
export declare const TelegramWidgetMessageSchema: z.ZodObject<{
|
|
42
|
+
message_id: z.ZodInt;
|
|
43
|
+
chat: z.ZodObject<{
|
|
44
|
+
id: z.ZodInt;
|
|
45
|
+
type: z.ZodString;
|
|
46
|
+
}, z.core.$loose>;
|
|
47
|
+
widget: z.ZodObject<{
|
|
48
|
+
html: z.ZodString;
|
|
49
|
+
id: z.ZodOptional<z.ZodString>;
|
|
50
|
+
width: z.ZodOptional<z.ZodInt>;
|
|
51
|
+
height: z.ZodOptional<z.ZodInt>;
|
|
52
|
+
public_data: z.ZodOptional<z.ZodString>;
|
|
53
|
+
chat_data: z.ZodOptional<z.ZodString>;
|
|
54
|
+
}, z.core.$loose>;
|
|
55
|
+
}, z.core.$loose>;
|
|
56
|
+
/** A sent widget message as Telegram returns it; fields not checked here pass through. */
|
|
57
|
+
export type TelegramWidgetMessage = z.infer<typeof TelegramWidgetMessageSchema>;
|
|
58
|
+
/**
|
|
59
|
+
* `Update.widget_query`: a query from a widget in a message the bot sent. The
|
|
60
|
+
* message is `chat` with `message_id`, or `inline_message_id` for an inline
|
|
61
|
+
* one; `from` is filled in by Telegram. `type` is one of the three kinds the
|
|
62
|
+
* Bot API documents; a kind it adds later fails this schema, and
|
|
63
|
+
* {@link parseTelegramWidgetQuery} still returns the query's id so it can be
|
|
64
|
+
* refused instead of left to time out.
|
|
65
|
+
*/
|
|
66
|
+
export declare const TelegramWidgetQuerySchema: z.ZodObject<{
|
|
67
|
+
id: z.ZodString;
|
|
68
|
+
from: z.ZodObject<{
|
|
69
|
+
id: z.ZodInt;
|
|
70
|
+
}, z.core.$loose>;
|
|
71
|
+
chat: z.ZodOptional<z.ZodObject<{
|
|
72
|
+
id: z.ZodInt;
|
|
73
|
+
type: z.ZodString;
|
|
74
|
+
}, z.core.$loose>>;
|
|
75
|
+
message_id: z.ZodOptional<z.ZodInt>;
|
|
76
|
+
inline_message_id: z.ZodOptional<z.ZodString>;
|
|
77
|
+
chat_instance: z.ZodString;
|
|
78
|
+
chat_type: z.ZodOptional<z.ZodString>;
|
|
79
|
+
type: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
80
|
+
type: z.ZodLiteral<"data">;
|
|
81
|
+
wallet_card: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
82
|
+
}, z.core.$loose>, z.ZodObject<{
|
|
83
|
+
type: z.ZodLiteral<"sign_data">;
|
|
84
|
+
wallet: z.ZodObject<{
|
|
85
|
+
address: z.ZodString;
|
|
86
|
+
amount: z.ZodString;
|
|
87
|
+
public_key: z.ZodOptional<z.ZodString>;
|
|
88
|
+
state_init: z.ZodOptional<z.ZodString>;
|
|
89
|
+
}, z.core.$loose>;
|
|
90
|
+
sign_data: z.ZodString;
|
|
91
|
+
}, z.core.$loose>, z.ZodObject<{
|
|
92
|
+
type: z.ZodLiteral<"sent_transaction">;
|
|
93
|
+
wallet: z.ZodObject<{
|
|
94
|
+
address: z.ZodString;
|
|
95
|
+
amount: z.ZodString;
|
|
96
|
+
public_key: z.ZodOptional<z.ZodString>;
|
|
97
|
+
state_init: z.ZodOptional<z.ZodString>;
|
|
98
|
+
}, z.core.$loose>;
|
|
99
|
+
msg_hash: z.ZodString;
|
|
100
|
+
}, z.core.$loose>], "type">;
|
|
101
|
+
data: z.ZodString;
|
|
102
|
+
widget_id: z.ZodOptional<z.ZodString>;
|
|
103
|
+
}, z.core.$loose>;
|
|
104
|
+
/** One widget query, as `TelegramWidgetQuerySchema` reads it. */
|
|
105
|
+
export type TelegramWidgetQuery = z.infer<typeof TelegramWidgetQuerySchema>;
|
|
106
|
+
/**
|
|
107
|
+
* A parsed widget query, or the id of one that did not parse together with why.
|
|
108
|
+
* The id is enough to answer: an unparsed query still gets a refusal.
|
|
109
|
+
*/
|
|
110
|
+
export type TelegramWidgetQueryParse = {
|
|
111
|
+
readonly query: TelegramWidgetQuery;
|
|
112
|
+
} | {
|
|
113
|
+
readonly id: string;
|
|
114
|
+
readonly error: z.ZodError;
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Read `update.widget_query`. Returns the query, the id and parse error of one
|
|
118
|
+
* that does not match, or `undefined` when there is no query id to answer.
|
|
119
|
+
*/
|
|
120
|
+
export declare function parseTelegramWidgetQuery(value: unknown): TelegramWidgetQueryParse | undefined;
|
|
121
|
+
//# sourceMappingURL=widget.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widget.d.ts","sourceRoot":"","sources":["../../src/telegram/widget.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,gFAAgF;AAChF,eAAO,MAAM,sBAAsB;IACjC,qCAAqC;;IAErC,+DAA+D;;IAE/D,2EAA2E;;IAE3E,2DAA2D;;IAE3D,gEAAgE;;EAEhE,CAAC;AA6CH;;;GAGG;AACH,eAAO,MAAM,wBAAwB,aAA0B,CAAC;AAEhE,gFAAgF;AAChF,eAAO,MAAM,wBAAwB,aAEpC,CAAC;AAeF;;;GAGG;AACH,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;iBAYtC,CAAC;AACH,0FAA0F;AAC1F,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAEhF;;;;;;;GAOG;AACH,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAyBpC,CAAC;AACH,iEAAiE;AACjE,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAE5E;;;GAGG;AACH,MAAM,MAAM,wBAAwB,GAChC;IAAE,QAAQ,CAAC,KAAK,EAAE,mBAAmB,CAAA;CAAE,GACvC;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,QAAQ,CAAA;CAAE,CAAC;AAExD;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,OAAO,GACb,wBAAwB,GAAG,SAAS,CAMtC"}
|
package/llms/stitchkit.txt
CHANGED
|
@@ -78,8 +78,8 @@ own, recorded as an ADR.
|
|
|
78
78
|
| `stitchkit/process/owner-loss` | bundled server entry (Bun, POSIX) | evolving | narrow bootstrap that keeps the process runner lazy while carrying its owner-loss guard in a single-file bundle |
|
|
79
79
|
| `stitchkit/files/packaging` | build time (Bun or Node) | evolving | installed native asset graph, integrity, Bun packaging plugin and the artifact loader check; a client bundled into one self-contained, hashed and verified file; no runtime install policy |
|
|
80
80
|
| `stitchkit/files` | server (Bun or Node) | stable | peer-free managed local-file boundary |
|
|
81
|
-
| `stitchkit/telegram` | server (Bun or Node) | evolving | peer-free Telegram platform primitives — Mini App `initData` verification, send-failure classification, one outbound budget per bot token with weighted albums and per-chat 429 pauses, resumable broadcasts, the operator channel with dedupe, a Bot API transport that separates a request that never left from an unknown outcome, local Bot API files, the waveform of a voice message read from its PCM, webhook ownership and durable webhook update intake |
|
|
82
|
-
| `stitchkit/telegram/grammy` | server (Bun or Node) | evolving | the token's outbound budget as one grammY client transformer — a 429 that comes back as a response pauses its chat, and a cancelled wait is a request that never left |
|
|
81
|
+
| `stitchkit/telegram` | server (Bun or Node) | evolving | peer-free Telegram platform primitives — Mini App `initData` verification, widget limits and the `widget_query` and widget message schemas, send-failure classification, one outbound budget per bot token with weighted albums and per-chat 429 pauses, resumable broadcasts, the operator channel with dedupe, a Bot API transport that separates a request that never left from an unknown outcome, local Bot API files, the waveform of a voice message read from its PCM, webhook ownership and durable webhook update intake |
|
|
82
|
+
| `stitchkit/telegram/grammy` | server (Bun or Node) | evolving | the token's outbound budget as one grammY client transformer — a 429 that comes back as a response pauses its chat, and a cancelled wait is a request that never left; the widget methods over the same client |
|
|
83
83
|
| `stitchkit/telegram/html` | browser and server | evolving | Telegram's HTML as a tree — clean any markup to what Telegram accepts, cut long text into valid parts by what the reader sees, check markup before it is sent |
|
|
84
84
|
| `stitchkit/telegram/voice` | browser and server | evolving | the waveform of a voice message as one format — packed for `sendVoice` the way Telegram Desktop scales it, unpacked to draw it, a `getMe` read of whether the server takes it |
|
|
85
85
|
| `stitchkit/telegram/screens` | server (Bun or Node) | evolving | a bot's menus as declared screens over grammY — typed paths, actions and input, message reconciliation, state in any `StorageAdapter`, a test chat |
|
package/llms/telegram-grammy.txt
CHANGED
|
@@ -5,18 +5,25 @@
|
|
|
5
5
|
|
|
6
6
|
Contains: API reference: `stitchkit/telegram/grammy` (docs/api/reference.md)
|
|
7
7
|
|
|
8
|
+
Also read:
|
|
9
|
+
- see `llms/telegram.txt` for the Telegram bots guide
|
|
10
|
+
|
|
8
11
|
==============================================================================
|
|
9
12
|
# API reference: `stitchkit/telegram/grammy` (docs/api/reference.md)
|
|
10
13
|
==============================================================================
|
|
11
14
|
|
|
12
15
|
## `stitchkit/telegram/grammy`
|
|
13
16
|
|
|
14
|
-
The token's outbound budget as one grammY client transformer
|
|
15
|
-
or Node; `grammy` appears in the
|
|
16
|
-
the bot brings it. → ADR 0274 —
|
|
17
|
+
The token's outbound budget as one grammY client transformer, and the widget
|
|
18
|
+
methods over the same client. Server-only, Bun or Node; `grammy` appears in the
|
|
19
|
+
declarations and is never imported at run time — the bot brings it. → ADR 0274 —
|
|
20
|
+
[guide](../guide/telegram.md#one-token-one-outbound-budget), [widgets](../guide/telegram.md#widgets)
|
|
17
21
|
|
|
18
22
|
| Export | Kind | Summary |
|
|
19
23
|
|--------|------|---------|
|
|
20
24
|
| `telegramBudgetTransformer` | function | `bot.api.config.use(telegramBudgetTransformer(budget))`: every Bot API call runs under the token's `telegramOutboundBudget`; a 429 that comes back as a response pauses the token, a cancellation before the request was handed on throws `TelegramNotDispatchedError`, a cancellation in flight stays the client's own error; it never retries |
|
|
25
|
+
| `telegramWidgetApi` / `TelegramWidgetApi` | function / _type_ | `telegramWidgetApi(bot.api)`: `sendWidget`, `editMessageWidgetData` and `answerWidgetQuery` through the client's `api.raw`, so its transformers — the outbound budget among them — run each call; input over a limit throws `ZodError` before any request, an already aborted signal throws `TelegramNotDispatchedError`, a request is handed on once and never repeated, `message is not modified` is success, and an unexpected successful answer is an error whose outcome is unknown |
|
|
26
|
+
| `TelegramSendWidgetParams` / `TelegramEditMessageWidgetDataParams` / `TelegramAnswerWidgetQueryParams` | _type_ | the methods' Bot API parameters by their Bot API names; an edit names `chat_id` with `message_id` or `inline_message_id`, and `chat_data` or `public_data` (`''` removes it, an omitted field keeps it) |
|
|
27
|
+
| `TelegramWidgetCallOptions` | _type_ | `signal` for one call: aborted before the request leaves, the call is not dispatched |
|
|
21
28
|
|
|
22
29
|
---
|
package/llms/telegram.2.txt
CHANGED
|
@@ -67,5 +67,10 @@ injected grammY bot. → ADR 0143, ADR 0201, ADR 0274 — [guide](../guide/teleg
|
|
|
67
67
|
| `postgresTelegramUpdateStore` / `PostgresTelegramUpdateStoreConfig` / `TelegramPostgresQuery` | function / _type_ | the store in Postgres over the client the application holds, as one `query(text, parameters)` returning rows — Bun `sql.unsafe`, Prisma `$queryRawUnsafe`, `pg` `pool.query`; each rule one conditional statement; `table`, `createTable` (default `true`) |
|
|
68
68
|
| `postgresTelegramUpdateStoreSchema` | function | the table, idempotent `claim_id` upgrade and index as a statement for a migration, safe to run twice; required before fenced methods when `createTable: false`, while legacy base methods remain compatible with the prior table |
|
|
69
69
|
| `checkTelegramUpdateStore` | function | put any store through every rule, each on a fresh store from `make`, concurrent claims included; resolves with the violations, empty when it keeps them |
|
|
70
|
+
| `TELEGRAM_WIDGET_LIMITS` | constant | Bot API 10.4 widget limits, sizes in UTF-8 bytes: `htmlBytes` 32768, `compressedHtmlBytes` 4096 after zlib level 9 (checked with the runtime's zlib, an estimate of Telegram's), `dataBytes` 1024 for `chat_data`, `public_data` and an answer, `queryDataBytes` 64, `answerWindowMs` 15 000 — [guide](../guide/telegram.md#widgets) |
|
|
71
|
+
| `TelegramWidgetHtmlSchema` / `TelegramWidgetDataSchema` | schema | widget HTML (1–32768 bytes, at most 4096 compressed) and widget data (0–1024 bytes), counted in UTF-8 bytes; NUL and an unpaired surrogate are refused, an empty data string is a value |
|
|
72
|
+
| `TelegramWidgetMessageSchema` / `TelegramWidgetMessage` | schema / _type_ | the message `sendWidget` returns — `message_id`, `chat`, `widget` with `html` and its data; parsed loosely, so fields Telegram adds pass through |
|
|
73
|
+
| `TelegramWidgetQuerySchema` / `TelegramWidgetQuery` | schema / _type_ | `Update.widget_query`: `id`, `from`, `chat` with `message_id` or `inline_message_id`, `chat_instance`, `type` (`data` / `sign_data` / `sent_transaction`), `data` of 1–64 bytes, `widget_id` |
|
|
74
|
+
| `parseTelegramWidgetQuery` / `TelegramWidgetQueryParse` | function / _type_ | read `update.widget_query`: `{ query }`, or `{ id, error }` for a query that does not parse — its id is enough to answer it with a refusal — or `undefined` without an id |
|
|
70
75
|
|
|
71
76
|
---
|
package/llms/telegram.txt
CHANGED
|
@@ -29,6 +29,7 @@ way: [ADR 0201](../decisions/0201-a-telegram-bot-is-assembled-from-primitives.md
|
|
|
29
29
|
| the bot as resources: command menu, then long polling with updates admitted by batch | `grammyBotResources` — [application kernel](application-kernel.md#optional-grammy-adapter) |
|
|
30
30
|
| a bot on a webhook: set only where it is this process's, updates recorded before Telegram is answered | `claimTelegramWebhook`, `createTelegramUpdateIntake`, `receiveTelegramWebhook` — [below](#a-bot-on-a-webhook) |
|
|
31
31
|
| text for Telegram's HTML: cleaned, cut to the limit, checked | `stitchkit/telegram/html` — [below](#message-markup) |
|
|
32
|
+
| widgets: send, change their data, answer their queries, under the token's budget | `telegramWidgetApi` from `stitchkit/telegram/grammy` — [below](#widgets) |
|
|
32
33
|
| the process journal | `createJsonLogger` from `stitchkit/observability` |
|
|
33
34
|
| the operator's chat: product events, apart from the journal | `createTelegramOperatorChannel` |
|
|
34
35
|
| a broadcast that survives crashes, deploys and Ctrl-C | `runTelegramBroadcast` |
|
|
@@ -393,6 +394,75 @@ round waits `connectAttemptMs`, default 2 s). The answer must arrive within `res
|
|
|
393
394
|
`maxResponseBytes` (default 1 MiB). It speaks HTTP/1.1 over `https:`, and over `http:` for a
|
|
394
395
|
local Bot API server, and it uses no proxy: where the network needs one, keep `fetch`.
|
|
395
396
|
|
|
397
|
+
## Widgets
|
|
398
|
+
|
|
399
|
+
A widget (Bot API 10.4) is HTML that the Telegram app runs and draws inside a message, with data
|
|
400
|
+
of its own the bot changes and queries it sends to the bot. grammY 1.46 does not type the three
|
|
401
|
+
methods, and a bot that reaches for them tends to build a second client and with it a second
|
|
402
|
+
limiter. `telegramWidgetApi` takes the client the bot already has and calls the methods through
|
|
403
|
+
its `api.raw`, so the client's transformers — the outbound budget among them — run every call:
|
|
404
|
+
|
|
405
|
+
```ts
|
|
406
|
+
import { telegramOutboundBudget } from 'stitchkit/telegram'
|
|
407
|
+
import { telegramBudgetTransformer, telegramWidgetApi } from 'stitchkit/telegram/grammy'
|
|
408
|
+
|
|
409
|
+
bot.api.config.use(telegramBudgetTransformer(telegramOutboundBudget({ token: env.BOT_TOKEN })))
|
|
410
|
+
const widgets = telegramWidgetApi(bot.api)
|
|
411
|
+
|
|
412
|
+
const message = await widgets.sendWidget(
|
|
413
|
+
{ chat_id, html, chat_data: state, allow_queries: true, reply_markup },
|
|
414
|
+
{ signal },
|
|
415
|
+
)
|
|
416
|
+
await widgets.editMessageWidgetData(
|
|
417
|
+
{ chat_id, message_id: message.message_id, chat_data: next },
|
|
418
|
+
{ signal },
|
|
419
|
+
)
|
|
420
|
+
await widgets.answerWidgetQuery({ widget_query_id: query.id, data: answer }, { signal })
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
The parameters are the Bot API's, by their Bot API names, so the call reads as the grammY call it
|
|
424
|
+
becomes once grammY types the method. A field is sent when it is not `undefined`: `chat_data: ''`
|
|
425
|
+
reaches Telegram and removes the data, an omitted field keeps it. An edit names `chat_id` with
|
|
426
|
+
`message_id`, or `inline_message_id`, and changes `chat_data`, `public_data` or both.
|
|
427
|
+
|
|
428
|
+
- **Limits are checked before the request, in UTF-8 bytes.** `TELEGRAM_WIDGET_LIMITS`: HTML 1–32768
|
|
429
|
+
bytes and at most 4096 after zlib level 9; `chat_data`, `public_data` and an answer 0–1024; query
|
|
430
|
+
data 1–64. One emoji is four bytes, one Cyrillic letter two. NUL and an unpaired surrogate are
|
|
431
|
+
refused too. A refused value throws `ZodError` naming its field and size: nothing was sent, and
|
|
432
|
+
the same input will be refused again, so a durable sender records it as failed rather than
|
|
433
|
+
retrying. `TelegramWidgetHtmlSchema` and `TelegramWidgetDataSchema` are the same checks for a
|
|
434
|
+
sender that wants its own margin first.
|
|
435
|
+
- **The compressed size is an estimate.** It is measured with the runtime's own zlib at level 9,
|
|
436
|
+
and zlib builds differ by tens of bytes near 4096 — Node's output is smaller than Bun's on the
|
|
437
|
+
same HTML — while Telegram does not say which it runs. HTML that compresses close to the limit
|
|
438
|
+
can pass here and be refused by Telegram; keep a margin below 4096.
|
|
439
|
+
- **A send and an edit cost one message; an answer costs none.** Telegram counts a data edit as a
|
|
440
|
+
sent message, so both wait for the token's schedule and a 429 pauses their chat; an inline edit
|
|
441
|
+
has no chat and a 429 on it pauses the token. `answerWidgetQuery` waits for no slot and no pause:
|
|
442
|
+
Telegram expects the answer within `TELEGRAM_WIDGET_LIMITS.answerWindowMs` (15 s).
|
|
443
|
+
- **What happens to a call is said by its error.** An already aborted `signal`, or one aborted
|
|
444
|
+
while the call waits for its slot, throws `TelegramNotDispatchedError` — nothing left, safe to
|
|
445
|
+
send again. A request handed to the client is never repeated: a failure after that point may
|
|
446
|
+
have been delivered, and a send whose outcome is unknown is the caller's to settle.
|
|
447
|
+
`message is not modified` on an edit is success. A successful answer that is not what the method
|
|
448
|
+
returns — `true` where a message was due, as a grammY webhook reply gives — is an error with the
|
|
449
|
+
parse failure as its `cause`: the request was sent and its outcome is unknown.
|
|
450
|
+
- **Queries are answered at intake.** `widget_query` must be in the webhook's or polling's
|
|
451
|
+
`allowed_updates`; grammY's `Update` type does not name it yet, so read
|
|
452
|
+
`update.widget_query` with `parseTelegramWidgetQuery`. It returns `{ query }`, or `{ id, error }`
|
|
453
|
+
for a query that does not parse — an unknown `type` or data outside 1–64 bytes — whose id is
|
|
454
|
+
enough to answer it with a refusal rather than leave the widget waiting, or `undefined` without
|
|
455
|
+
an id. Telegram's message, chat and query objects are parsed loosely: fields it adds later pass
|
|
456
|
+
through.
|
|
457
|
+
- **Shared widgets are not here.** `is_shared`, `sendSharedWidget`, `editSharedWidgetData` and
|
|
458
|
+
`shared_widget_query` are outside this API; in production Telegram sends widgets to private
|
|
459
|
+
chats only.
|
|
460
|
+
|
|
461
|
+
The installed
|
|
462
|
+
[`telegram-widget-api.mjs`](../../packages/core/scripts/consumer-lane/fixtures/minimal/src/telegram-widget-api.mjs)
|
|
463
|
+
fixture runs the packed methods through the packed budget transformer on Bun and Node with no
|
|
464
|
+
grammY installed.
|
|
465
|
+
|
|
396
466
|
## Message markup
|
|
397
467
|
|
|
398
468
|
`stitchkit/telegram/html` is Telegram's HTML parse mode as a tree, with no peer
|
package/llms-full.txt
CHANGED
|
@@ -69,8 +69,8 @@ own, recorded as an ADR.
|
|
|
69
69
|
| `stitchkit/process/owner-loss` | bundled server entry (Bun, POSIX) | evolving | narrow bootstrap that keeps the process runner lazy while carrying its owner-loss guard in a single-file bundle |
|
|
70
70
|
| `stitchkit/files/packaging` | build time (Bun or Node) | evolving | installed native asset graph, integrity, Bun packaging plugin and the artifact loader check; a client bundled into one self-contained, hashed and verified file; no runtime install policy |
|
|
71
71
|
| `stitchkit/files` | server (Bun or Node) | stable | peer-free managed local-file boundary |
|
|
72
|
-
| `stitchkit/telegram` | server (Bun or Node) | evolving | peer-free Telegram platform primitives — Mini App `initData` verification, send-failure classification, one outbound budget per bot token with weighted albums and per-chat 429 pauses, resumable broadcasts, the operator channel with dedupe, a Bot API transport that separates a request that never left from an unknown outcome, local Bot API files, the waveform of a voice message read from its PCM, webhook ownership and durable webhook update intake |
|
|
73
|
-
| `stitchkit/telegram/grammy` | server (Bun or Node) | evolving | the token's outbound budget as one grammY client transformer — a 429 that comes back as a response pauses its chat, and a cancelled wait is a request that never left |
|
|
72
|
+
| `stitchkit/telegram` | server (Bun or Node) | evolving | peer-free Telegram platform primitives — Mini App `initData` verification, widget limits and the `widget_query` and widget message schemas, send-failure classification, one outbound budget per bot token with weighted albums and per-chat 429 pauses, resumable broadcasts, the operator channel with dedupe, a Bot API transport that separates a request that never left from an unknown outcome, local Bot API files, the waveform of a voice message read from its PCM, webhook ownership and durable webhook update intake |
|
|
73
|
+
| `stitchkit/telegram/grammy` | server (Bun or Node) | evolving | the token's outbound budget as one grammY client transformer — a 429 that comes back as a response pauses its chat, and a cancelled wait is a request that never left; the widget methods over the same client |
|
|
74
74
|
| `stitchkit/telegram/html` | browser and server | evolving | Telegram's HTML as a tree — clean any markup to what Telegram accepts, cut long text into valid parts by what the reader sees, check markup before it is sent |
|
|
75
75
|
| `stitchkit/telegram/voice` | browser and server | evolving | the waveform of a voice message as one format — packed for `sendVoice` the way Telegram Desktop scales it, unpacked to draw it, a `getMe` read of whether the server takes it |
|
|
76
76
|
| `stitchkit/telegram/screens` | server (Bun or Node) | evolving | a bot's menus as declared screens over grammY — typed paths, actions and input, message reconciliation, state in any `StorageAdapter`, a test chat |
|
|
@@ -16559,6 +16559,7 @@ way: [ADR 0201](../decisions/0201-a-telegram-bot-is-assembled-from-primitives.md
|
|
|
16559
16559
|
| the bot as resources: command menu, then long polling with updates admitted by batch | `grammyBotResources` — [application kernel](application-kernel.md#optional-grammy-adapter) |
|
|
16560
16560
|
| a bot on a webhook: set only where it is this process's, updates recorded before Telegram is answered | `claimTelegramWebhook`, `createTelegramUpdateIntake`, `receiveTelegramWebhook` — [below](#a-bot-on-a-webhook) |
|
|
16561
16561
|
| text for Telegram's HTML: cleaned, cut to the limit, checked | `stitchkit/telegram/html` — [below](#message-markup) |
|
|
16562
|
+
| widgets: send, change their data, answer their queries, under the token's budget | `telegramWidgetApi` from `stitchkit/telegram/grammy` — [below](#widgets) |
|
|
16562
16563
|
| the process journal | `createJsonLogger` from `stitchkit/observability` |
|
|
16563
16564
|
| the operator's chat: product events, apart from the journal | `createTelegramOperatorChannel` |
|
|
16564
16565
|
| a broadcast that survives crashes, deploys and Ctrl-C | `runTelegramBroadcast` |
|
|
@@ -16923,6 +16924,75 @@ round waits `connectAttemptMs`, default 2 s). The answer must arrive within `res
|
|
|
16923
16924
|
`maxResponseBytes` (default 1 MiB). It speaks HTTP/1.1 over `https:`, and over `http:` for a
|
|
16924
16925
|
local Bot API server, and it uses no proxy: where the network needs one, keep `fetch`.
|
|
16925
16926
|
|
|
16927
|
+
## Widgets
|
|
16928
|
+
|
|
16929
|
+
A widget (Bot API 10.4) is HTML that the Telegram app runs and draws inside a message, with data
|
|
16930
|
+
of its own the bot changes and queries it sends to the bot. grammY 1.46 does not type the three
|
|
16931
|
+
methods, and a bot that reaches for them tends to build a second client and with it a second
|
|
16932
|
+
limiter. `telegramWidgetApi` takes the client the bot already has and calls the methods through
|
|
16933
|
+
its `api.raw`, so the client's transformers — the outbound budget among them — run every call:
|
|
16934
|
+
|
|
16935
|
+
```ts
|
|
16936
|
+
import { telegramOutboundBudget } from 'stitchkit/telegram'
|
|
16937
|
+
import { telegramBudgetTransformer, telegramWidgetApi } from 'stitchkit/telegram/grammy'
|
|
16938
|
+
|
|
16939
|
+
bot.api.config.use(telegramBudgetTransformer(telegramOutboundBudget({ token: env.BOT_TOKEN })))
|
|
16940
|
+
const widgets = telegramWidgetApi(bot.api)
|
|
16941
|
+
|
|
16942
|
+
const message = await widgets.sendWidget(
|
|
16943
|
+
{ chat_id, html, chat_data: state, allow_queries: true, reply_markup },
|
|
16944
|
+
{ signal },
|
|
16945
|
+
)
|
|
16946
|
+
await widgets.editMessageWidgetData(
|
|
16947
|
+
{ chat_id, message_id: message.message_id, chat_data: next },
|
|
16948
|
+
{ signal },
|
|
16949
|
+
)
|
|
16950
|
+
await widgets.answerWidgetQuery({ widget_query_id: query.id, data: answer }, { signal })
|
|
16951
|
+
```
|
|
16952
|
+
|
|
16953
|
+
The parameters are the Bot API's, by their Bot API names, so the call reads as the grammY call it
|
|
16954
|
+
becomes once grammY types the method. A field is sent when it is not `undefined`: `chat_data: ''`
|
|
16955
|
+
reaches Telegram and removes the data, an omitted field keeps it. An edit names `chat_id` with
|
|
16956
|
+
`message_id`, or `inline_message_id`, and changes `chat_data`, `public_data` or both.
|
|
16957
|
+
|
|
16958
|
+
- **Limits are checked before the request, in UTF-8 bytes.** `TELEGRAM_WIDGET_LIMITS`: HTML 1–32768
|
|
16959
|
+
bytes and at most 4096 after zlib level 9; `chat_data`, `public_data` and an answer 0–1024; query
|
|
16960
|
+
data 1–64. One emoji is four bytes, one Cyrillic letter two. NUL and an unpaired surrogate are
|
|
16961
|
+
refused too. A refused value throws `ZodError` naming its field and size: nothing was sent, and
|
|
16962
|
+
the same input will be refused again, so a durable sender records it as failed rather than
|
|
16963
|
+
retrying. `TelegramWidgetHtmlSchema` and `TelegramWidgetDataSchema` are the same checks for a
|
|
16964
|
+
sender that wants its own margin first.
|
|
16965
|
+
- **The compressed size is an estimate.** It is measured with the runtime's own zlib at level 9,
|
|
16966
|
+
and zlib builds differ by tens of bytes near 4096 — Node's output is smaller than Bun's on the
|
|
16967
|
+
same HTML — while Telegram does not say which it runs. HTML that compresses close to the limit
|
|
16968
|
+
can pass here and be refused by Telegram; keep a margin below 4096.
|
|
16969
|
+
- **A send and an edit cost one message; an answer costs none.** Telegram counts a data edit as a
|
|
16970
|
+
sent message, so both wait for the token's schedule and a 429 pauses their chat; an inline edit
|
|
16971
|
+
has no chat and a 429 on it pauses the token. `answerWidgetQuery` waits for no slot and no pause:
|
|
16972
|
+
Telegram expects the answer within `TELEGRAM_WIDGET_LIMITS.answerWindowMs` (15 s).
|
|
16973
|
+
- **What happens to a call is said by its error.** An already aborted `signal`, or one aborted
|
|
16974
|
+
while the call waits for its slot, throws `TelegramNotDispatchedError` — nothing left, safe to
|
|
16975
|
+
send again. A request handed to the client is never repeated: a failure after that point may
|
|
16976
|
+
have been delivered, and a send whose outcome is unknown is the caller's to settle.
|
|
16977
|
+
`message is not modified` on an edit is success. A successful answer that is not what the method
|
|
16978
|
+
returns — `true` where a message was due, as a grammY webhook reply gives — is an error with the
|
|
16979
|
+
parse failure as its `cause`: the request was sent and its outcome is unknown.
|
|
16980
|
+
- **Queries are answered at intake.** `widget_query` must be in the webhook's or polling's
|
|
16981
|
+
`allowed_updates`; grammY's `Update` type does not name it yet, so read
|
|
16982
|
+
`update.widget_query` with `parseTelegramWidgetQuery`. It returns `{ query }`, or `{ id, error }`
|
|
16983
|
+
for a query that does not parse — an unknown `type` or data outside 1–64 bytes — whose id is
|
|
16984
|
+
enough to answer it with a refusal rather than leave the widget waiting, or `undefined` without
|
|
16985
|
+
an id. Telegram's message, chat and query objects are parsed loosely: fields it adds later pass
|
|
16986
|
+
through.
|
|
16987
|
+
- **Shared widgets are not here.** `is_shared`, `sendSharedWidget`, `editSharedWidgetData` and
|
|
16988
|
+
`shared_widget_query` are outside this API; in production Telegram sends widgets to private
|
|
16989
|
+
chats only.
|
|
16990
|
+
|
|
16991
|
+
The installed
|
|
16992
|
+
[`telegram-widget-api.mjs`](../../packages/core/scripts/consumer-lane/fixtures/minimal/src/telegram-widget-api.mjs)
|
|
16993
|
+
fixture runs the packed methods through the packed budget transformer on Bun and Node with no
|
|
16994
|
+
grammY installed.
|
|
16995
|
+
|
|
16926
16996
|
## Message markup
|
|
16927
16997
|
|
|
16928
16998
|
`stitchkit/telegram/html` is Telegram's HTML parse mode as a tree, with no peer
|
|
@@ -25285,18 +25355,27 @@ injected grammY bot. → ADR 0143, ADR 0201, ADR 0274 — [guide](../guide/teleg
|
|
|
25285
25355
|
| `postgresTelegramUpdateStore` / `PostgresTelegramUpdateStoreConfig` / `TelegramPostgresQuery` | function / _type_ | the store in Postgres over the client the application holds, as one `query(text, parameters)` returning rows — Bun `sql.unsafe`, Prisma `$queryRawUnsafe`, `pg` `pool.query`; each rule one conditional statement; `table`, `createTable` (default `true`) |
|
|
25286
25356
|
| `postgresTelegramUpdateStoreSchema` | function | the table, idempotent `claim_id` upgrade and index as a statement for a migration, safe to run twice; required before fenced methods when `createTable: false`, while legacy base methods remain compatible with the prior table |
|
|
25287
25357
|
| `checkTelegramUpdateStore` | function | put any store through every rule, each on a fresh store from `make`, concurrent claims included; resolves with the violations, empty when it keeps them |
|
|
25358
|
+
| `TELEGRAM_WIDGET_LIMITS` | constant | Bot API 10.4 widget limits, sizes in UTF-8 bytes: `htmlBytes` 32768, `compressedHtmlBytes` 4096 after zlib level 9 (checked with the runtime's zlib, an estimate of Telegram's), `dataBytes` 1024 for `chat_data`, `public_data` and an answer, `queryDataBytes` 64, `answerWindowMs` 15 000 — [guide](../guide/telegram.md#widgets) |
|
|
25359
|
+
| `TelegramWidgetHtmlSchema` / `TelegramWidgetDataSchema` | schema | widget HTML (1–32768 bytes, at most 4096 compressed) and widget data (0–1024 bytes), counted in UTF-8 bytes; NUL and an unpaired surrogate are refused, an empty data string is a value |
|
|
25360
|
+
| `TelegramWidgetMessageSchema` / `TelegramWidgetMessage` | schema / _type_ | the message `sendWidget` returns — `message_id`, `chat`, `widget` with `html` and its data; parsed loosely, so fields Telegram adds pass through |
|
|
25361
|
+
| `TelegramWidgetQuerySchema` / `TelegramWidgetQuery` | schema / _type_ | `Update.widget_query`: `id`, `from`, `chat` with `message_id` or `inline_message_id`, `chat_instance`, `type` (`data` / `sign_data` / `sent_transaction`), `data` of 1–64 bytes, `widget_id` |
|
|
25362
|
+
| `parseTelegramWidgetQuery` / `TelegramWidgetQueryParse` | function / _type_ | read `update.widget_query`: `{ query }`, or `{ id, error }` for a query that does not parse — its id is enough to answer it with a refusal — or `undefined` without an id |
|
|
25288
25363
|
|
|
25289
25364
|
---
|
|
25290
25365
|
|
|
25291
25366
|
## `stitchkit/telegram/grammy`
|
|
25292
25367
|
|
|
25293
|
-
The token's outbound budget as one grammY client transformer
|
|
25294
|
-
or Node; `grammy` appears in the
|
|
25295
|
-
the bot brings it. → ADR 0274 —
|
|
25368
|
+
The token's outbound budget as one grammY client transformer, and the widget
|
|
25369
|
+
methods over the same client. Server-only, Bun or Node; `grammy` appears in the
|
|
25370
|
+
declarations and is never imported at run time — the bot brings it. → ADR 0274 —
|
|
25371
|
+
[guide](../guide/telegram.md#one-token-one-outbound-budget), [widgets](../guide/telegram.md#widgets)
|
|
25296
25372
|
|
|
25297
25373
|
| Export | Kind | Summary |
|
|
25298
25374
|
|--------|------|---------|
|
|
25299
25375
|
| `telegramBudgetTransformer` | function | `bot.api.config.use(telegramBudgetTransformer(budget))`: every Bot API call runs under the token's `telegramOutboundBudget`; a 429 that comes back as a response pauses the token, a cancellation before the request was handed on throws `TelegramNotDispatchedError`, a cancellation in flight stays the client's own error; it never retries |
|
|
25376
|
+
| `telegramWidgetApi` / `TelegramWidgetApi` | function / _type_ | `telegramWidgetApi(bot.api)`: `sendWidget`, `editMessageWidgetData` and `answerWidgetQuery` through the client's `api.raw`, so its transformers — the outbound budget among them — run each call; input over a limit throws `ZodError` before any request, an already aborted signal throws `TelegramNotDispatchedError`, a request is handed on once and never repeated, `message is not modified` is success, and an unexpected successful answer is an error whose outcome is unknown |
|
|
25377
|
+
| `TelegramSendWidgetParams` / `TelegramEditMessageWidgetDataParams` / `TelegramAnswerWidgetQueryParams` | _type_ | the methods' Bot API parameters by their Bot API names; an edit names `chat_id` with `message_id` or `inline_message_id`, and `chat_data` or `public_data` (`''` removes it, an omitted field keeps it) |
|
|
25378
|
+
| `TelegramWidgetCallOptions` | _type_ | `signal` for one call: aborted before the request leaves, the call is not dispatched |
|
|
25300
25379
|
|
|
25301
25380
|
---
|
|
25302
25381
|
|
package/llms.txt
CHANGED
|
@@ -9,7 +9,7 @@ Build with stitchkit: define a contract once, then `implement` it and serve it (
|
|
|
9
9
|
Load the slice for each entrypoint your code imports — `import … from 'stitchkit/server'` → `llms/server.txt`; the root `stitchkit` import → `llms/stitchkit.txt`. A slice holds that entrypoint's API reference section and the guide pages whose home it is; every guide lives in exactly one slice, and a slice that needs another's guide names it under "Also read". Each file is at most 50.0 KB; a longer one continues in numbered parts, each naming the next at its top. Moving across versions: load `llms/upgrading.txt` and the range slices it lists between your version and the target. `llms-full.txt` inlines everything; it is far larger than a context window, so do not read it whole.
|
|
10
10
|
|
|
11
11
|
## Entrypoint slices
|
|
12
|
-
- **stitchkit**: [llms/stitchkit.txt](llms/stitchkit.txt) 45.
|
|
12
|
+
- **stitchkit**: [llms/stitchkit.txt](llms/stitchkit.txt) 45.2 KB → [llms/stitchkit.2.txt](llms/stitchkit.2.txt) 30.9 KB → [llms/stitchkit.3.txt](llms/stitchkit.3.txt) 19.1 KB
|
|
13
13
|
- **stitchkit/live**: [llms/live.txt](llms/live.txt) 21.2 KB
|
|
14
14
|
- **stitchkit/react**: [llms/react.txt](llms/react.txt) 8.7 KB
|
|
15
15
|
- **stitchkit/react/keyboard**: [llms/react-keyboard.txt](llms/react-keyboard.txt) 22.7 KB
|
|
@@ -45,8 +45,8 @@ Load the slice for each entrypoint your code imports — `import … from 'stitc
|
|
|
45
45
|
- **stitchkit/testing**: [llms/testing.txt](llms/testing.txt) 33.7 KB
|
|
46
46
|
- **stitchkit/agent-runtime/sandbox**: [llms/agent-runtime-sandbox.txt](llms/agent-runtime-sandbox.txt) 8.3 KB
|
|
47
47
|
- **stitchkit/files**: [llms/files.txt](llms/files.txt) 6.2 KB
|
|
48
|
-
- **stitchkit/telegram**: [llms/telegram.txt](llms/telegram.txt)
|
|
49
|
-
- **stitchkit/telegram/grammy**: [llms/telegram-grammy.txt](llms/telegram-grammy.txt)
|
|
48
|
+
- **stitchkit/telegram**: [llms/telegram.txt](llms/telegram.txt) 39.3 KB → [llms/telegram.2.txt](llms/telegram.2.txt) 15.2 KB
|
|
49
|
+
- **stitchkit/telegram/grammy**: [llms/telegram-grammy.txt](llms/telegram-grammy.txt) 2.3 KB
|
|
50
50
|
- **stitchkit/telegram/html**: [llms/telegram-html.txt](llms/telegram-html.txt) 2.7 KB
|
|
51
51
|
- **stitchkit/telegram/voice**: [llms/telegram-voice.txt](llms/telegram-voice.txt) 1.9 KB
|
|
52
52
|
- **stitchkit/telegram/screens**: [llms/telegram-screens.txt](llms/telegram-screens.txt) 21.2 KB
|
|
@@ -106,7 +106,7 @@ Load the slice for each entrypoint your code imports — `import … from 'stitc
|
|
|
106
106
|
- [React Query policy](https://github.com/max-listov/stitchkit/blob/master/docs/guide/react.md): request-local SSR clients, a browser singleton and ApiError retry rules
|
|
107
107
|
- [Keyboard layers and list zones](https://github.com/max-listov/stitchkit/blob/master/docs/guide/keyboard.md): stitchkit/react/keyboard — which part of a screen gets a key: ordered layers, one Escape per level, list zones that move real focus
|
|
108
108
|
- [Voice](https://github.com/max-listov/stitchkit/blob/master/docs/guide/voice.md): stitchkit/voice — sentences cut while a reply streams, the text a voice reads, a speech queue that synthesises ahead and stops on interruption
|
|
109
|
-
- [Telegram bots](https://github.com/max-listov/stitchkit/blob/master/docs/guide/telegram.md): stitchkit/telegram — the journal, the operator channel, resumable broadcasts, local Bot API files, webhook ownership and durable update intake, message markup (stitchkit/telegram/html), voice waveforms (stitchkit/telegram/voice); the bot as application resources
|
|
109
|
+
- [Telegram bots](https://github.com/max-listov/stitchkit/blob/master/docs/guide/telegram.md): stitchkit/telegram — the journal, one outbound budget per token and its grammY transformer, widgets (stitchkit/telegram/grammy), the operator channel, resumable broadcasts, local Bot API files, webhook ownership and durable update intake, message markup (stitchkit/telegram/html), voice waveforms (stitchkit/telegram/voice); the bot as application resources
|
|
110
110
|
- [Telegram screens](https://github.com/max-listov/stitchkit/blob/master/docs/guide/telegram-screens.md): stitchkit/telegram/screens — a bot menu as declared screens: typed paths, actions and input, messages reconciled in place, state in a StorageAdapter, a test chat
|
|
111
111
|
- [GeoIP](https://github.com/max-listov/stitchkit/blob/master/docs/guide/geo.md): stitchkit/geo — a server-only managed reader, three observable states and last-known-good generation reloads
|
|
112
112
|
- [XLSX](https://github.com/max-listov/stitchkit/blob/master/docs/guide/xlsx.md): stitchkit/xlsx — a workbook from rows and typed columns, with no dependency and no formula in the file
|
package/package.json
CHANGED
package/dist/index-6j725ez5.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
// src/telegram/not-dispatched.ts
|
|
2
|
-
class TelegramNotDispatchedError2 extends Error {
|
|
3
|
-
stage;
|
|
4
|
-
name = "TelegramNotDispatchedError";
|
|
5
|
-
code = "TELEGRAM_NOT_DISPATCHED";
|
|
6
|
-
constructor(stage, message, options) {
|
|
7
|
-
super(message, options);
|
|
8
|
-
this.stage = stage;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
function isTelegramNotDispatchedError(error) {
|
|
12
|
-
return error instanceof TelegramNotDispatchedError2 || error instanceof Error && error.name === "TelegramNotDispatchedError" && Reflect.get(error, "code") === "TELEGRAM_NOT_DISPATCHED";
|
|
13
|
-
}
|
|
14
|
-
function isTelegramNotDispatched(error, depth = 0) {
|
|
15
|
-
if (error instanceof TelegramNotDispatchedError2)
|
|
16
|
-
return true;
|
|
17
|
-
if (typeof error !== "object" || error === null || depth > 4)
|
|
18
|
-
return false;
|
|
19
|
-
if (Reflect.get(error, "code") === "TELEGRAM_NOT_DISPATCHED")
|
|
20
|
-
return true;
|
|
21
|
-
const nested = Reflect.get(error, "cause") ?? Reflect.get(error, "error");
|
|
22
|
-
return nested !== error && isTelegramNotDispatched(nested, depth + 1);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export { TelegramNotDispatchedError2, isTelegramNotDispatchedError, isTelegramNotDispatched };
|