@send-bot/send-bot 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.
@@ -0,0 +1 @@
1
+ export { };
package/dist/index.js ADDED
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from "commander";
3
+ import { sendTelegramMessage } from "@send-bot/send-bot-core";
4
+ import { homedir } from "node:os";
5
+ import { dirname, join } from "node:path";
6
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
7
+ import { z } from "zod";
8
+ //#region src/index.ts
9
+ const configPath = join(homedir(), ".config", "sendbot", "config.json");
10
+ const configSchema = z.object({ telegramBotToken: z.string().min(1).optional() });
11
+ function writeTelegramToken(token) {
12
+ mkdirSync(dirname(configPath), { recursive: true });
13
+ writeFileSync(configPath, `${JSON.stringify({ telegramBotToken: token }, null, 2)}\n`, { mode: 384 });
14
+ }
15
+ function getTelegramBotToken() {
16
+ if (!existsSync(configPath)) throw new Error("Telegram bot token in required, Rend sendbot init");
17
+ const config = configSchema.parse(JSON.parse(readFileSync(configPath, "utf-8")));
18
+ if (!config.telegramBotToken) throw new Error("Telegram bot token in required, Run sendbot init");
19
+ return config.telegramBotToken;
20
+ }
21
+ const program = new Command();
22
+ program.name("sendbot").description("Send CLI");
23
+ program.command("init").description("Configure sendbot cli local settings").requiredOption("--tg-token <botToken>", "Telegram Bot Token").action(async (options) => {
24
+ await writeTelegramToken(options.tgToken);
25
+ });
26
+ program.command("telegram").description("Send a Telegram message").argument("<chatId>", "Telegram chat ID").argument("<message>", "Message text to send").action(async (chatId, message) => {
27
+ if (!chatId || !message) process.exit(1);
28
+ try {
29
+ console.log("sending message");
30
+ const res = await sendTelegramMessage({
31
+ botToken: getTelegramBotToken(),
32
+ chatId,
33
+ message
34
+ });
35
+ if (res.ok) console.log(res);
36
+ else throw new Error("error sending message");
37
+ } catch (error) {
38
+ console.error(error);
39
+ process.exit(1);
40
+ }
41
+ });
42
+ await program.parseAsync(process.argv).catch((e) => {
43
+ console.error(e);
44
+ process.exit(1);
45
+ });
46
+ //#endregion
47
+ export {};
48
+
49
+ //# 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 { sendTelegramMessage } from \"@send-bot/send-bot-core\";\nimport { homedir } from \"node:os\";\nimport { dirname, join } from \"node:path\";\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { z } from \"zod\";\nconst configPath = join(homedir(), \".config\", \"sendbot\", \"config.json\");\nconst configSchema = z.object({\n telegramBotToken: z.string().min(1).optional(),\n});\nfunction writeTelegramToken(token: string) {\n mkdirSync(dirname(configPath), { recursive: true });\n writeFileSync(\n configPath,\n `${JSON.stringify({ telegramBotToken: token }, null, 2)}\\n`,\n {\n mode: 0o600,\n },\n );\n}\nfunction getTelegramBotToken() {\n if (!existsSync(configPath)) {\n throw new Error(\"Telegram bot token in required, Rend sendbot init\");\n }\n const config = configSchema.parse(\n JSON.parse(readFileSync(configPath, \"utf-8\")),\n );\n if (!config.telegramBotToken)\n throw new Error(\"Telegram bot token in required, Run sendbot init\");\n return config.telegramBotToken;\n}\nconst program = new Command();\nprogram.name(\"sendbot\").description(\"Send CLI\");\nprogram\n .command(\"init\")\n .description(\"Configure sendbot cli local settings\")\n .requiredOption(\"--tg-token <botToken>\", \"Telegram Bot Token\")\n .action(async (options: { tgToken: string }) => {\n await writeTelegramToken(options.tgToken);\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 if (!chatId || !message) process.exit(1);\n try {\n console.log(\"sending message\");\n const res = await sendTelegramMessage({\n botToken: getTelegramBotToken(),\n chatId: chatId,\n message: message,\n });\n if (res.ok) {\n console.log(res);\n } else {\n throw new Error(\"error sending message\");\n }\n } catch (error) {\n console.error(error);\n process.exit(1);\n }\n });\n\nawait program.parseAsync(process.argv).catch((e) => {\n console.error(e);\n process.exit(1);\n});\n"],"mappings":";;;;;;;;AAOA,MAAM,aAAa,KAAK,QAAQ,GAAG,WAAW,WAAW,aAAa;AACtE,MAAM,eAAe,EAAE,OAAO,EAC5B,kBAAkB,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,EAC/C,CAAC;AACD,SAAS,mBAAmB,OAAe;CACzC,UAAU,QAAQ,UAAU,GAAG,EAAE,WAAW,KAAK,CAAC;CAClD,cACE,YACA,GAAG,KAAK,UAAU,EAAE,kBAAkB,MAAM,GAAG,MAAM,CAAC,EAAE,KACxD,EACE,MAAM,IACR,CACF;AACF;AACA,SAAS,sBAAsB;CAC7B,IAAI,CAAC,WAAW,UAAU,GACxB,MAAM,IAAI,MAAM,mDAAmD;CAErE,MAAM,SAAS,aAAa,MAC1B,KAAK,MAAM,aAAa,YAAY,OAAO,CAAC,CAC9C;CACA,IAAI,CAAC,OAAO,kBACV,MAAM,IAAI,MAAM,kDAAkD;CACpE,OAAO,OAAO;AAChB;AACA,MAAM,UAAU,IAAI,QAAQ;AAC5B,QAAQ,KAAK,SAAS,CAAC,CAAC,YAAY,UAAU;AAC9C,QACG,QAAQ,MAAM,CAAC,CACf,YAAY,sCAAsC,CAAC,CACnD,eAAe,yBAAyB,oBAAoB,CAAC,CAC7D,OAAO,OAAO,YAAiC;CAC9C,MAAM,mBAAmB,QAAQ,OAAO;AAC1C,CAAC;AACH,QACG,QAAQ,UAAU,CAAC,CACnB,YAAY,yBAAyB,CAAC,CACtC,SAAS,YAAY,kBAAkB,CAAC,CACxC,SAAS,aAAa,sBAAsB,CAAC,CAC7C,OAAO,OAAO,QAAgB,YAAoB;CACjD,IAAI,CAAC,UAAU,CAAC,SAAS,QAAQ,KAAK,CAAC;CACvC,IAAI;EACF,QAAQ,IAAI,iBAAiB;EAC7B,MAAM,MAAM,MAAM,oBAAoB;GACpC,UAAU,oBAAoB;GACtB;GACC;EACX,CAAC;EACD,IAAI,IAAI,IACN,QAAQ,IAAI,GAAG;OAEf,MAAM,IAAI,MAAM,uBAAuB;CAE3C,SAAS,OAAO;EACd,QAAQ,MAAM,KAAK;EACnB,QAAQ,KAAK,CAAC;CAChB;AACF,CAAC;AAEH,MAAM,QAAQ,WAAW,QAAQ,IAAI,CAAC,CAAC,OAAO,MAAM;CAClD,QAAQ,MAAM,CAAC;CACf,QAAQ,KAAK,CAAC;AAChB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@send-bot/send-bot",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "files": [
6
+ "dist"
7
+ ],
8
+ "module": "./dist/index.js",
9
+ "main": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+
15
+ "dependencies": {
16
+ "commander": "^15.0.0",
17
+ "@send-bot/send-bot-core": "workspace:*",
18
+ "zod": "^4.4.3"
19
+ },
20
+ "devDependencies": {
21
+ "@types/node": "^26.0.1"
22
+ },
23
+ "exports":{
24
+ ".":{
25
+ "import":"./dist/index.js",
26
+ "types":"./dist/index.d.ts"
27
+ }
28
+ },
29
+ "scripts": {
30
+ "build":"tsdown",
31
+ "pack:dry":"bun run build && bun pm pack --dry-run",
32
+ "prepublishOnly": "bun run build"
33
+ }
34
+ }