telegram-bot-api-nodejs 1.0.2 → 1.0.4

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 CHANGED
@@ -23,12 +23,7 @@ export interface SendMessageOptions extends SendBasicOptions {
23
23
  disable_web_page_preview?: boolean;
24
24
  entities?: MessageEntity[];
25
25
  }
26
- export interface SendPhotoOptions extends SendBasicOptions {
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;
@@ -490,9 +485,6 @@ interface BotCommand {
490
485
  command: string;
491
486
  description: string;
492
487
  }
493
- /**
494
- * Methods
495
- */
496
488
  export declare function setWebhook(token: string, body: SetWebHookOptions, signal: AbortSignal): Promise<Boolean>;
497
489
  export declare function deleteWebhook(token: string, signal: AbortSignal): Promise<Boolean>;
498
490
  /** @todo cehck if response is the same as in typings */
@@ -500,7 +492,11 @@ export declare function getWebhookInfo(token: string, signal: AbortSignal): Prom
500
492
  export declare function getMe(token: string, signal: AbortSignal): Promise<User>;
501
493
  export declare function sendMessage(token: string, payload: SendMessageOptions, signal: AbortSignal): Promise<Message>;
502
494
  export declare function editMessageText(token: string, payload: EditMessageTextOptions, signal: AbortSignal): Promise<Message>;
503
- export declare function sendPhoto(token: string, payload: SendPhotoOptions, signal: AbortSignal): Promise<Message>;
495
+ export declare function sendPhoto(token: string, payload: SendBasicOptions & {
496
+ photo: string;
497
+ caption?: string;
498
+ parse_mode?: ParseMode;
499
+ }, signal: AbortSignal): Promise<Message>;
504
500
  export declare function sendAnimation(token: string, payload: SendAnimationOptions, signal: AbortSignal): Promise<Message>;
505
501
  export declare function sendDocument(token: string, payload: SendDocumentOptions, signal: AbortSignal): Promise<Message>;
506
502
  export declare function setMessageReaction(token: string, payload: {
@@ -629,4 +625,10 @@ export declare class TelegramError extends Error {
629
625
  * Helpers
630
626
  */
631
627
  export declare const SUPPORTED_REACTION_EMOJI: string[];
628
+ export declare function isUnauthorizedError(err: unknown): err is Error;
629
+ export declare function isBotBlockedByUserError(err: unknown): err is Error;
630
+ export declare function isChatNotFoundError(err: unknown): err is Error;
631
+ export declare function isUserDeactivatedError(err: unknown): err is Error;
632
+ export declare function isBotKickedFromSupergroupError(err: unknown): err is Error;
633
+ export declare function isNotEnoughRightsError(err: unknown): err is Error;
632
634
  export {};
package/index.js CHANGED
@@ -1,13 +1,10 @@
1
1
  /**
2
- * Common headers for API calls
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",
@@ -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,
@@ -490,3 +487,21 @@ export const SUPPORTED_REACTION_EMOJI = ["👍", "👎", "\u2764\ufe0f" // red h
490
487
  "✍", "ðŸĪ—", "ðŸŦĄ", "🎅", "🎄", "☃", "💅", "ðŸĪŠ", "ðŸ—ŋ", "🆒", "💘", "🙉", "ðŸĶ„",
491
488
  "😘", "💊", "🙊", "😎", "ðŸ‘ū", "ðŸĪ·â€â™‚", "ðŸĪ·", "ðŸĪ·â€â™€", "ðŸ˜Ą"
492
489
  ];
490
+ export function isUnauthorizedError(err) {
491
+ return err instanceof Error && err.message === "Unauthorized";
492
+ }
493
+ export function isBotBlockedByUserError(err) {
494
+ return err instanceof Error && err.message.includes("Forbidden: bot was blocked by the user");
495
+ }
496
+ export function isChatNotFoundError(err) {
497
+ return err instanceof Error && err.message.includes("Bad Request: chat not found");
498
+ }
499
+ export function isUserDeactivatedError(err) {
500
+ return err instanceof Error && err.message.includes("Forbidden: user is deactivated");
501
+ }
502
+ export function isBotKickedFromSupergroupError(err) {
503
+ return err instanceof Error && err.message.includes("Forbidden: bot was kicked from the supergroup chat");
504
+ }
505
+ export function isNotEnoughRightsError(err) {
506
+ return err instanceof Error && err.message.includes("Bad Request: not enough rights to send text messages to the chat");
507
+ }
package/package.json CHANGED
@@ -1,10 +1,17 @@
1
1
  {
2
2
  "name": "telegram-bot-api-nodejs",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Telegram Bot API client for nodejs",
5
5
  "type": "module",
6
- "module": "index.js",
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",
@@ -14,7 +21,7 @@
14
21
  "author": "",
15
22
  "license": "ISC",
16
23
  "devDependencies": {
17
- "@types/node": "^20.8.10",
18
- "typescript": "^5.2.2"
24
+ "@types/node": "^20.11.17",
25
+ "typescript": "^5.3.3"
19
26
  }
20
27
  }