telegram-bot-api-nodejs 1.0.32 → 1.0.34

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.
Files changed (3) hide show
  1. package/index.d.ts +2 -1
  2. package/index.js +17 -0
  3. package/package.json +3 -2
package/index.d.ts CHANGED
@@ -555,7 +555,7 @@ interface ChosenInlineResult {
555
555
  inline_message_id?: string;
556
556
  query: string;
557
557
  }
558
- interface Invoice {
558
+ export interface Invoice {
559
559
  title: string;
560
560
  description: string;
561
561
  start_parameter: string;
@@ -771,4 +771,5 @@ export declare function isNotEnoughRightsError(err: unknown): boolean;
771
771
  export declare function isUpgradeToSupergroupChatError(err: unknown): boolean;
772
772
  export declare function isTextMustBeNonEmptyError(err: unknown): boolean;
773
773
  export declare function isTooManyRequestsError(err: unknown): boolean;
774
+ export declare function parseRetryAfterTime(err: unknown): number;
774
775
  export {};
package/index.js CHANGED
@@ -568,3 +568,20 @@ export function isTextMustBeNonEmptyError(err) {
568
568
  export function isTooManyRequestsError(err) {
569
569
  return err instanceof Error && err.message.includes("Too Many Requests: retry after");
570
570
  }
571
+ export function parseRetryAfterTime(err) {
572
+ if (!(err instanceof Error)) {
573
+ throw new RangeError("`err` needs to be an Error");
574
+ }
575
+ if (!err.message.startsWith("Too Many Requests: retry after")) {
576
+ throw new RangeError(`'err' message does not start with "Too Many Requests: retry after" ("${err.message}")`);
577
+ }
578
+ const param = err.message.replace("Too Many Requests: retry after", "").trim();
579
+ if (!param) {
580
+ throw new RangeError(`'err' message does not match the format "Too Many Requests format"`);
581
+ }
582
+ const time = Number(param);
583
+ if (Number.isNaN(time)) {
584
+ throw new RangeError(`'err' message has invalid time parameter ("${err.message}"`);
585
+ }
586
+ return time;
587
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "telegram-bot-api-nodejs",
3
- "version": "1.0.32",
3
+ "version": "1.0.34",
4
4
  "description": "Telegram Bot API client for nodejs",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -17,7 +17,8 @@
17
17
  "build": "tsc",
18
18
  "watch": "tsc --watch",
19
19
  "pretest": "npm run build",
20
- "test": "node --test"
20
+ "test": "node --test",
21
+ "spec": "node --test spec.js"
21
22
  },
22
23
  "author": "",
23
24
  "license": "ISC",