@boyanivskyy-packages/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 +39 -0
- package/dist/index.js +50 -0
- package/dist/index.js.map +1 -0
- package/package.json +28 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
//#region src/schemas.d.ts
|
|
3
|
+
export declare const telegramMessageInputSchema: z.ZodObject<{
|
|
4
|
+
chatId: z.ZodString;
|
|
5
|
+
message: z.ZodString;
|
|
6
|
+
}, z.core.$strip>;
|
|
7
|
+
export declare const telegramMessageOptionsSchema: z.ZodObject<{
|
|
8
|
+
chatId: z.ZodString;
|
|
9
|
+
message: z.ZodString;
|
|
10
|
+
botToken: z.ZodString;
|
|
11
|
+
}, z.core.$strip>;
|
|
12
|
+
export declare const telegramSendMessageSchema: z.ZodObject<{
|
|
13
|
+
chat_id: z.ZodString;
|
|
14
|
+
text: z.ZodString;
|
|
15
|
+
}, z.core.$strip>;
|
|
16
|
+
export declare const telegramSendMessageRequestSchema: z.ZodObject<{
|
|
17
|
+
chat_id: z.ZodString;
|
|
18
|
+
text: z.ZodString;
|
|
19
|
+
}, z.core.$strip>;
|
|
20
|
+
export declare const telegramSendMessageResponseSchema: z.ZodObject<{
|
|
21
|
+
ok: z.ZodBoolean;
|
|
22
|
+
result: z.ZodOptional<z.ZodObject<{
|
|
23
|
+
message_id: z.ZodNumber;
|
|
24
|
+
}, z.core.$strip>>;
|
|
25
|
+
description: z.ZodOptional<z.ZodString>;
|
|
26
|
+
}, z.core.$strip>;
|
|
27
|
+
export declare const telegramMessageOutputSchema: z.ZodObject<{
|
|
28
|
+
ok: z.ZodLiteral<true>;
|
|
29
|
+
chatId: z.ZodString;
|
|
30
|
+
messageId: z.ZodNumber;
|
|
31
|
+
}, z.core.$strip>;
|
|
32
|
+
export type TelegramMessageInput = z.infer<typeof telegramMessageInputSchema>;
|
|
33
|
+
export type TelegramMessageOptions = z.infer<typeof telegramMessageOptionsSchema>;
|
|
34
|
+
export type TelegramMessageOutput = z.infer<typeof telegramMessageOutputSchema>;
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/operations.d.ts
|
|
37
|
+
export declare function sendTelegramMessage(input: TelegramMessageOptions): Promise<TelegramMessageOutput>;
|
|
38
|
+
//#endregion
|
|
39
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
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 telegramSendMessageSchema = z.object({
|
|
9
|
+
chat_id: z.string().min(1),
|
|
10
|
+
text: z.string().min(1)
|
|
11
|
+
});
|
|
12
|
+
const telegramSendMessageRequestSchema = z.object({
|
|
13
|
+
chat_id: z.string().min(1),
|
|
14
|
+
text: z.string().min(1)
|
|
15
|
+
});
|
|
16
|
+
const telegramSendMessageResponseSchema = z.object({
|
|
17
|
+
ok: z.boolean(),
|
|
18
|
+
result: z.object({ message_id: z.number() }).optional(),
|
|
19
|
+
description: z.string().optional()
|
|
20
|
+
});
|
|
21
|
+
const telegramMessageOutputSchema = z.object({
|
|
22
|
+
ok: z.literal(true),
|
|
23
|
+
chatId: z.string(),
|
|
24
|
+
messageId: z.number()
|
|
25
|
+
});
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/operations.ts
|
|
28
|
+
async function sendTelegramMessage(input) {
|
|
29
|
+
const parsedInput = telegramMessageOptionsSchema.parse(input);
|
|
30
|
+
const requestBody = telegramSendMessageRequestSchema.parse({
|
|
31
|
+
chat_id: parsedInput.chatId,
|
|
32
|
+
text: parsedInput.message
|
|
33
|
+
});
|
|
34
|
+
const response = await fetch(`https://api.telegram.org/bot${parsedInput.botToken}/sendMessage`, {
|
|
35
|
+
method: "POST",
|
|
36
|
+
headers: { "Content-Type": "application/json" },
|
|
37
|
+
body: await Response.json(requestBody).text()
|
|
38
|
+
});
|
|
39
|
+
const data = telegramSendMessageResponseSchema.parse(await response.json());
|
|
40
|
+
if (!response.ok || !data.ok || !data.result) throw new Error(data.description ?? "Telegram message request failed");
|
|
41
|
+
return telegramMessageOutputSchema.parse({
|
|
42
|
+
ok: true,
|
|
43
|
+
chatId: parsedInput.chatId,
|
|
44
|
+
messageId: data.result.message_id
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
export { sendTelegramMessage, telegramMessageInputSchema, telegramMessageOptionsSchema, telegramMessageOutputSchema, telegramSendMessageRequestSchema, telegramSendMessageResponseSchema, telegramSendMessageSchema };
|
|
49
|
+
|
|
50
|
+
//# 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 telegramSendMessageSchema = z.object({\n chat_id: z.string().min(1),\n text: z.string().min(1),\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 type TelegramMessageOptions,\n type TelegramMessageOutput,\n telegramMessageOptionsSchema,\n telegramMessageOutputSchema,\n telegramSendMessageRequestSchema,\n telegramSendMessageResponseSchema,\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: { 'Content-Type': 'application/json' },\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(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,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,4BAA4B,EAAE,OAAO;CAChD,SAAS,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;CACzB,MAAM,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;AACxB,CAAC;AAED,MAAa,mCAAmC,EAAE,OAAO;CACvD,SAAS,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;CACzB,MAAM,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;AACxB,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;;;AC1BD,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,EAAE,gBAAgB,mBAAmB;EAC9C,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,KAAK,eAAe,iCAAiC;CAGvE,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": "@boyanivskyy-packages/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.6.1"
|
|
27
|
+
}
|
|
28
|
+
}
|