@manoj_dilz/sendkit-core 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.
@@ -0,0 +1,37 @@
1
+ import { z } from "zod";
2
+
3
+ //#region src/schemas.d.ts
4
+ declare const TelegramMessageInputSchema: z.ZodObject<{
5
+ chatId: z.ZodString;
6
+ message: z.ZodString;
7
+ }, z.core.$strip>;
8
+ declare const TelegramMessageOptionsSchema: z.ZodObject<{
9
+ chatId: z.ZodString;
10
+ message: z.ZodString;
11
+ botToken: z.ZodString;
12
+ }, z.core.$strip>;
13
+ declare const TelegramSendMessageRequestSchema: z.ZodObject<{
14
+ chat_id: z.ZodString;
15
+ text: z.ZodString;
16
+ }, z.core.$strip>;
17
+ declare const TelegramSendMessageResponseSchema: z.ZodObject<{
18
+ ok: z.ZodBoolean;
19
+ result: z.ZodOptional<z.ZodObject<{
20
+ message_id: z.ZodNumber;
21
+ }, z.core.$strip>>;
22
+ description: z.ZodOptional<z.ZodString>;
23
+ }, z.core.$strip>;
24
+ declare const TelegramMessageOutputSchema: z.ZodObject<{
25
+ ok: z.ZodLiteral<true>;
26
+ chatId: z.ZodString;
27
+ messageId: z.ZodNumber;
28
+ }, z.core.$strip>;
29
+ type TelegramMessageInput = z.infer<typeof TelegramMessageInputSchema>;
30
+ type TelegramMessageOptions = z.infer<typeof TelegramMessageOptionsSchema>;
31
+ type TelegramMessageOutput = z.infer<typeof TelegramMessageOutputSchema>;
32
+ //#endregion
33
+ //#region src/operations.d.ts
34
+ declare function sendTelegramMessage(input: TelegramMessageOptions): Promise<TelegramMessageOutput>;
35
+ //#endregion
36
+ export { TelegramMessageInput, TelegramMessageInputSchema, TelegramMessageOptions, TelegramMessageOptionsSchema, TelegramMessageOutput, TelegramMessageOutputSchema, TelegramSendMessageRequestSchema, TelegramSendMessageResponseSchema, sendTelegramMessage };
37
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,46 @@
1
+ import { z } from "zod";
2
+ //#region src/schemas.ts
3
+ const TelegramMessageInputSchema = z.object({
4
+ chatId: z.string().min(1, "Chat ID is required!"),
5
+ message: z.string().min(1, "Message is required!")
6
+ });
7
+ const TelegramMessageOptionsSchema = TelegramMessageInputSchema.extend({ botToken: z.string().min(1, "Telegram bot token in required") });
8
+ const TelegramSendMessageRequestSchema = z.object({
9
+ chat_id: z.string().min(1),
10
+ text: z.string().min(1)
11
+ });
12
+ const TelegramSendMessageResponseSchema = z.object({
13
+ ok: z.boolean(),
14
+ result: z.object({ message_id: z.number() }).optional(),
15
+ description: z.string().optional()
16
+ });
17
+ const TelegramMessageOutputSchema = z.object({
18
+ ok: z.literal(true),
19
+ chatId: z.string(),
20
+ messageId: z.number()
21
+ });
22
+ //#endregion
23
+ //#region src/operations.ts
24
+ async function sendTelegramMessage(input) {
25
+ const parsedInput = TelegramMessageOptionsSchema.parse(input);
26
+ const requestBody = TelegramSendMessageRequestSchema.parse({
27
+ chat_id: parsedInput.chatId,
28
+ text: parsedInput.message
29
+ });
30
+ const response = await fetch(`https://api.telegram.org/bot${parsedInput.botToken}/sendMessage`, {
31
+ method: "POST",
32
+ headers: { "Content-Type": "application/json" },
33
+ body: JSON.stringify(requestBody)
34
+ });
35
+ const data = TelegramSendMessageResponseSchema.parse(await response.json());
36
+ if (!response.ok || !data.ok || !data.result) throw new Error(data.description ?? "Telegram message request failed");
37
+ return TelegramMessageOutputSchema.parse({
38
+ ok: true,
39
+ chatId: parsedInput.chatId,
40
+ messageId: data.result.message_id
41
+ });
42
+ }
43
+ //#endregion
44
+ export { TelegramMessageInputSchema, TelegramMessageOptionsSchema, TelegramMessageOutputSchema, TelegramSendMessageRequestSchema, TelegramSendMessageResponseSchema, sendTelegramMessage };
45
+
46
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/schemas.ts","../src/operations.ts"],"sourcesContent":["import { z } from \"zod\";\n\nexport const TelegramMessageInputSchema = z.object({\n chatId: z.string().min(1, \"Chat ID is required!\"),\n message: z.string().min(1, \"Message is required!\"),\n});\n\nexport const TelegramMessageOptionsSchema = TelegramMessageInputSchema.extend({\n botToken: z.string().min(1, \"Telegram bot token in required\"),\n});\n\nexport const TelegramSendMessageRequestSchema = z.object({\n chat_id: z.string().min(1),\n text: z.string().min(1),\n});\n\nexport const TelegramSendMessageResponseSchema = z.object({\n ok: z.boolean(),\n result: z\n .object({\n message_id: z.number(),\n })\n .optional(),\n description: z.string().optional(),\n});\n\nexport const TelegramMessageOutputSchema = z.object({\n ok: z.literal(true),\n chatId: z.string(),\n messageId: z.number(),\n});\n\nexport type TelegramMessageInput = z.infer<typeof TelegramMessageInputSchema>;\nexport type TelegramMessageOptions = z.infer<typeof TelegramMessageOptionsSchema>;\nexport type TelegramMessageOutput = z.infer<typeof TelegramMessageOutputSchema>;\n","import {\n TelegramMessageOutputSchema,\n TelegramMessageOptionsSchema,\n TelegramSendMessageRequestSchema,\n TelegramSendMessageResponseSchema,\n type TelegramMessageOptions,\n type TelegramMessageOutput,\n} from \"./schemas\";\n\nexport async function sendTelegramMessage(\n input: TelegramMessageOptions,\n): Promise<TelegramMessageOutput> {\n const parsedInput = TelegramMessageOptionsSchema.parse(input);\n const requestBody = TelegramSendMessageRequestSchema.parse({\n chat_id: parsedInput.chatId,\n text: parsedInput.message,\n });\n\n const response = await fetch(`https://api.telegram.org/bot${parsedInput.botToken}/sendMessage`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify(requestBody),\n });\n const data = TelegramSendMessageResponseSchema.parse(await response.json());\n\n if (!response.ok || !data.ok || !data.result) {\n throw new Error(data.description ?? \"Telegram message request failed\");\n }\n\n return TelegramMessageOutputSchema.parse({\n ok: true,\n chatId: parsedInput.chatId,\n messageId: data.result.message_id,\n });\n}\n"],"mappings":";;AAEA,MAAa,6BAA6B,EAAE,OAAO;CACjD,QAAQ,EAAE,OAAO,CAAC,C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@
1
+ {
2
+ "name": "@manoj_dilz/sendkit-core",
3
+ "version": "0.0.0",
4
+ "files": [
5
+ "dist"
6
+ ],
7
+ "type": "module",
8
+ "main": "./dist/index.js",
9
+ "module": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.js"
15
+ }
16
+ },
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
20
+ "scripts": {
21
+ "build": "tsdown",
22
+ "pack:dry": "bun run build && npm pack --dry-run",
23
+ "prepublishOnly": "bun run build"
24
+ },
25
+ "dependencies": {
26
+ "zod": "^4.4.3"
27
+ }
28
+ }