telegram-bot-api-nodejs 1.0.1 → 1.0.3
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/index.d.ts +21 -23
- package/index.js +21 -21
- package/package.json +13 -5
- package/index.ts +0 -1616
- package/tsconfig.json +0 -8
package/index.d.ts
CHANGED
|
@@ -23,12 +23,7 @@ export interface SendMessageOptions extends SendBasicOptions {
|
|
|
23
23
|
disable_web_page_preview?: boolean;
|
|
24
24
|
entities?: MessageEntity[];
|
|
25
25
|
}
|
|
26
|
-
|
|
27
|
-
photo: string;
|
|
28
|
-
parse_mode?: ParseMode;
|
|
29
|
-
caption?: string;
|
|
30
|
-
}
|
|
31
|
-
export interface SendAnimationOptions extends SendBasicOptions {
|
|
26
|
+
interface SendAnimationOptions extends SendBasicOptions {
|
|
32
27
|
animation: string;
|
|
33
28
|
parse_mode?: ParseMode;
|
|
34
29
|
caption?: string;
|
|
@@ -45,9 +40,6 @@ export interface AnswerCallbackQueryOptions {
|
|
|
45
40
|
url?: string;
|
|
46
41
|
cache_time?: number;
|
|
47
42
|
}
|
|
48
|
-
export interface GetChatOptions {
|
|
49
|
-
chat_id: string;
|
|
50
|
-
}
|
|
51
43
|
interface SetMyCommandsOptions {
|
|
52
44
|
commands: BotCommand[];
|
|
53
45
|
}
|
|
@@ -63,11 +55,6 @@ interface EditMessageReplyMarkupOptions {
|
|
|
63
55
|
message_id?: number | string;
|
|
64
56
|
inline_message_id?: string;
|
|
65
57
|
}
|
|
66
|
-
export interface GetUserProfilePhotosOptions {
|
|
67
|
-
user_id: number | string;
|
|
68
|
-
offset?: number;
|
|
69
|
-
limit?: number;
|
|
70
|
-
}
|
|
71
58
|
interface PassportFile {
|
|
72
59
|
file_id: string;
|
|
73
60
|
file_size: number;
|
|
@@ -498,9 +485,6 @@ interface BotCommand {
|
|
|
498
485
|
command: string;
|
|
499
486
|
description: string;
|
|
500
487
|
}
|
|
501
|
-
/**
|
|
502
|
-
* Methods
|
|
503
|
-
*/
|
|
504
488
|
export declare function setWebhook(token: string, body: SetWebHookOptions, signal: AbortSignal): Promise<Boolean>;
|
|
505
489
|
export declare function deleteWebhook(token: string, signal: AbortSignal): Promise<Boolean>;
|
|
506
490
|
/** @todo cehck if response is the same as in typings */
|
|
@@ -508,7 +492,11 @@ export declare function getWebhookInfo(token: string, signal: AbortSignal): Prom
|
|
|
508
492
|
export declare function getMe(token: string, signal: AbortSignal): Promise<User>;
|
|
509
493
|
export declare function sendMessage(token: string, payload: SendMessageOptions, signal: AbortSignal): Promise<Message>;
|
|
510
494
|
export declare function editMessageText(token: string, payload: EditMessageTextOptions, signal: AbortSignal): Promise<Message>;
|
|
511
|
-
export declare function sendPhoto(token: string, payload:
|
|
495
|
+
export declare function sendPhoto(token: string, payload: SendBasicOptions & {
|
|
496
|
+
photo: string;
|
|
497
|
+
caption?: string;
|
|
498
|
+
parse_mode?: ParseMode;
|
|
499
|
+
}, signal: AbortSignal): Promise<Message>;
|
|
512
500
|
export declare function sendAnimation(token: string, payload: SendAnimationOptions, signal: AbortSignal): Promise<Message>;
|
|
513
501
|
export declare function sendDocument(token: string, payload: SendDocumentOptions, signal: AbortSignal): Promise<Message>;
|
|
514
502
|
export declare function setMessageReaction(token: string, payload: {
|
|
@@ -517,10 +505,18 @@ export declare function setMessageReaction(token: string, payload: {
|
|
|
517
505
|
reaction?: ReactionType[];
|
|
518
506
|
is_big?: boolean;
|
|
519
507
|
}, signal: AbortSignal): Promise<Boolean>;
|
|
520
|
-
export declare function getUserProfilePhotos(token: string, payload:
|
|
521
|
-
|
|
508
|
+
export declare function getUserProfilePhotos(token: string, payload: {
|
|
509
|
+
user_id: number | string;
|
|
510
|
+
offset?: number;
|
|
511
|
+
limit?: number;
|
|
512
|
+
}, signal: AbortSignal): Promise<UserProfilePhotos>;
|
|
513
|
+
export declare function getFile(token: string, payload: {
|
|
514
|
+
file_id: string;
|
|
515
|
+
}, signal: AbortSignal): Promise<File>;
|
|
522
516
|
export declare function answerCallbackQuery(token: string, payload: AnswerCallbackQueryOptions, signal: AbortSignal): Promise<File>;
|
|
523
|
-
export declare function getChat(token: string, payload:
|
|
517
|
+
export declare function getChat(token: string, payload: {
|
|
518
|
+
chat_id: string;
|
|
519
|
+
}, signal: AbortSignal): Promise<Chat>;
|
|
524
520
|
export declare function getChatMember(token: string, payload: {
|
|
525
521
|
chat_id: string;
|
|
526
522
|
user_id: string;
|
|
@@ -619,9 +615,11 @@ export declare function parsePollOption(v: PollOption): {
|
|
|
619
615
|
* @see https://core.telegram.org/bots/api#callbackquery
|
|
620
616
|
*/
|
|
621
617
|
export declare function parseCallbackQuery(v?: CallbackQuery): CallbackQuery | undefined;
|
|
618
|
+
export declare function parseResponse<T>(response: Response): Promise<T>;
|
|
622
619
|
export declare class TelegramError extends Error {
|
|
623
|
-
|
|
624
|
-
|
|
620
|
+
error_code: number;
|
|
621
|
+
parameters: Record<string, any>;
|
|
622
|
+
constructor(message: string, error_code: number, parameters?: Record<string, any>);
|
|
625
623
|
}
|
|
626
624
|
/**
|
|
627
625
|
* Helpers
|
package/index.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Methods
|
|
3
3
|
*/
|
|
4
4
|
const headers = {
|
|
5
5
|
"Accept": "application/json",
|
|
6
6
|
"Content-Type": "application/json",
|
|
7
7
|
};
|
|
8
|
-
/**
|
|
9
|
-
* Methods
|
|
10
|
-
*/
|
|
11
8
|
export function setWebhook(token, body, signal) {
|
|
12
9
|
return fetch(`https://api.telegram.org/bot${token}/setWebhook`, {
|
|
13
10
|
method: "POST",
|
|
@@ -97,10 +94,10 @@ export function getUserProfilePhotos(token, payload, signal) {
|
|
|
97
94
|
signal
|
|
98
95
|
}).then((parseResponse));
|
|
99
96
|
}
|
|
100
|
-
export function getFile(token,
|
|
97
|
+
export function getFile(token, payload, signal) {
|
|
101
98
|
return fetch(`https://api.telegram.org/bot${token}/getFile`, {
|
|
102
99
|
method: "POST",
|
|
103
|
-
body: JSON.stringify(
|
|
100
|
+
body: JSON.stringify(payload),
|
|
104
101
|
headers,
|
|
105
102
|
signal
|
|
106
103
|
}).then((parseResponse));
|
|
@@ -176,17 +173,17 @@ export function parseMessage(m) {
|
|
|
176
173
|
date: Number(m.date),
|
|
177
174
|
chat: parseChat(m.chat),
|
|
178
175
|
text: String(m.text ?? ""),
|
|
179
|
-
forward_from: m.forward_from ? parseUser(m.forward_from) : void 0,
|
|
180
|
-
forward_from_chat: m.forward_from_chat ? parseChat(m.forward_from_chat) : void 0,
|
|
181
|
-
forward_from_message_id: m.forward_from_message_id ? Number(m.forward_from_message_id) : void 0,
|
|
182
|
-
forward_signature: m.forward_signature ? String(m.forward_signature) : void 0,
|
|
183
|
-
forward_sender_name: m.forward_sender_name ? String(m.forward_sender_name) : void 0,
|
|
184
|
-
forward_date: m.forward_date ? Number(m.forward_date) : void 0,
|
|
176
|
+
forward_from: m.forward_from ? parseUser(m.forward_from) : void 0, // User;
|
|
177
|
+
forward_from_chat: m.forward_from_chat ? parseChat(m.forward_from_chat) : void 0, // Chat;
|
|
178
|
+
forward_from_message_id: m.forward_from_message_id ? Number(m.forward_from_message_id) : void 0, // number;
|
|
179
|
+
forward_signature: m.forward_signature ? String(m.forward_signature) : void 0, // string;
|
|
180
|
+
forward_sender_name: m.forward_sender_name ? String(m.forward_sender_name) : void 0, // string;
|
|
181
|
+
forward_date: m.forward_date ? Number(m.forward_date) : void 0, // number;
|
|
185
182
|
// reply_to_message: m.reply_to_message ? parseMessage(m.reply_to_message) : void 0, // Message;
|
|
186
|
-
edit_date: m.edit_date ? Number(m.edit_date) : void 0,
|
|
187
|
-
media_group_id: m.media_group_id ? String(m.media_group_id) : void 0,
|
|
188
|
-
author_signature: m.author_signature ? String(m.author_signature) : void 0,
|
|
189
|
-
entities: m.entities ? parseEntities(m.entities) : void 0,
|
|
183
|
+
edit_date: m.edit_date ? Number(m.edit_date) : void 0, // number;
|
|
184
|
+
media_group_id: m.media_group_id ? String(m.media_group_id) : void 0, // string;
|
|
185
|
+
author_signature: m.author_signature ? String(m.author_signature) : void 0, // string;
|
|
186
|
+
entities: m.entities ? parseEntities(m.entities) : void 0, // MessageEntity[];
|
|
190
187
|
// caption_entities: m.caption_entities ? parseSometh(m.caption_entities) : void 0, // MessageEntity[];
|
|
191
188
|
audio: m.audio ? parseAudio(m.audio) : void 0,
|
|
192
189
|
document: m.document ? parseDocument(m.document) : void 0,
|
|
@@ -450,7 +447,7 @@ function parseReactionCount(reaction) {
|
|
|
450
447
|
total_count: Number(reaction.total_count),
|
|
451
448
|
};
|
|
452
449
|
}
|
|
453
|
-
function parseResponse(response) {
|
|
450
|
+
export function parseResponse(response) {
|
|
454
451
|
return response.text().then(function (text) {
|
|
455
452
|
let data;
|
|
456
453
|
try {
|
|
@@ -465,14 +462,17 @@ function parseResponse(response) {
|
|
|
465
462
|
}
|
|
466
463
|
const error_code = Number(data.error_code ?? 0);
|
|
467
464
|
const description = String(data.description ?? "");
|
|
468
|
-
|
|
465
|
+
const parameters = data.parameters || {};
|
|
466
|
+
throw new TelegramError(description, error_code, parameters);
|
|
469
467
|
});
|
|
470
468
|
}
|
|
471
469
|
export class TelegramError extends Error {
|
|
472
|
-
|
|
473
|
-
|
|
470
|
+
error_code;
|
|
471
|
+
parameters;
|
|
472
|
+
constructor(message, error_code, parameters = {}) {
|
|
474
473
|
super(message);
|
|
475
|
-
this.
|
|
474
|
+
this.error_code = error_code;
|
|
475
|
+
this.parameters = parameters;
|
|
476
476
|
}
|
|
477
477
|
}
|
|
478
478
|
/**
|
package/package.json
CHANGED
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "telegram-bot-api-nodejs",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Telegram Bot API client for nodejs",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"
|
|
6
|
+
"main": "index.js",
|
|
7
7
|
"types": "index.d.ts",
|
|
8
|
+
"engines": {
|
|
9
|
+
"node": ">=18.x"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"index.js",
|
|
13
|
+
"index.d.ts"
|
|
14
|
+
],
|
|
8
15
|
"scripts": {
|
|
9
16
|
"prepublishOnly": "npm run build",
|
|
10
17
|
"build": "tsc",
|
|
11
|
-
"
|
|
18
|
+
"pretest": "npm run build",
|
|
19
|
+
"test": "node --test"
|
|
12
20
|
},
|
|
13
21
|
"author": "",
|
|
14
22
|
"license": "ISC",
|
|
15
23
|
"devDependencies": {
|
|
16
|
-
"@types/node": "^20.
|
|
17
|
-
"typescript": "^5.
|
|
24
|
+
"@types/node": "^20.11.17",
|
|
25
|
+
"typescript": "^5.3.3"
|
|
18
26
|
}
|
|
19
27
|
}
|