gramio 0.0.40 → 0.0.41

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/bot.js CHANGED
@@ -44,11 +44,14 @@ const callback_data_1 = require("@gramio/callback-data");
44
44
  const contexts_1 = require("@gramio/contexts");
45
45
  const files_1 = require("@gramio/files");
46
46
  const format_1 = require("@gramio/format");
47
+ const debug_1 = __importDefault(require("debug"));
47
48
  const inspectable_1 = require("inspectable");
48
49
  const undici_1 = require("undici");
49
50
  const errors_1 = require("./errors");
50
51
  const plugin_1 = require("./plugin");
51
52
  const updates_1 = require("./updates");
53
+ const $debugger = (0, debug_1.default)("gramio");
54
+ const debug$api = $debugger.extend("api");
52
55
  /** Bot instance
53
56
  *
54
57
  * @example
@@ -134,7 +137,11 @@ let Bot = (() => {
134
137
  this.options = {
135
138
  ...(typeof tokenOrOptions === "object" ? tokenOrOptions : options),
136
139
  token,
137
- api: { ...options?.api, baseURL: "https://api.telegram.org/bot" },
140
+ api: {
141
+ baseURL: "https://api.telegram.org/bot",
142
+ retryGetUpdatesWait: 1000,
143
+ ...options?.api,
144
+ },
138
145
  };
139
146
  if (!(options?.plugins &&
140
147
  "format" in options.plugins &&
@@ -165,6 +172,7 @@ let Bot = (() => {
165
172
  }
166
173
  }
167
174
  async _callApi(method, params = {}) {
175
+ const debug$api$method = debug$api.extend(method);
168
176
  const url = `${this.options.api.baseURL}${this.options.token}/${method}`;
169
177
  const reqOptions = {
170
178
  method: "POST",
@@ -190,8 +198,10 @@ let Bot = (() => {
190
198
  };
191
199
  reqOptions.body = JSON.stringify(params);
192
200
  }
201
+ debug$api$method("options: %j", reqOptions);
193
202
  const response = await (0, undici_1.request)(url, reqOptions);
194
203
  const data = (await response.body.json());
204
+ debug$api$method("response: %j", data);
195
205
  if (!data.ok) {
196
206
  const err = new errors_1.TelegramError(data, method, params);
197
207
  // @ts-expect-error
@@ -678,7 +688,7 @@ let Bot = (() => {
678
688
  ?.replace(`@${this.info.username}`, "");
679
689
  // @ts-expect-error
680
690
  context.args = context.text?.slice(entity.length).trim() || null;
681
- return cmd?.startsWith(command);
691
+ return cmd === command;
682
692
  }))
683
693
  // @ts-expect-error
684
694
  return handler(context);
package/dist/types.d.ts CHANGED
@@ -25,6 +25,11 @@ export interface BotOptions {
25
25
  * @default false
26
26
  * */
27
27
  useTest?: boolean;
28
+ /**
29
+ * Time in milliseconds before calling {@link APIMethods.getUpdates | getUpdates} again
30
+ * @default 1000
31
+ */
32
+ retryGetUpdatesWait?: number;
28
33
  };
29
34
  }
30
35
  /**
package/dist/updates.js CHANGED
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Updates = void 0;
4
+ const promises_1 = require("node:timers/promises");
4
5
  const contexts_1 = require("@gramio/contexts");
5
6
  const composer_1 = require("./composer");
7
+ const errors_1 = require("./errors");
6
8
  class Updates {
7
9
  bot;
8
10
  isStarted = false;
@@ -66,10 +68,16 @@ class Updates {
66
68
  const updates = await this.bot.api.getUpdates({
67
69
  ...params,
68
70
  offset: this.offset,
71
+ suppress: true,
69
72
  });
70
- for await (const update of updates) {
71
- //TODO: update errors
72
- await this.handleUpdate(update).catch(console.error);
73
+ if (updates instanceof errors_1.TelegramError || typeof updates === "undefined") {
74
+ await promises_1.scheduler.wait(this.bot.options.api.retryGetUpdatesWait);
75
+ }
76
+ else {
77
+ for await (const update of updates) {
78
+ //TODO: update errors
79
+ await this.handleUpdate(update).catch(console.error);
80
+ }
73
81
  }
74
82
  }
75
83
  }
@@ -30,49 +30,6 @@ export type WebhookHandlers = keyof typeof frameworks;
30
30
  * });
31
31
  * ```
32
32
  */
