@apicity/telegram 0.2.4

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Justin Tanner
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,135 @@
1
+ # @apicity/telegram
2
+
3
+ [![npm](https://img.shields.io/npm/v/@apicity/telegram?color=cb0000)](https://www.npmjs.com/package/@apicity/telegram)
4
+ [![zero dependencies](https://img.shields.io/badge/dependencies-0-brightgreen)](package.json)
5
+ [![TypeScript](https://img.shields.io/badge/TypeScript-strict-blue?logo=typescript&logoColor=white)](tsconfig.json)
6
+ [![docs](https://img.shields.io/badge/docs-core.telegram.org-blue)](https://core.telegram.org/bots/api)
7
+
8
+ Telegram Bot API provider for sending text, photo, video, and audio messages.
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ npm install @apicity/telegram
14
+ # or
15
+ pnpm add @apicity/telegram
16
+ ```
17
+
18
+ ## Quick Start
19
+
20
+ ```typescript
21
+ import { createTelegram } from "@apicity/telegram";
22
+
23
+ const telegram = createTelegram({ botToken: process.env.TELEGRAM_BOT_KEY! });
24
+ ```
25
+
26
+ ## Setup
27
+
28
+ This package uses a Telegram Bot API token. In this repo,
29
+ `TELEGRAM_BOT_KEY` resolves from 1Password for `@apicitylogbot`.
30
+
31
+ ```typescript
32
+ import { createTelegram } from "@apicity/telegram";
33
+
34
+ const telegram = createTelegram({
35
+ botToken: process.env.TELEGRAM_BOT_KEY!,
36
+ });
37
+
38
+ await telegram.sendMessage({
39
+ chat_id: "@your_channel_or_chat_id",
40
+ text: "hello from @apicity/telegram",
41
+ });
42
+
43
+ const photo = new Blob(["image bytes"], { type: "image/png" });
44
+ await telegram.sendPhoto({
45
+ chat_id: "@your_channel_or_chat_id",
46
+ photo,
47
+ caption: "uploaded from @apicitylogbot",
48
+ });
49
+ ```
50
+
51
+ **Notes**
52
+
53
+ - `chat_id` can be a numeric chat id or a username such as `@channelname`.
54
+ - `photo`, `video`, `audio`, `thumbnail`, and `cover` accept a Telegram
55
+ `file_id`, an HTTP URL, an `attach://...` reference, or a `Blob`.
56
+ - Blob payloads are sent as `multipart/form-data`; string payloads use
57
+ `application/json`.
58
+
59
+ ## API Reference
60
+
61
+ 4 endpoints across 4 groups. Each method mirrors an upstream URL path.
62
+
63
+ ### sendAudio
64
+
65
+ <details>
66
+ <summary><code>POST</code> <b><code>telegram.sendAudio</code></b></summary>
67
+
68
+ <code>POST https://api.telegram.org/bot{token}/sendAudio</code>
69
+
70
+ [Upstream docs ↗](https://core.telegram.org/bots/api#sendaudio)
71
+
72
+ ```typescript
73
+ const res = await telegram.sendAudio({ /* ... */ });
74
+ ```
75
+
76
+ Source: [`packages/provider/telegram/src/telegram.ts`](src/telegram.ts)
77
+
78
+ </details>
79
+
80
+ ### sendMessage
81
+
82
+ <details>
83
+ <summary><code>POST</code> <b><code>telegram.sendMessage</code></b></summary>
84
+
85
+ <code>POST https://api.telegram.org/bot{token}/sendMessage</code>
86
+
87
+ [Upstream docs ↗](https://core.telegram.org/bots/api#sendmessage)
88
+
89
+ ```typescript
90
+ const res = await telegram.sendMessage({ /* ... */ });
91
+ ```
92
+
93
+ Source: [`packages/provider/telegram/src/telegram.ts`](src/telegram.ts)
94
+
95
+ </details>
96
+
97
+ ### sendPhoto
98
+
99
+ <details>
100
+ <summary><code>POST</code> <b><code>telegram.sendPhoto</code></b></summary>
101
+
102
+ <code>POST https://api.telegram.org/bot{token}/sendPhoto</code>
103
+
104
+ [Upstream docs ↗](https://core.telegram.org/bots/api#sendphoto)
105
+
106
+ ```typescript
107
+ const res = await telegram.sendPhoto({ /* ... */ });
108
+ ```
109
+
110
+ Source: [`packages/provider/telegram/src/telegram.ts`](src/telegram.ts)
111
+
112
+ </details>
113
+
114
+ ### sendVideo
115
+
116
+ <details>
117
+ <summary><code>POST</code> <b><code>telegram.sendVideo</code></b></summary>
118
+
119
+ <code>POST https://api.telegram.org/bot{token}/sendVideo</code>
120
+
121
+ [Upstream docs ↗](https://core.telegram.org/bots/api#sendvideo)
122
+
123
+ ```typescript
124
+ const res = await telegram.sendVideo({ /* ... */ });
125
+ ```
126
+
127
+ Source: [`packages/provider/telegram/src/telegram.ts`](src/telegram.ts)
128
+
129
+ </details>
130
+
131
+ Part of the [apicity](https://github.com/justintanner/apicity) monorepo.
132
+
133
+ ## License
134
+
135
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,8 @@
1
+ export interface EndpointExample {
2
+ source: string;
3
+ payload: unknown;
4
+ }
5
+ declare const EXAMPLES: Record<string, EndpointExample>;
6
+ export default EXAMPLES;
7
+ export declare function attachExamples<T>(provider: T): T;
8
+ //# sourceMappingURL=example.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"example.d.ts","sourceRoot":"","sources":["../../src/example.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,QAAA,MAAM,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAQ7C,CAAC;AAEF,eAAe,QAAQ,CAAC;AAOxB,wBAAgB,cAAc,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC,CA6ChD"}
@@ -0,0 +1,93 @@
1
+ // Auto-generated by `pnpm run gen:examples` — do not edit by hand.
2
+ // Source: tests/recordings/<provider>_*/<test>_*/recording.har
3
+ //
4
+ // Each entry is the green-path payload for one endpoint, mined from a real
5
+ // integration-test recording. `attachExamples` walks the provider tree and
6
+ // hangs the matching entry off each endpoint function as `.example`.
7
+ const EXAMPLES = {
8
+ "POST sendMessage": {
9
+ "source": "telegram/send-all-types",
10
+ "payload": {
11
+ "chat_id": "@justintanner",
12
+ "text": "apicity telegram HAR text 2026-06-06T16:29:37.784Z"
13
+ }
14
+ }
15
+ };
16
+ export default EXAMPLES;
17
+ // Walks each "<METHOD> <dotPath>" key onto the provider's tree. Tries the
18
+ // standard `provider.<method>.<dotPath>` shape first, then a few fallbacks
19
+ // to cover providers with non-standard layouts (fal's `.run.` namespace,
20
+ // kie's sub-providers, `free`'s flat root). Returns the same provider for
21
+ // drop-in use as `return attachExamples({ ... });`.
22
+ export function attachExamples(provider) {
23
+ const root = provider;
24
+ const HTTP_KEYS = new Set(["post", "get", "put", "delete", "patch", "head"]);
25
+ for (const [key, example] of Object.entries(EXAMPLES)) {
26
+ const sp = key.indexOf(" ");
27
+ if (sp < 0)
28
+ continue;
29
+ const method = key.slice(0, sp).toLowerCase();
30
+ const segs = key.slice(sp + 1).split(".");
31
+ const candidates = [
32
+ root[method],
33
+ root[method]?.run,
34
+ root,
35
+ ];
36
+ if (segs.length > 1) {
37
+ const sub = root[segs[0]];
38
+ if (sub && typeof sub === "object") {
39
+ const subMethod = sub[method];
40
+ if (subMethod)
41
+ candidates.push({ __nested: subMethod, __segs: segs.slice(1) });
42
+ }
43
+ }
44
+ let attached = false;
45
+ for (const c of candidates) {
46
+ const fn = walkToFn(c, segs);
47
+ if (fn) {
48
+ Object.assign(fn, { example });
49
+ attached = true;
50
+ break;
51
+ }
52
+ }
53
+ if (attached)
54
+ continue;
55
+ for (const k of Object.keys(root)) {
56
+ if (HTTP_KEYS.has(k))
57
+ continue;
58
+ if (!segs.includes(k))
59
+ continue;
60
+ const sub = root[k];
61
+ if (!sub || typeof sub !== "object")
62
+ continue;
63
+ const subMethod = sub[method];
64
+ if (!subMethod)
65
+ continue;
66
+ const fn = walkToFn(subMethod, segs);
67
+ if (fn) {
68
+ Object.assign(fn, { example });
69
+ break;
70
+ }
71
+ }
72
+ }
73
+ return provider;
74
+ }
75
+ function walkToFn(start, segs) {
76
+ if (start && typeof start === "object" && "__nested" in start) {
77
+ const wrapper = start;
78
+ return walkToFn(wrapper.__nested, wrapper.__segs);
79
+ }
80
+ let cur = start;
81
+ for (const seg of segs) {
82
+ if (cur === null || cur === undefined)
83
+ return null;
84
+ const t = typeof cur;
85
+ if (t !== "object" && t !== "function")
86
+ return null;
87
+ cur = cur[seg];
88
+ }
89
+ return typeof cur === "function"
90
+ ? cur
91
+ : null;
92
+ }
93
+ //# sourceMappingURL=example.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"example.js","sourceRoot":"","sources":["../../src/example.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,+DAA+D;AAC/D,EAAE;AACF,2EAA2E;AAC3E,2EAA2E;AAC3E,qEAAqE;AAOrE,MAAM,QAAQ,GAAoC;IAChD,kBAAkB,EAAE;QAClB,QAAQ,EAAE,yBAAyB;QACnC,SAAS,EAAE;YACT,SAAS,EAAE,eAAe;YAC1B,MAAM,EAAE,oDAAoD;SAC7D;KACF;CACF,CAAC;AAEF,eAAe,QAAQ,CAAC;AAExB,0EAA0E;AAC1E,2EAA2E;AAC3E,yEAAyE;AACzE,0EAA0E;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C;IACpD,CAAC;IACD,IAAI,GAAG,GAAY,KAAK,CAAC;IACzB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,SAAS;YAAE,OAAO,IAAI,CAAC;QACnD,MAAM,CAAC,GAAG,OAAO,GAAG,CAAC;QACrB,IAAI,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,UAAU;YAAE,OAAO,IAAI,CAAC;QACpD,GAAG,GAAI,GAA+B,CAAC,GAAG,CAAC,CAAC;IAC9C,CAAC;IACD,OAAO,OAAO,GAAG,KAAK,UAAU;QAC9B,CAAC,CAAE,GAAuC;QAC1C,CAAC,CAAC,IAAI,CAAC;AACX,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { createTelegram } from "./telegram";
2
+ export { TelegramError } from "./types";
3
+ export type { TelegramApiErrorResponse, TelegramApiResponse, TelegramChat, TelegramInputFile, TelegramMessage, TelegramOptions, TelegramProvider, TelegramPostNamespace, TelegramSendAudioMethod, TelegramSendAudioRequest, TelegramSendAudioResponse, TelegramSendMessageMethod, TelegramSendMessageRequest, TelegramSendMessageResponse, TelegramSendPhotoMethod, TelegramSendPhotoRequest, TelegramSendPhotoResponse, TelegramSendVideoMethod, TelegramSendVideoRequest, TelegramSendVideoResponse, TelegramUser, } from "./types";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,YAAY,EACV,wBAAwB,EACxB,mBAAmB,EACnB,YAAY,EACZ,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,qBAAqB,EACrB,uBAAuB,EACvB,wBAAwB,EACxB,yBAAyB,EACzB,yBAAyB,EACzB,0BAA0B,EAC1B,2BAA2B,EAC3B,uBAAuB,EACvB,wBAAwB,EACxB,yBAAyB,EACzB,uBAAuB,EACvB,wBAAwB,EACxB,yBAAyB,EACzB,YAAY,GACb,MAAM,SAAS,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { createTelegram } from "./telegram.js";
2
+ export { TelegramError } from "./types.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { TelegramOptions, TelegramProvider } from "./types";
2
+ export declare function createTelegram(opts: TelegramOptions): TelegramProvider;
3
+ //# sourceMappingURL=telegram.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telegram.d.ts","sourceRoot":"","sources":["../../src/telegram.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,eAAe,EACf,gBAAgB,EASjB,MAAM,SAAS,CAAC;AASjB,wBAAgB,cAAc,CAAC,IAAI,EAAE,eAAe,GAAG,gBAAgB,CAqMtE"}
@@ -0,0 +1,150 @@
1
+ import { TelegramError } from "./types.js";
2
+ import { TelegramSendAudioRequestSchema, TelegramSendMessageRequestSchema, TelegramSendPhotoRequestSchema, TelegramSendVideoRequestSchema, } from "./zod.js";
3
+ import { attachExamples } from "./example.js";
4
+ export function createTelegram(opts) {
5
+ const baseURL = (opts.baseURL ?? "https://api.telegram.org/bot{token}")
6
+ .replace("{token}", opts.botToken)
7
+ .replace(/\/+$/, "");
8
+ const doFetch = opts.fetch ?? fetch;
9
+ const timeout = opts.timeout ?? 30000;
10
+ function attachAbortHandler(signal, controller) {
11
+ if (signal.aborted) {
12
+ controller.abort();
13
+ return;
14
+ }
15
+ signal.addEventListener("abort", () => controller.abort(), { once: true });
16
+ }
17
+ function formatErrorMessage(status, body) {
18
+ if (typeof body === "object" && body !== null) {
19
+ const b = body;
20
+ if (b.description) {
21
+ return `Telegram API error ${status}: ${b.description}`;
22
+ }
23
+ }
24
+ return `Telegram API error: ${status}`;
25
+ }
26
+ function errorCode(body) {
27
+ if (typeof body === "object" && body !== null) {
28
+ const code = body.error_code;
29
+ if (typeof code === "number")
30
+ return String(code);
31
+ }
32
+ return undefined;
33
+ }
34
+ function hasBlob(value) {
35
+ if (value instanceof Blob)
36
+ return true;
37
+ if (Array.isArray(value))
38
+ return value.some(hasBlob);
39
+ if (typeof value === "object" && value !== null) {
40
+ return Object.values(value).some(hasBlob);
41
+ }
42
+ return false;
43
+ }
44
+ function appendFormField(form, key, value) {
45
+ if (value === undefined || value === null)
46
+ return;
47
+ if (value instanceof Blob) {
48
+ form.append(key, value);
49
+ return;
50
+ }
51
+ if (typeof value === "string") {
52
+ form.append(key, value);
53
+ return;
54
+ }
55
+ if (typeof value === "boolean" || typeof value === "number") {
56
+ form.append(key, String(value));
57
+ return;
58
+ }
59
+ form.append(key, JSON.stringify(value));
60
+ }
61
+ function multipartBody(body) {
62
+ const form = new FormData();
63
+ if (typeof body !== "object" || body === null || Array.isArray(body)) {
64
+ return form;
65
+ }
66
+ for (const [key, value] of Object.entries(body)) {
67
+ appendFormField(form, key, value);
68
+ }
69
+ return form;
70
+ }
71
+ async function makeRequest(path, body, signal) {
72
+ const controller = new AbortController();
73
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
74
+ if (signal) {
75
+ attachAbortHandler(signal, controller);
76
+ }
77
+ try {
78
+ const headers = {};
79
+ const init = {
80
+ method: "POST",
81
+ signal: controller.signal,
82
+ };
83
+ if (hasBlob(body)) {
84
+ init.body = multipartBody(body);
85
+ }
86
+ else {
87
+ headers["Content-Type"] = "application/json";
88
+ init.headers = headers;
89
+ init.body = JSON.stringify(body);
90
+ }
91
+ const res = await doFetch(`${baseURL}${path}`, init);
92
+ clearTimeout(timeoutId);
93
+ if (!res.ok) {
94
+ let resBody = null;
95
+ try {
96
+ resBody = await res.json();
97
+ }
98
+ catch {
99
+ // ignore parse errors
100
+ }
101
+ throw new TelegramError(formatErrorMessage(res.status, resBody), res.status, resBody, errorCode(resBody));
102
+ }
103
+ return (await res.json());
104
+ }
105
+ catch (error) {
106
+ clearTimeout(timeoutId);
107
+ if (error instanceof TelegramError)
108
+ throw error;
109
+ throw new TelegramError(`Telegram request failed: ${error}`, 500);
110
+ }
111
+ }
112
+ // sig-ok: `bot{token}` is Telegram's auth prefix, not a method namespace.
113
+ // POST https://api.telegram.org/bot{token}/sendMessage
114
+ // Docs: https://core.telegram.org/bots/api#sendmessage
115
+ const sendMessage = Object.assign(async (req, signal) => {
116
+ return makeRequest("/sendMessage", req, signal);
117
+ }, { schema: TelegramSendMessageRequestSchema });
118
+ // sig-ok: `bot{token}` is Telegram's auth prefix, not a method namespace.
119
+ // POST https://api.telegram.org/bot{token}/sendPhoto
120
+ // Docs: https://core.telegram.org/bots/api#sendphoto
121
+ const sendPhoto = Object.assign(async (req, signal) => {
122
+ return makeRequest("/sendPhoto", req, signal);
123
+ }, { schema: TelegramSendPhotoRequestSchema });
124
+ // sig-ok: `bot{token}` is Telegram's auth prefix, not a method namespace.
125
+ // POST https://api.telegram.org/bot{token}/sendVideo
126
+ // Docs: https://core.telegram.org/bots/api#sendvideo
127
+ const sendVideo = Object.assign(async (req, signal) => {
128
+ return makeRequest("/sendVideo", req, signal);
129
+ }, { schema: TelegramSendVideoRequestSchema });
130
+ // sig-ok: `bot{token}` is Telegram's auth prefix, not a method namespace.
131
+ // POST https://api.telegram.org/bot{token}/sendAudio
132
+ // Docs: https://core.telegram.org/bots/api#sendaudio
133
+ const sendAudio = Object.assign(async (req, signal) => {
134
+ return makeRequest("/sendAudio", req, signal);
135
+ }, { schema: TelegramSendAudioRequestSchema });
136
+ const post = {
137
+ sendMessage,
138
+ sendPhoto,
139
+ sendVideo,
140
+ sendAudio,
141
+ };
142
+ return attachExamples({
143
+ sendMessage,
144
+ sendPhoto,
145
+ sendVideo,
146
+ sendAudio,
147
+ post,
148
+ });
149
+ }
150
+ //# sourceMappingURL=telegram.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telegram.js","sourceRoot":"","sources":["../../src/telegram.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAaxC,OAAO,EACL,8BAA8B,EAC9B,gCAAgC,EAChC,8BAA8B,EAC9B,8BAA8B,GAC/B,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAE3C,MAAM,UAAU,cAAc,CAAC,IAAqB;IAClD,MAAM,OAAO,GAAG,CAAC,IAAI,CAAC,OAAO,IAAI,qCAAqC,CAAC;SACpE,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC;SACjC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACvB,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC;IACpC,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,KAAK,CAAC;IAEtC,SAAS,kBAAkB,CACzB,MAAmB,EACnB,UAA2B;QAE3B,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACnB,UAAU,CAAC,KAAK,EAAE,CAAC;YACnB,OAAO;QACT,CAAC;QACD,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7E,CAAC;IAED,SAAS,kBAAkB,CAAC,MAAc,EAAE,IAAa;QACvD,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YAC9C,MAAM,CAAC,GAAG,IAAqD,CAAC;YAChE,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;gBAClB,OAAO,sBAAsB,MAAM,KAAK,CAAC,C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E,CAC7C,CAAC;IAEF,0EAA0E;IAC1E,qDAAqD;IACrD,qDAAqD;IACrD,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAC7B,KAAK,EACH,GAA6B,EAC7B,MAAoB,EACgB,EAAE;QACtC,OAAO,WAAW,CAA4B,YAAY,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;IAC3E,CAAC,EACD,EAAE,MAAM,EAAE,8BAA8B,EAAE,CAC3C,CAAC;IAEF,0EAA0E;IAC1E,qDAAqD;IACrD,qDAAqD;IACrD,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAC7B,KAAK,EACH,GAA6B,EAC7B,MAAoB,EACgB,EAAE;QACtC,OAAO,WAAW,CAA4B,YAAY,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;IAC3E,CAAC,EACD,EAAE,MAAM,EAAE,8BAA8B,EAAE,CAC3C,CAAC;IAEF,0EAA0E;IAC1E,qDAAqD;IACrD,qDAAqD;IACrD,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAC7B,KAAK,EACH,GAA6B,EAC7B,MAAoB,EACgB,EAAE;QACtC,OAAO,WAAW,CAA4B,YAAY,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;IAC3E,CAAC,EACD,EAAE,MAAM,EAAE,8BAA8B,EAAE,CAC3C,CAAC;IAEF,MAAM,IAAI,GAAG;QACX,WAAW;QACX,SAAS;QACT,SAAS;QACT,SAAS;KACV,CAAC;IAEF,OAAO,cAAc,CAAC;QACpB,WAAW;QACX,SAAS;QACT,SAAS;QACT,SAAS;QACT,IAAI;KACL,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,84 @@
1
+ import type { z } from "zod";
2
+ import type { TelegramSendAudioRequest, TelegramSendMessageRequest, TelegramSendPhotoRequest, TelegramSendVideoRequest } from "./zod";
3
+ export type { TelegramInputFile, TelegramOptions, TelegramSendAudioRequest, TelegramSendMessageRequest, TelegramSendPhotoRequest, TelegramSendVideoRequest, } from "./zod";
4
+ export declare class TelegramError extends Error {
5
+ readonly status: number;
6
+ readonly body: unknown;
7
+ readonly code?: string;
8
+ constructor(message: string, status: number, body?: unknown, code?: string);
9
+ }
10
+ export interface TelegramApiResponse<T> {
11
+ ok: true;
12
+ result: T;
13
+ }
14
+ export interface TelegramApiErrorResponse {
15
+ ok: false;
16
+ error_code: number;
17
+ description: string;
18
+ parameters?: Record<string, unknown>;
19
+ }
20
+ export interface TelegramUser {
21
+ id: number;
22
+ is_bot: boolean;
23
+ first_name: string;
24
+ last_name?: string;
25
+ username?: string;
26
+ language_code?: string;
27
+ is_premium?: boolean;
28
+ }
29
+ export interface TelegramChat {
30
+ id: number;
31
+ type: string;
32
+ title?: string;
33
+ username?: string;
34
+ first_name?: string;
35
+ last_name?: string;
36
+ }
37
+ export interface TelegramMessage {
38
+ message_id: number;
39
+ message_thread_id?: number;
40
+ from?: TelegramUser;
41
+ sender_chat?: TelegramChat;
42
+ date: number;
43
+ chat: TelegramChat;
44
+ text?: string;
45
+ caption?: string;
46
+ photo?: Array<Record<string, unknown>>;
47
+ video?: Record<string, unknown>;
48
+ audio?: Record<string, unknown>;
49
+ [key: string]: unknown;
50
+ }
51
+ export type TelegramSendMessageResponse = TelegramApiResponse<TelegramMessage>;
52
+ export type TelegramSendPhotoResponse = TelegramApiResponse<TelegramMessage>;
53
+ export type TelegramSendVideoResponse = TelegramApiResponse<TelegramMessage>;
54
+ export type TelegramSendAudioResponse = TelegramApiResponse<TelegramMessage>;
55
+ export interface TelegramSendMessageMethod {
56
+ (req: TelegramSendMessageRequest, signal?: AbortSignal): Promise<TelegramSendMessageResponse>;
57
+ schema: z.ZodType<TelegramSendMessageRequest>;
58
+ }
59
+ export interface TelegramSendPhotoMethod {
60
+ (req: TelegramSendPhotoRequest, signal?: AbortSignal): Promise<TelegramSendPhotoResponse>;
61
+ schema: z.ZodType<TelegramSendPhotoRequest>;
62
+ }
63
+ export interface TelegramSendVideoMethod {
64
+ (req: TelegramSendVideoRequest, signal?: AbortSignal): Promise<TelegramSendVideoResponse>;
65
+ schema: z.ZodType<TelegramSendVideoRequest>;
66
+ }
67
+ export interface TelegramSendAudioMethod {
68
+ (req: TelegramSendAudioRequest, signal?: AbortSignal): Promise<TelegramSendAudioResponse>;
69
+ schema: z.ZodType<TelegramSendAudioRequest>;
70
+ }
71
+ export interface TelegramPostNamespace {
72
+ sendMessage: TelegramSendMessageMethod;
73
+ sendPhoto: TelegramSendPhotoMethod;
74
+ sendVideo: TelegramSendVideoMethod;
75
+ sendAudio: TelegramSendAudioMethod;
76
+ }
77
+ export interface TelegramProvider {
78
+ sendMessage: TelegramSendMessageMethod;
79
+ sendPhoto: TelegramSendPhotoMethod;
80
+ sendVideo: TelegramSendVideoMethod;
81
+ sendAudio: TelegramSendAudioMethod;
82
+ post: TelegramPostNamespace;
83
+ }
84
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,wBAAwB,EACxB,wBAAwB,EACzB,MAAM,OAAO,CAAC;AAEf,YAAY,EACV,iBAAiB,EACjB,eAAe,EACf,wBAAwB,EACxB,0BAA0B,EAC1B,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,OAAO,CAAC;AAIf,qBAAa,aAAc,SAAQ,KAAK;IACtC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;gBAEX,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,MAAM;CAO3E;AAID,MAAM,WAAW,mBAAmB,CAAC,CAAC;IACpC,EAA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BAAuB,CAAC;IACnC,SAAS,EAAE,uBAAuB,CAAC;CACpC;AAED,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,yBAAyB,CAAC;IACvC,SAAS,EAAE,uBAAuB,CAAC;IACnC,SAAS,EAAE,uBAAuB,CAAC;IACnC,SAAS,EAAE,uBAAuB,CAAC;IACnC,IAAI,EAAE,qBAAqB,CAAC;CAC7B"}
@@ -0,0 +1,14 @@
1
+ // -- Error -------------------------------------------------------------------
2
+ export class TelegramError extends Error {
3
+ status;
4
+ body;
5
+ code;
6
+ constructor(message, status, body, code) {
7
+ super(message);
8
+ this.name = "TelegramError";
9
+ this.status = status;
10
+ this.body = body ?? null;
11
+ this.code = code;
12
+ }
13
+ }
14
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAiBA,+EAA+E;AAE/E,MAAM,OAAO,aAAc,SAAQ,KAAK;IAC7B,MAAM,CAAS;IACf,IAAI,CAAU;IACd,IAAI,CAAU;IAEvB,YAAY,OAAe,EAAE,MAAc,EAAE,IAAc,EAAE,IAAa;QACxE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,IAAI,IAAI,CAAC;QACzB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF"}
@@ -0,0 +1,273 @@
1
+ import { z } from "zod";
2
+ export declare const TelegramOptionsSchema: z.ZodObject<{
3
+ botToken: z.ZodString;
4
+ baseURL: z.ZodOptional<z.ZodString>;
5
+ timeout: z.ZodOptional<z.ZodNumber>;
6
+ fetch: z.ZodOptional<z.ZodType<typeof fetch, z.ZodTypeDef, typeof fetch>>;
7
+ }, "strip", z.ZodTypeAny, {
8
+ botToken: string;
9
+ baseURL?: string | undefined;
10
+ timeout?: number | undefined;
11
+ fetch?: typeof fetch | undefined;
12
+ }, {
13
+ botToken: string;
14
+ baseURL?: string | undefined;
15
+ timeout?: number | undefined;
16
+ fetch?: typeof fetch | undefined;
17
+ }>;
18
+ export type TelegramOptions = z.infer<typeof TelegramOptionsSchema>;
19
+ export declare const TelegramChatIdSchema: z.ZodUnion<[z.ZodNumber, z.ZodString]>;
20
+ export declare const TelegramRecordSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
21
+ export declare const TelegramEntitiesSchema: z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>, "many">;
22
+ export declare const TelegramParseModeSchema: z.ZodEnum<["Markdown", "MarkdownV2", "HTML"]>;
23
+ export declare const TelegramInputFileSchema: z.ZodUnion<[z.ZodString, z.ZodType<Blob, z.ZodTypeDef, Blob>]>;
24
+ export type TelegramInputFile = z.infer<typeof TelegramInputFileSchema>;
25
+ export declare const TelegramSendMessageRequestSchema: z.ZodObject<{
26
+ text: z.ZodString;
27
+ parse_mode: z.ZodOptional<z.ZodEnum<["Markdown", "MarkdownV2", "HTML"]>>;
28
+ entities: z.ZodOptional<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>, "many">>;
29
+ link_preview_options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
30
+ business_connection_id: z.ZodOptional<z.ZodString>;
31
+ chat_id: z.ZodUnion<[z.ZodNumber, z.ZodString]>;
32
+ message_thread_id: z.ZodOptional<z.ZodNumber>;
33
+ direct_messages_topic_id: z.ZodOptional<z.ZodNumber>;
34
+ disable_notification: z.ZodOptional<z.ZodBoolean>;
35
+ protect_content: z.ZodOptional<z.ZodBoolean>;
36
+ allow_paid_broadcast: z.ZodOptional<z.ZodBoolean>;
37
+ message_effect_id: z.ZodOptional<z.ZodString>;
38
+ suggested_post_parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
39
+ reply_parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
40
+ reply_markup: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
41
+ }, "strip", z.ZodTypeAny, {
42
+ text: string;
43
+ chat_id: string | number;
44
+ parse_mode?: "Markdown" | "MarkdownV2" | "HTML" | undefined;
45
+ entities?: Record<string, unknown>[] | undefined;
46
+ link_preview_options?: Record<string, unknown> | undefined;
47
+ business_connection_id?: string | undefined;
48
+ message_thread_id?: number | undefined;
49
+ direct_messages_topic_id?: number | undefined;
50
+ disable_notification?: boolean | undefined;
51
+ protect_content?: boolean | undefined;
52
+ allow_paid_broadcast?: boolean | undefined;
53
+ message_effect_id?: string | undefined;
54
+ suggested_post_parameters?: Record<string, unknown> | undefined;
55
+ reply_parameters?: Record<string, unknown> | undefined;
56
+ reply_markup?: Record<string, unknown> | undefined;
57
+ }, {
58
+ text: string;
59
+ chat_id: string | number;
60
+ parse_mode?: "Markdown" | "MarkdownV2" | "HTML" | undefined;
61
+ entities?: Record<string, unknown>[] | undefined;
62
+ link_preview_options?: Record<string, unknown> | undefined;
63
+ business_connection_id?: string | undefined;
64
+ message_thread_id?: number | undefined;
65
+ direct_messages_topic_id?: number | undefined;
66
+ disable_notification?: boolean | undefined;
67
+ protect_content?: boolean | undefined;
68
+ allow_paid_broadcast?: boolean | undefined;
69
+ message_effect_id?: string | undefined;
70
+ suggested_post_parameters?: Record<string, unknown> | undefined;
71
+ reply_parameters?: Record<string, unknown> | undefined;
72
+ reply_markup?: Record<string, unknown> | undefined;
73
+ }>;
74
+ export type TelegramSendMessageRequest = z.infer<typeof TelegramSendMessageRequestSchema>;
75
+ export declare const TelegramSendPhotoRequestSchema: z.ZodObject<{
76
+ has_spoiler: z.ZodOptional<z.ZodBoolean>;
77
+ caption: z.ZodOptional<z.ZodString>;
78
+ parse_mode: z.ZodOptional<z.ZodEnum<["Markdown", "MarkdownV2", "HTML"]>>;
79
+ caption_entities: z.ZodOptional<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>, "many">>;
80
+ show_caption_above_media: z.ZodOptional<z.ZodBoolean>;
81
+ photo: z.ZodUnion<[z.ZodString, z.ZodType<Blob, z.ZodTypeDef, Blob>]>;
82
+ business_connection_id: z.ZodOptional<z.ZodString>;
83
+ chat_id: z.ZodUnion<[z.ZodNumber, z.ZodString]>;
84
+ message_thread_id: z.ZodOptional<z.ZodNumber>;
85
+ direct_messages_topic_id: z.ZodOptional<z.ZodNumber>;
86
+ disable_notification: z.ZodOptional<z.ZodBoolean>;
87
+ protect_content: z.ZodOptional<z.ZodBoolean>;
88
+ allow_paid_broadcast: z.ZodOptional<z.ZodBoolean>;
89
+ message_effect_id: z.ZodOptional<z.ZodString>;
90
+ suggested_post_parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
91
+ reply_parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
92
+ reply_markup: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
93
+ }, "strip", z.ZodTypeAny, {
94
+ chat_id: string | number;
95
+ photo: string | Blob;
96
+ parse_mode?: "Markdown" | "MarkdownV2" | "HTML" | undefined;
97
+ business_connection_id?: string | undefined;
98
+ message_thread_id?: number | undefined;
99
+ direct_messages_topic_id?: number | undefined;
100
+ disable_notification?: boolean | undefined;
101
+ protect_content?: boolean | undefined;
102
+ allow_paid_broadcast?: boolean | undefined;
103
+ message_effect_id?: string | undefined;
104
+ suggested_post_parameters?: Record<string, unknown> | undefined;
105
+ reply_parameters?: Record<string, unknown> | undefined;
106
+ reply_markup?: Record<string, unknown> | undefined;
107
+ has_spoiler?: boolean | undefined;
108
+ caption?: string | undefined;
109
+ caption_entities?: Record<string, unknown>[] | undefined;
110
+ show_caption_above_media?: boolean | undefined;
111
+ }, {
112
+ chat_id: string | number;
113
+ photo: string | Blob;
114
+ parse_mode?: "Markdown" | "MarkdownV2" | "HTML" | undefined;
115
+ business_connection_id?: string | undefined;
116
+ message_thread_id?: number | undefined;
117
+ direct_messages_topic_id?: number | undefined;
118
+ disable_notification?: boolean | undefined;
119
+ protect_content?: boolean | undefined;
120
+ allow_paid_broadcast?: boolean | undefined;
121
+ message_effect_id?: string | undefined;
122
+ suggested_post_parameters?: Record<string, unknown> | undefined;
123
+ reply_parameters?: Record<string, unknown> | undefined;
124
+ reply_markup?: Record<string, unknown> | undefined;
125
+ has_spoiler?: boolean | undefined;
126
+ caption?: string | undefined;
127
+ caption_entities?: Record<string, unknown>[] | undefined;
128
+ show_caption_above_media?: boolean | undefined;
129
+ }>;
130
+ export type TelegramSendPhotoRequest = z.infer<typeof TelegramSendPhotoRequestSchema>;
131
+ export declare const TelegramSendVideoRequestSchema: z.ZodObject<{
132
+ has_spoiler: z.ZodOptional<z.ZodBoolean>;
133
+ supports_streaming: z.ZodOptional<z.ZodBoolean>;
134
+ caption: z.ZodOptional<z.ZodString>;
135
+ parse_mode: z.ZodOptional<z.ZodEnum<["Markdown", "MarkdownV2", "HTML"]>>;
136
+ caption_entities: z.ZodOptional<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>, "many">>;
137
+ show_caption_above_media: z.ZodOptional<z.ZodBoolean>;
138
+ video: z.ZodUnion<[z.ZodString, z.ZodType<Blob, z.ZodTypeDef, Blob>]>;
139
+ duration: z.ZodOptional<z.ZodNumber>;
140
+ width: z.ZodOptional<z.ZodNumber>;
141
+ height: z.ZodOptional<z.ZodNumber>;
142
+ thumbnail: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodType<Blob, z.ZodTypeDef, Blob>]>>;
143
+ cover: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodType<Blob, z.ZodTypeDef, Blob>]>>;
144
+ start_timestamp: z.ZodOptional<z.ZodNumber>;
145
+ business_connection_id: z.ZodOptional<z.ZodString>;
146
+ chat_id: z.ZodUnion<[z.ZodNumber, z.ZodString]>;
147
+ message_thread_id: z.ZodOptional<z.ZodNumber>;
148
+ direct_messages_topic_id: z.ZodOptional<z.ZodNumber>;
149
+ disable_notification: z.ZodOptional<z.ZodBoolean>;
150
+ protect_content: z.ZodOptional<z.ZodBoolean>;
151
+ allow_paid_broadcast: z.ZodOptional<z.ZodBoolean>;
152
+ message_effect_id: z.ZodOptional<z.ZodString>;
153
+ suggested_post_parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
154
+ reply_parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
155
+ reply_markup: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
156
+ }, "strip", z.ZodTypeAny, {
157
+ chat_id: string | number;
158
+ video: string | Blob;
159
+ parse_mode?: "Markdown" | "MarkdownV2" | "HTML" | undefined;
160
+ business_connection_id?: string | undefined;
161
+ message_thread_id?: number | undefined;
162
+ direct_messages_topic_id?: number | undefined;
163
+ disable_notification?: boolean | undefined;
164
+ protect_content?: boolean | undefined;
165
+ allow_paid_broadcast?: boolean | undefined;
166
+ message_effect_id?: string | undefined;
167
+ suggested_post_parameters?: Record<string, unknown> | undefined;
168
+ reply_parameters?: Record<string, unknown> | undefined;
169
+ reply_markup?: Record<string, unknown> | undefined;
170
+ has_spoiler?: boolean | undefined;
171
+ caption?: string | undefined;
172
+ caption_entities?: Record<string, unknown>[] | undefined;
173
+ show_caption_above_media?: boolean | undefined;
174
+ duration?: number | undefined;
175
+ width?: number | undefined;
176
+ height?: number | undefined;
177
+ thumbnail?: string | Blob | undefined;
178
+ cover?: string | Blob | undefined;
179
+ start_timestamp?: number | undefined;
180
+ supports_streaming?: boolean | undefined;
181
+ }, {
182
+ chat_id: string | number;
183
+ video: string | Blob;
184
+ parse_mode?: "Markdown" | "MarkdownV2" | "HTML" | undefined;
185
+ business_connection_id?: string | undefined;
186
+ message_thread_id?: number | undefined;
187
+ direct_messages_topic_id?: number | undefined;
188
+ disable_notification?: boolean | undefined;
189
+ protect_content?: boolean | undefined;
190
+ allow_paid_broadcast?: boolean | undefined;
191
+ message_effect_id?: string | undefined;
192
+ suggested_post_parameters?: Record<string, unknown> | undefined;
193
+ reply_parameters?: Record<string, unknown> | undefined;
194
+ reply_markup?: Record<string, unknown> | undefined;
195
+ has_spoiler?: boolean | undefined;
196
+ caption?: string | undefined;
197
+ caption_entities?: Record<string, unknown>[] | undefined;
198
+ show_caption_above_media?: boolean | undefined;
199
+ duration?: number | undefined;
200
+ width?: number | undefined;
201
+ height?: number | undefined;
202
+ thumbnail?: string | Blob | undefined;
203
+ cover?: string | Blob | undefined;
204
+ start_timestamp?: number | undefined;
205
+ supports_streaming?: boolean | undefined;
206
+ }>;
207
+ export type TelegramSendVideoRequest = z.infer<typeof TelegramSendVideoRequestSchema>;
208
+ export declare const TelegramSendAudioRequestSchema: z.ZodObject<{
209
+ duration: z.ZodOptional<z.ZodNumber>;
210
+ performer: z.ZodOptional<z.ZodString>;
211
+ title: z.ZodOptional<z.ZodString>;
212
+ thumbnail: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodType<Blob, z.ZodTypeDef, Blob>]>>;
213
+ caption: z.ZodOptional<z.ZodString>;
214
+ parse_mode: z.ZodOptional<z.ZodEnum<["Markdown", "MarkdownV2", "HTML"]>>;
215
+ caption_entities: z.ZodOptional<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>, "many">>;
216
+ show_caption_above_media: z.ZodOptional<z.ZodBoolean>;
217
+ audio: z.ZodUnion<[z.ZodString, z.ZodType<Blob, z.ZodTypeDef, Blob>]>;
218
+ business_connection_id: z.ZodOptional<z.ZodString>;
219
+ chat_id: z.ZodUnion<[z.ZodNumber, z.ZodString]>;
220
+ message_thread_id: z.ZodOptional<z.ZodNumber>;
221
+ direct_messages_topic_id: z.ZodOptional<z.ZodNumber>;
222
+ disable_notification: z.ZodOptional<z.ZodBoolean>;
223
+ protect_content: z.ZodOptional<z.ZodBoolean>;
224
+ allow_paid_broadcast: z.ZodOptional<z.ZodBoolean>;
225
+ message_effect_id: z.ZodOptional<z.ZodString>;
226
+ suggested_post_parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
227
+ reply_parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
228
+ reply_markup: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
229
+ }, "strip", z.ZodTypeAny, {
230
+ chat_id: string | number;
231
+ audio: string | Blob;
232
+ parse_mode?: "Markdown" | "MarkdownV2" | "HTML" | undefined;
233
+ business_connection_id?: string | undefined;
234
+ message_thread_id?: number | undefined;
235
+ direct_messages_topic_id?: number | undefined;
236
+ disable_notification?: boolean | undefined;
237
+ protect_content?: boolean | undefined;
238
+ allow_paid_broadcast?: boolean | undefined;
239
+ message_effect_id?: string | undefined;
240
+ suggested_post_parameters?: Record<string, unknown> | undefined;
241
+ reply_parameters?: Record<string, unknown> | undefined;
242
+ reply_markup?: Record<string, unknown> | undefined;
243
+ caption?: string | undefined;
244
+ caption_entities?: Record<string, unknown>[] | undefined;
245
+ show_caption_above_media?: boolean | undefined;
246
+ duration?: number | undefined;
247
+ thumbnail?: string | Blob | undefined;
248
+ performer?: string | undefined;
249
+ title?: string | undefined;
250
+ }, {
251
+ chat_id: string | number;
252
+ audio: string | Blob;
253
+ parse_mode?: "Markdown" | "MarkdownV2" | "HTML" | undefined;
254
+ business_connection_id?: string | undefined;
255
+ message_thread_id?: number | undefined;
256
+ direct_messages_topic_id?: number | undefined;
257
+ disable_notification?: boolean | undefined;
258
+ protect_content?: boolean | undefined;
259
+ allow_paid_broadcast?: boolean | undefined;
260
+ message_effect_id?: string | undefined;
261
+ suggested_post_parameters?: Record<string, unknown> | undefined;
262
+ reply_parameters?: Record<string, unknown> | undefined;
263
+ reply_markup?: Record<string, unknown> | undefined;
264
+ caption?: string | undefined;
265
+ caption_entities?: Record<string, unknown>[] | undefined;
266
+ show_caption_above_media?: boolean | undefined;
267
+ duration?: number | undefined;
268
+ thumbnail?: string | Blob | undefined;
269
+ performer?: string | undefined;
270
+ title?: string | undefined;
271
+ }>;
272
+ export type TelegramSendAudioRequest = z.infer<typeof TelegramSendAudioRequestSchema>;
273
+ //# sourceMappingURL=zod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../../src/zod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;EAKhC,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAMpE,eAAO,MAAM,oBAAoB,wCAA0C,CAAC;AAC5E,eAAO,MAAM,oBAAoB,wCAAoC,CAAC;AACtE,eAAO,MAAM,sBAAsB,4DAAgC,CAAC;AACpE,eAAO,MAAM,uBAAuB,+CAIlC,CAAC;AACH,eAAO,MAAM,uBAAuB,gEAGlC,CAAC;AAEH,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AA2BxE,eAAO,MAAM,gCAAgC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAM3C,CAAC;AAEH,MAAM,MAAM,0BAA0B,GAAG,CAAC,CAAC,KAAK,CAC9C,OAAO,gCAAgC,CACxC,CAAC;AAMF,eAAO,MAAM,8BAA8B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAKzC,CAAC;AAEH,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,KAAK,CAC5C,OAAO,8BAA8B,CACtC,CAAC;AAMF,eAAO,MAAM,8BAA8B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAYzC,CAAC;AAEH,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,KAAK,CAC5C,OAAO,8BAA8B,CACtC,CAAC;AAMF,eAAO,MAAM,8BAA8B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAQzC,CAAC;AAEH,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,KAAK,CAC5C,OAAO,8BAA8B,CACtC,CAAC"}
@@ -0,0 +1,92 @@
1
+ import { z } from "zod";
2
+ // ---------------------------------------------------------------------------
3
+ // Provider options
4
+ // ---------------------------------------------------------------------------
5
+ export const TelegramOptionsSchema = z.object({
6
+ botToken: z.string().min(1),
7
+ baseURL: z.string().optional(),
8
+ timeout: z.number().optional(),
9
+ fetch: z.custom().optional(),
10
+ });
11
+ // ---------------------------------------------------------------------------
12
+ // Shared Telegram Bot API shapes
13
+ // ---------------------------------------------------------------------------
14
+ export const TelegramChatIdSchema = z.union([z.number().int(), z.string()]);
15
+ export const TelegramRecordSchema = z.record(z.string(), z.unknown());
16
+ export const TelegramEntitiesSchema = z.array(TelegramRecordSchema);
17
+ export const TelegramParseModeSchema = z.enum([
18
+ "Markdown",
19
+ "MarkdownV2",
20
+ "HTML",
21
+ ]);
22
+ export const TelegramInputFileSchema = z.union([
23
+ z.string().min(1),
24
+ z.instanceof(Blob),
25
+ ]);
26
+ const messageBase = {
27
+ business_connection_id: z.string().optional(),
28
+ chat_id: TelegramChatIdSchema,
29
+ message_thread_id: z.number().int().optional(),
30
+ direct_messages_topic_id: z.number().int().optional(),
31
+ disable_notification: z.boolean().optional(),
32
+ protect_content: z.boolean().optional(),
33
+ allow_paid_broadcast: z.boolean().optional(),
34
+ message_effect_id: z.string().optional(),
35
+ suggested_post_parameters: TelegramRecordSchema.optional(),
36
+ reply_parameters: TelegramRecordSchema.optional(),
37
+ reply_markup: TelegramRecordSchema.optional(),
38
+ };
39
+ const captionFields = {
40
+ caption: z.string().optional(),
41
+ parse_mode: TelegramParseModeSchema.optional(),
42
+ caption_entities: TelegramEntitiesSchema.optional(),
43
+ show_caption_above_media: z.boolean().optional(),
44
+ };
45
+ // ---------------------------------------------------------------------------
46
+ // POST /bot{token}/sendMessage
47
+ // ---------------------------------------------------------------------------
48
+ export const TelegramSendMessageRequestSchema = z.object({
49
+ ...messageBase,
50
+ text: z.string().min(1),
51
+ parse_mode: TelegramParseModeSchema.optional(),
52
+ entities: TelegramEntitiesSchema.optional(),
53
+ link_preview_options: TelegramRecordSchema.optional(),
54
+ });
55
+ // ---------------------------------------------------------------------------
56
+ // POST /bot{token}/sendPhoto
57
+ // ---------------------------------------------------------------------------
58
+ export const TelegramSendPhotoRequestSchema = z.object({
59
+ ...messageBase,
60
+ photo: TelegramInputFileSchema,
61
+ ...captionFields,
62
+ has_spoiler: z.boolean().optional(),
63
+ });
64
+ // ---------------------------------------------------------------------------
65
+ // POST /bot{token}/sendVideo
66
+ // ---------------------------------------------------------------------------
67
+ export const TelegramSendVideoRequestSchema = z.object({
68
+ ...messageBase,
69
+ video: TelegramInputFileSchema,
70
+ duration: z.number().int().optional(),
71
+ width: z.number().int().optional(),
72
+ height: z.number().int().optional(),
73
+ thumbnail: TelegramInputFileSchema.optional(),
74
+ cover: TelegramInputFileSchema.optional(),
75
+ start_timestamp: z.number().int().optional(),
76
+ ...captionFields,
77
+ has_spoiler: z.boolean().optional(),
78
+ supports_streaming: z.boolean().optional(),
79
+ });
80
+ // ---------------------------------------------------------------------------
81
+ // POST /bot{token}/sendAudio
82
+ // ---------------------------------------------------------------------------
83
+ export const TelegramSendAudioRequestSchema = z.object({
84
+ ...messageBase,
85
+ audio: TelegramInputFileSchema,
86
+ ...captionFields,
87
+ duration: z.number().int().optional(),
88
+ performer: z.string().optional(),
89
+ title: z.string().optional(),
90
+ thumbnail: TelegramInputFileSchema.optional(),
91
+ });
92
+ //# sourceMappingURL=zod.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zod.js","sourceRoot":"","sources":["../../src/zod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,8EAA8E;AAC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ChC,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC5B,SAAS,EAAE,uBAAuB,CAAC,QAAQ,EAAE;CAC9C,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@apicity/telegram",
3
+ "version": "0.2.4",
4
+ "description": "Telegram Bot API provider for sending text, photo, video, and audio messages.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/justintanner/apicity.git",
9
+ "directory": "provider/telegram"
10
+ },
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "type": "module",
15
+ "main": "dist/src/index.js",
16
+ "types": "dist/src/index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "import": "./dist/src/index.js",
20
+ "types": "./dist/src/index.d.ts"
21
+ },
22
+ "./zod": {
23
+ "import": "./dist/src/zod.js",
24
+ "types": "./dist/src/zod.d.ts"
25
+ }
26
+ },
27
+ "dependencies": {
28
+ "zod": "^3.24.0"
29
+ },
30
+ "files": [
31
+ "dist",
32
+ "README.md",
33
+ "LICENSE"
34
+ ],
35
+ "sideEffects": false,
36
+ "keywords": [
37
+ "telegram",
38
+ "telegram-bot-api",
39
+ "bot",
40
+ "messages",
41
+ "apicity"
42
+ ],
43
+ "author": "Justin Tanner",
44
+ "engines": {
45
+ "node": ">=18.0.0"
46
+ },
47
+ "homepage": "https://github.com/justintanner/apicity#readme",
48
+ "bugs": {
49
+ "url": "https://github.com/justintanner/apicity/issues"
50
+ },
51
+ "scripts": {
52
+ "build": "tsc -p tsconfig.json && node scripts/dist.mjs"
53
+ }
54
+ }