@mrb-dev/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.
- package/dist/index.d.ts +37 -0
- package/dist/index.js +46 -0
- package/dist/index.js.map +1 -0
- package/package.json +28 -0
package/dist/index.d.ts
ADDED
|
@@ -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, TelegramMessageOptions, TelegramMessageOutput, sendTelegramMessage, telegramMessageInputSchema, telegramMessageOptionsSchema, telegramMessageOutputSchema, telegramSendMessageRequestSchema, telegramSendMessageResponseSchema };
|
|
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 is required") });
|
|
8
|
+
const telegramSendMessageRequestSchema = z.object({
|
|
9
|
+
chat_id: z.string().min(1, "Chat ID is required"),
|
|
10
|
+
text: z.string().min(1, "Message is required")
|
|
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: await Response.json(requestBody).text()
|
|
34
|
+
});
|
|
35
|
+
const data = telegramSendMessageResponseSchema.parse(await response.json());
|
|
36
|
+
if (!response.ok || !data.ok || !data.result) throw new Error(`Failed to send Telegram message: ${data.description ?? "Unknown error"}`);
|
|
37
|
+
return telegramMessageOutputSchema.parse({
|
|
38
|
+
ok: true,
|
|
39
|
+
chatId: parsedInput.chatId,
|
|
40
|
+
messageId: data.result.message_id
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
export { sendTelegramMessage, telegramMessageInputSchema, telegramMessageOptionsSchema, telegramMessageOutputSchema, telegramSendMessageRequestSchema, telegramSendMessageResponseSchema };
|
|
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 is required\"),\n});\n\nexport const telegramSendMessageRequestSchema = z.object({\n chat_id: z.string().min(1, \"Chat ID is required\"),\n text: z.string().min(1, \"Message is required\"),\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: await Response.json(requestBody).text(),\n });\n\n const data = telegramSendMessageResponseSchema.parse(await response.json());\n\n if (!response.ok || !data.ok || !data.result) {\n throw new Error(`Failed to send Telegram message: ${data.description ?? \"Unknown error\"}`);\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,CAAC,IAAI,GAAG,qBAAqB;CAC/C,SAAS,EAAE,OAAO,CAAC,CAAC,IAAI,GAAG,qBAAqB;AAClD,CAAC;AAED,MAAa,+BAA+B,2BAA2B,OAAO,EAC5E,UAAU,EAAE,OAAO,CAAC,CAAC,IAAI,GAAG,gCAAgC,EAC9D,CAAC;AAED,MAAa,mCAAmC,EAAE,OAAO;CACvD,SAAS,EAAE,OAAO,CAAC,CAAC,IAAI,GAAG,qBAAqB;CAChD,MAAM,EAAE,OAAO,CAAC,CAAC,IAAI,GAAG,qBAAqB;AAC/C,CAAC;AAED,MAAa,oCAAoC,EAAE,OAAO;CACxD,IAAI,EAAE,QAAQ;CACd,QAAQ,EACL,OAAO,EACN,YAAY,EAAE,OAAO,EACvB,CAAC,CAAC,CACD,SAAS;CACZ,aAAa,EAAE,OAAO,CAAC,CAAC,SAAS;AACnC,CAAC;AAED,MAAa,8BAA8B,EAAE,OAAO;CAClD,IAAI,EAAE,QAAQ,IAAI;CAClB,QAAQ,EAAE,OAAO;CACjB,WAAW,EAAE,OAAO;AACtB,CAAC;;;ACrBD,eAAsB,oBACpB,OACgC;CAChC,MAAM,cAAc,6BAA6B,MAAM,KAAK;CAC5D,MAAM,cAAc,iCAAiC,MAAM;EACzD,SAAS,YAAY;EACrB,MAAM,YAAY;CACpB,CAAC;CAED,MAAM,WAAW,MAAM,MAAM,+BAA+B,YAAY,SAAS,eAAe;EAC9F,QAAQ;EACR,SAAS,EACP,gBAAgB,mBAClB;EACA,MAAM,MAAM,SAAS,KAAK,WAAW,CAAC,CAAC,KAAK;CAC9C,CAAC;CAED,MAAM,OAAO,kCAAkC,MAAM,MAAM,SAAS,KAAK,CAAC;CAE1E,IAAI,CAAC,SAAS,MAAM,CAAC,KAAK,MAAM,CAAC,KAAK,QACpC,MAAM,IAAI,MAAM,oCAAoC,KAAK,eAAe,iBAAiB;CAG3F,OAAO,4BAA4B,MAAM;EACvC,IAAI;EACJ,QAAQ,YAAY;EACpB,WAAW,KAAK,OAAO;CACzB,CAAC;AACH"}
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mrb-dev/sendkit-core",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"files": [
|
|
5
|
+
"dist"
|
|
6
|
+
],
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"type": "module",
|
|
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
|
+
}
|