33
- export declare function webhookHandler<Framework extends keyof typeof frameworks>(bot: Bot, framework: Framework, secretToken?: string): ReturnType<{
34
- elysia: ({ body, headers }: any) => {
35
- update: any;
36
- header: any;
37
- unauthorized: () => import("undici").Response;
38
- };
39
- fastify: (request: any, reply: any) => {
40
- update: any;
41
- header: any;
42
- unauthorized: () => any;
43
- };
44
- hono: (c: any) => {
45
- update: any;
46
- header: any;
47
- unauthorized: () => any;
48
- };
49
- express: (req: any, res: any) => {
50
- update: any;
51
- header: any;
52
- unauthorized: () => any;
53
- };
54
- koa: (ctx: any) => {
55
- update: any;
56
- header: any;
57
- unauthorized: () => void;
58
- };
59
- http: (req: any, res: any) => {
60
- update: Promise<import("@gramio/types").TelegramUpdate>;
61
- header: any;
62
- unauthorized: () => any;
63
- };
64
- "std/http": (req: any) => {
65
- update: any;
66
- header: any;
67
- response: () => import("undici").Response;
68
- unauthorized: () => import("undici").Response;
69
- };
70
- "Bun.serve": (req: any) => {
71
- update: any;
72
- header: any;
73
- response: () => import("undici").Response;
74
- unauthorized: () => import("undici").Response;
75
- };
76
- }[Framework]> extends {
33
+ export declare function webhookHandler<Framework extends keyof typeof frameworks>(bot: Bot, framework: Framework, secretToken?: string): ReturnType<(typeof frameworks)[Framework]> extends {
77
34
  response: () => any;
78
35
  } ? (...args: Parameters<(typeof frameworks)[Framework]>) => ReturnType<ReturnType<(typeof frameworks)[Framework]>["response"]> : (...args: Parameters<(typeof frameworks)[Framework]>) => void;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.webhookHandler = void 0;
3
+ exports.webhookHandler = webhookHandler;
4
4
  const adapters_1 = require("./adapters");
5
5
  /**
6
6
  * Setup handler with yours web-framework to receive updates via webhook
@@ -44,4 +44,3 @@ function webhookHandler(bot, framework, secretToken) {
44
44
  return response();
45
45
  });
46
46
  }
47
- exports.webhookHandler = webhookHandler;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gramio",
3
3
  "type": "commonjs",
4
- "version": "0.0.40",
4
+ "version": "0.0.41",
5
5
  "description": "Powerful Telegram Bot API framework",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
@@ -28,8 +28,9 @@
28
28
  "license": "ISC",
29
29
  "devDependencies": {
30
30
  "@biomejs/biome": "1.7.3",
31
- "@types/node": "^20.14.5",
32
- "typescript": "^5.4.5"
31
+ "@types/debug": "^4.1.12",
32
+ "@types/node": "^20.14.9",
33
+ "typescript": "^5.5.2"
33
34
  },
34
35
  "dependencies": {
35
36
  "@gramio/callback-data": "^0.0.3",
@@ -38,6 +39,7 @@
38
39
  "@gramio/format": "^0.1.3",
39
40
  "@gramio/keyboards": "^0.3.3",
40
41
  "@gramio/types": "^7.5.0",
42
+ "debug": "^4.3.5",
41
43
  "inspectable": "^3.0.2",
42
44
  "middleware-io": "^2.8.1",
43
45
  "undici": "^6.19.2"