iris-relay 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,85 @@
1
+ # iris-relay
2
+
3
+ Lightweight, zero-dependency Telegram message relay. Tree-shakeable ESM package with built-in `.env` loading — true plug-and-play.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pnpm add iris-relay
9
+ ```
10
+
11
+ ## Setup
12
+
13
+ Create a `.env` file in your project root:
14
+
15
+ ```env
16
+ XERO_BOT_TOKEN=your_bot_token_from_botfather
17
+ XERO_CHAT_ID=your_telegram_chat_id
18
+ ```
19
+
20
+ > **How to get these:**
21
+ > - **Bot Token** — message [@BotFather](https://t.me/BotFather) on Telegram to create a bot
22
+ > - **Chat ID** — message [@userinfobot](https://t.me/userinfobot) on Telegram to get your chat ID
23
+
24
+ That's it. No dotenv import needed — `iris-relay` auto-loads your `.env` file.
25
+
26
+ ## Usage
27
+
28
+ ### One-off message
29
+
30
+ ```ts
31
+ import { relay } from "iris-relay";
32
+
33
+ await relay("Hello from my server! 🚀");
34
+ ```
35
+
36
+ ### Pre-configured sender
37
+
38
+ ```ts
39
+ import { createRelay } from "iris-relay";
40
+
41
+ const send = createRelay({
42
+ botToken: process.env.XERO_BOT_TOKEN,
43
+ chatId: process.env.XERO_CHAT_ID,
44
+ });
45
+
46
+ await send("Deploy successful ✅");
47
+ await send("Build failed ❌");
48
+ ```
49
+
50
+ ### Options
51
+
52
+ ```ts
53
+ await relay("Check this out", {
54
+ parseMode: "HTML", // HTML | Markdown | MarkdownV2
55
+ disablePreview: true, // no link previews
56
+ silent: true, // no notification sound
57
+ });
58
+ ```
59
+
60
+ ## API
61
+
62
+ ### `relay(message, config?): Promise<RelayResult>`
63
+
64
+ Send a single message. Returns `{ success: boolean, messageId?: number, error?: string }`.
65
+
66
+ | Param | Type | Description |
67
+ |-------|------|-------------|
68
+ | `message` | `string` | The message text to send |
69
+ | `config.botToken` | `string?` | Bot token (defaults to `XERO_BOT_TOKEN` env var) |
70
+ | `config.chatId` | `string?` | Chat ID (defaults to `XERO_CHAT_ID` env var) |
71
+ | `config.parseMode` | `"HTML" \| "Markdown" \| "MarkdownV2"` | Message formatting |
72
+ | `config.disablePreview` | `boolean?` | Disable link previews |
73
+ | `config.silent` | `boolean?` | Send without notification sound |
74
+
75
+ ### `createRelay(config): (message, overrides?) => Promise<RelayResult>`
76
+
77
+ Create a pre-configured sender function. Useful when sending multiple messages with the same config.
78
+
79
+ ## Requirements
80
+
81
+ - Node.js ≥ 18 (uses native `fetch`)
82
+
83
+ ## License
84
+
85
+ MIT
@@ -0,0 +1,3 @@
1
+ export { relay, createRelay } from "./relay.js";
2
+ export type { RelayConfig, RelayResult, TelegramResponse } from "./types.js";
3
+ //# 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,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAChD,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { relay, createRelay } from "./relay.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,27 @@
1
+ import type { RelayConfig, RelayResult } from "./types.js";
2
+ /**
3
+ * Send a one-off message to your Telegram chat.
4
+ *
5
+ * Reads `IRIS_BOT_TOKEN` and `IRIS_CHAT_ID` from env, or accepts them via config.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { relay } from "iris";
10
+ * await relay("Hello from my server!");
11
+ * ```
12
+ */
13
+ export declare function relay(message: string, config?: RelayConfig): Promise<RelayResult>;
14
+ /**
15
+ * Create a pre-configured relay function with baked-in credentials.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import { createRelay } from "iris";
20
+ *
21
+ * const send = createRelay({ botToken: "...", chatId: "..." });
22
+ * await send("Deploy successful ✅");
23
+ * await send("Build failed ❌");
24
+ * ```
25
+ */
26
+ export declare function createRelay(config: RelayConfig): (message: string, overrides?: Partial<RelayConfig>) => Promise<RelayResult>;
27
+ //# sourceMappingURL=relay.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relay.d.ts","sourceRoot":"","sources":["../src/relay.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAoB,MAAM,YAAY,CAAC;AAkB7E;;;;;;;;;;GAUG;AACH,wBAAsB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAsBvF;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,WAAW,IAEnC,SAAS,MAAM,EAAE,YAAY,OAAO,CAAC,WAAW,CAAC,KAAG,OAAO,CAAC,WAAW,CAAC,CAEnF"}
package/dist/relay.js ADDED
@@ -0,0 +1,62 @@
1
+ import { config } from "dotenv";
2
+ // Auto-load .env on import — true plug-and-play
3
+ config();
4
+ const TG_API = "https://api.telegram.org";
5
+ function resolveConfig(overrides) {
6
+ const botToken = overrides?.botToken
7
+ ?? process.env.XERO_BOT_TOKEN;
8
+ const chatId = overrides?.chatId
9
+ ?? process.env.XERO_CHAT_ID;
10
+ if (!botToken)
11
+ throw new Error("iris: botToken is required — pass it in config or set XERO_BOT_TOKEN env var");
12
+ if (!chatId)
13
+ throw new Error("iris: chatId is required — pass it in config or set XERO_CHAT_ID env var");
14
+ return { botToken, chatId, ...overrides };
15
+ }
16
+ /**
17
+ * Send a one-off message to your Telegram chat.
18
+ *
19
+ * Reads `IRIS_BOT_TOKEN` and `IRIS_CHAT_ID` from env, or accepts them via config.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * import { relay } from "iris";
24
+ * await relay("Hello from my server!");
25
+ * ```
26
+ */
27
+ export async function relay(message, config) {
28
+ const { botToken, chatId, parseMode, disablePreview, silent } = resolveConfig(config);
29
+ const res = await fetch(`${TG_API}/bot${botToken}/sendMessage`, {
30
+ method: "POST",
31
+ headers: { "Content-Type": "application/json" },
32
+ body: JSON.stringify({
33
+ chat_id: chatId,
34
+ text: message,
35
+ ...(parseMode && { parse_mode: parseMode }),
36
+ ...(disablePreview && { disable_web_page_preview: true }),
37
+ ...(silent && { disable_notification: true }),
38
+ }),
39
+ });
40
+ const data = (await res.json());
41
+ if (!data.ok) {
42
+ return { success: false, error: data.description ?? `Telegram API error (${data.error_code})` };
43
+ }
44
+ return { success: true, messageId: data.result?.message_id };
45
+ }
46
+ /**
47
+ * Create a pre-configured relay function with baked-in credentials.
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * import { createRelay } from "iris";
52
+ *
53
+ * const send = createRelay({ botToken: "...", chatId: "..." });
54
+ * await send("Deploy successful ✅");
55
+ * await send("Build failed ❌");
56
+ * ```
57
+ */
58
+ export function createRelay(config) {
59
+ const resolved = resolveConfig(config);
60
+ return (message, overrides) => relay(message, { ...resolved, ...overrides });
61
+ }
62
+ //# sourceMappingURL=relay.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relay.js","sourceRoot":"","sources":["../src/relay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,gDAAgD;AAChD,MAAM,EAAE,CAAC;AAET,MAAM,MAAM,GAAG,0BAA0B,CAAC;AAE1C,SAAS,aAAa,CAAC,SAAuB;IAC1C,MAAM,QAAQ,GAAG,SAAS,EAAE,QAAQ;WAC7B,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;IAClC,MAAM,MAAM,GAAG,SAAS,EAAE,MAAM;WACzB,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AAI,EAAE,SAAS,EAAE,IAAI,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC;AACjE,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,WAAW,CAAC,MAAmB;IAC3C,MAAM,QAAQ,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;IACvC,OAAO,CAAC,OAAe,EAAE,SAAgC,EAAwB,EAAE,CAC/E,KAAK,CAAC,OAAO,EAAE,EAAE,GAAG,QAAQ,EAAE,GAAG,SAAS,EAAE,CAAC,CAAC;AACtD,CAAC"}
@@ -0,0 +1,32 @@
1
+ export interface RelayConfig {
2
+ /** Telegram Bot API token from @BotFather */
3
+ botToken?: string;
4
+ /** Your Telegram chat ID */
5
+ chatId?: string;
6
+ /** Parse mode for messages: HTML, Markdown, or MarkdownV2 */
7
+ parseMode?: "HTML" | "Markdown" | "MarkdownV2";
8
+ /** Disable link previews in messages */
9
+ disablePreview?: boolean;
10
+ /** Send message silently (no notification sound) */
11
+ silent?: boolean;
12
+ }
13
+ export interface TelegramResponse {
14
+ ok: boolean;
15
+ result?: {
16
+ message_id: number;
17
+ chat: {
18
+ id: number;
19
+ type: string;
20
+ };
21
+ text: string;
22
+ date: number;
23
+ };
24
+ description?: string;
25
+ error_code?: number;
26
+ }
27
+ export interface RelayResult {
28
+ success: boolean;
29
+ messageId?: number;
30
+ error?: string;
31
+ }
32
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IACxB,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,4BAA4B;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,6DAA6D;IAC7D,SAAS,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,YAAY,CAAC;IAC/C,wCAAwC;IACxC,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,oDAAoD;IACpD,MAAM,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,gBAAgB;IAC7B,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,CAAC,EAAE;QACL,UAAU,EAAE,MAAM,CAAC;QACnB,IAAI,EAAE;YAAE,EAAE,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE,CAAC;QACnC,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,WAAW;IACxB,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "iris-relay",
3
+ "version": "1.0.0",
4
+ "description": "Lightweight, zero-dependency Telegram message relay",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "keywords": [
18
+ "telegram",
19
+ "relay",
20
+ "bot",
21
+ "message",
22
+ "notification"
23
+ ],
24
+ "author": "",
25
+ "license": "MIT",
26
+ "engines": {
27
+ "node": ">=18"
28
+ },
29
+ "sideEffects": false,
30
+ "devDependencies": {
31
+ "@types/node": "^25.3.5",
32
+ "tsx": "^4.21.0",
33
+ "typescript": "^5.9.3"
34
+ },
35
+ "dependencies": {
36
+ "dotenv": "^17.3.1"
37
+ },
38
+ "scripts": {
39
+ "build": "tsc",
40
+ "test": "tsx test.ts"
41
+ }
42
+ }