@cwa-dou/telekit 0.0.0-stage → 0.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 +57 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +41 -0
- package/dist/index.js.map +1 -0
- package/package.json +34 -4
package/README.md
CHANGED
|
@@ -1,3 +1,58 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @cwa-dou/telekit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Command line tool to send notifications (currently Telegram) with telekit.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g @cwa-dou/telekit
|
|
9
|
+
# or run without installing
|
|
10
|
+
npx @cwa-dou/telekit --help
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Requires Node.js >= 18.
|
|
14
|
+
|
|
15
|
+
## Setup
|
|
16
|
+
|
|
17
|
+
1. Create a bot with [@BotFather](https://t.me/BotFather) and copy the bot token.
|
|
18
|
+
2. Get the chat ID you want to message (send a message to your bot, then open
|
|
19
|
+
`https://api.telegram.org/bot<token>/getUpdates` and read `message.chat.id`).
|
|
20
|
+
3. Save the token locally:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
telekit init --telegram-bot-token <token>
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
The token is stored in `~/.config/telekit/config.json` (file mode `600`).
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
telekit telegram <chatId> "<message>"
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Prints the result as JSON on success:
|
|
35
|
+
|
|
36
|
+
```json
|
|
37
|
+
{ "ok": true, "chatId": "123456789", "messageId": 42 }
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
On failure the error message is printed to stderr and the exit code is `1`.
|
|
41
|
+
|
|
42
|
+
## Commands
|
|
43
|
+
|
|
44
|
+
| Command | Description |
|
|
45
|
+
| --------------------------------------- | ------------------------------------------- |
|
|
46
|
+
| `telekit init --telegram-bot-token <t>` | Save the Telegram bot token to local config |
|
|
47
|
+
| `telekit telegram <chatId> <message>` | Send a Telegram message |
|
|
48
|
+
|
|
49
|
+
## Related packages
|
|
50
|
+
|
|
51
|
+
- [`@cwa-dou/telekit-core`](https://www.npmjs.com/package/@cwa-dou/telekit-core) - shared schemas and operations
|
|
52
|
+
- [`@cwa-dou/telekit-mcp`](https://www.npmjs.com/package/@cwa-dou/telekit-mcp) - local stdio MCP server
|
|
53
|
+
|
|
54
|
+
Part of [telekit](https://github.com/anhtudo97/telekit).
|
|
55
|
+
|
|
56
|
+
## License
|
|
57
|
+
|
|
58
|
+
ISC
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
import { dirname, join } from "node:path";
|
|
6
|
+
import { sendTelegramMessage } from "@cwa-dou/telekit-core";
|
|
7
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
8
|
+
// src/index.ts
|
|
9
|
+
const program = new Command();
|
|
10
|
+
const configPath = join(homedir(), ".config", "telekit", "config.json");
|
|
11
|
+
const cliConfigSchema = z.object({ telegramBotToken: z.string().min(1).optional() });
|
|
12
|
+
function writeTelegramBotToken(token) {
|
|
13
|
+
mkdirSync(dirname(configPath), { recursive: true });
|
|
14
|
+
writeFileSync(configPath, `${JSON.stringify({ telegramBotToken: token }, null, 2)}\n`, { mode: 384 });
|
|
15
|
+
}
|
|
16
|
+
function getTelegramBotToken() {
|
|
17
|
+
if (!existsSync(configPath)) throw new Error("Telegram bot token is required. Run `telekit init`.");
|
|
18
|
+
const token = cliConfigSchema.parse(JSON.parse(readFileSync(configPath, "utf8"))).telegramBotToken;
|
|
19
|
+
if (!token) throw new Error("Telegram bot token is required. Run `telekit init`.");
|
|
20
|
+
return token;
|
|
21
|
+
}
|
|
22
|
+
program.name("telekit").description("TeleKit CLI backed by @cwa-dou/telekit-core");
|
|
23
|
+
program.command("init").description("Configure TeleKit CLI local settings").requiredOption("--telegram-bot-token <botToken>", "Telegram bot token").action(async (options) => {
|
|
24
|
+
writeTelegramBotToken(options.telegramBotToken);
|
|
25
|
+
console.log(`Saved TeleKit CLI config to ${configPath}`);
|
|
26
|
+
});
|
|
27
|
+
program.command("telegram").description("Send a Telegram message").argument("<chatId>", "Telegram chat ID").argument("<message>", "Message text to send").action(async (chatId, message) => {
|
|
28
|
+
const result = await sendTelegramMessage({
|
|
29
|
+
botToken: getTelegramBotToken(),
|
|
30
|
+
chatId,
|
|
31
|
+
message
|
|
32
|
+
});
|
|
33
|
+
console.log(JSON.stringify(result));
|
|
34
|
+
});
|
|
35
|
+
await program.parseAsync(process.argv).catch((error) => {
|
|
36
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
37
|
+
process.exitCode = 1;
|
|
38
|
+
});
|
|
39
|
+
export {};
|
|
40
|
+
|
|
41
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { Command } from \"commander\";\nimport { z } from \"zod\";\nimport { homedir } from \"node:os\";\nimport { dirname, join } from \"node:path\";\nimport { sendTelegramMessage } from \"@cwa-dou/telekit-core\";\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from \"node:fs\";\n\nconst program = new Command();\nconst configPath = join(homedir(), \".config\", \"telekit\", \"config.json\");\nconst cliConfigSchema = z.object({\n telegramBotToken: z.string().min(1).optional(),\n});\n\nfunction writeTelegramBotToken(token: string) {\n mkdirSync(dirname(configPath), { recursive: true });\n writeFileSync(configPath, `${JSON.stringify({ telegramBotToken: token }, null, 2)}\\n`, {\n mode: 0o600,\n });\n}\n\nfunction getTelegramBotToken() {\n if (!existsSync(configPath)) {\n throw new Error(\"Telegram bot token is required. Run `telekit init`.\");\n }\n\n const config = cliConfigSchema.parse(JSON.parse(readFileSync(configPath, \"utf8\")));\n const token = config.telegramBotToken;\n\n if (!token) {\n throw new Error(\"Telegram bot token is required. Run `telekit init`.\");\n }\n\n return token;\n}\n\nprogram.name(\"telekit\").description(\"TeleKit CLI backed by @cwa-dou/telekit-core\");\n\nprogram\n .command(\"init\")\n .description(\"Configure TeleKit CLI local settings\")\n .requiredOption(\"--telegram-bot-token <botToken>\", \"Telegram bot token\")\n .action(async (options: { telegramBotToken: string }) => {\n writeTelegramBotToken(options.telegramBotToken);\n console.log(`Saved TeleKit CLI config to ${configPath}`);\n });\n\nprogram\n .command(\"telegram\")\n .description(\"Send a Telegram message\")\n .argument(\"<chatId>\", \"Telegram chat ID\")\n .argument(\"<message>\", \"Message text to send\")\n .action(async (chatId: string, message: string) => {\n const result = await sendTelegramMessage({\n botToken: getTelegramBotToken(),\n chatId,\n message,\n });\n\n console.log(JSON.stringify(result));\n });\n\nawait program.parseAsync(process.argv).catch((error: unknown) => {\n console.error(error instanceof Error ? error.message : String(error));\n process.exitCode = 1;\n});\n"],"mappings":";;;;;;;;AAQA,MAAM,UAAU,IAAI,QAAQ;AAC5B,MAAM,aAAa,KAAK,QAAQ,GAAG,WAAW,WAAW,aAAa;AACtE,MAAM,kBAAkB,EAAE,OAAO,EAC/B,kBAAkB,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,EAC/C,CAAC;AAED,SAAS,sBAAsB,OAAe;CAC5C,UAAU,QAAQ,UAAU,GAAG,EAAE,WAAW,KAAK,CAAC;CAClD,cAAc,YAAY,GAAG,KAAK,UAAU,EAAE,kBAAkB,MAAM,GAAG,MAAM,CAAC,EAAE,KAAK,EACrF,MAAM,IACR,CAAC;AACH;AAEA,SAAS,s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
|
|
11
|
+
"main": "./dist/index.js",
|
|
12
|
+
"module": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsdown",
|
|
25
|
+
"pack:dry": "bun run build && bun pm pack --dry-run",
|
|
26
|
+
"prepublishOnly": "bun run build"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@cwa-dou/telekit-core": "^0.0.0",
|
|
30
|
+
"commander": "^15.0.0",
|
|
31
|
+
"zod": "^4.6.7"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/node": "^26.6.6"
|
|
35
|
+
}
|
|
36
|
+
}
|