gramio 0.0.49 → 0.0.50

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
@@ -38,8 +38,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
38
38
  };
39
39
  Object.defineProperty(exports, "__esModule", { value: true });
40
40
  exports.Bot = void 0;
41
- const node_buffer_1 = require("node:buffer");
42
41
  const promises_1 = __importDefault(require("node:fs/promises"));
42
+ const node_stream_1 = require("node:stream");
43
43
  const callback_data_1 = require("@gramio/callback-data");
44
44
  const contexts_1 = require("@gramio/contexts");
45
45
  const files_1 = require("@gramio/files");
@@ -253,11 +253,14 @@ let Bot = (() => {
253
253
  const file = await this.api.getFile({ file_id: fileId });
254
254
  const url = `${this.options.api.baseURL.replace("/bot", "/file/bot")}${this.options.token}/${file.file_path}`;
255
255
  const res = await fetch(url);
256
- const buffer = await res.arrayBuffer();
257
256
  if (path) {
258
- await promises_1.default.writeFile(path, node_buffer_1.Buffer.from(buffer));
257
+ if (!res.body)
258
+ throw new Error("Response without body (should be never throw)");
259
+ // @ts-ignore denoo
260
+ await promises_1.default.writeFile(path, node_stream_1.Readable.fromWeb(res.body));
259
261
  return path;
260
262
  }
263
+ const buffer = await res.arrayBuffer();
261
264
  return buffer;
262
265
  }
263
266
  /**
@@ -619,9 +622,7 @@ let Bot = (() => {
619
622
  if ((typeof trigger === "string" && context.query === trigger) ||
620
623
  // @ts-expect-error
621
624
  (typeof trigger === "function" && trigger(context)) ||
622
- (trigger instanceof RegExp &&
623
- context.query &&
624
- trigger.test(context.query))) {
625
+ (trigger instanceof RegExp && trigger.test(context.query))) {
625
626
  //@ts-expect-error
626
627
  context.args =
627
628
  trigger instanceof RegExp ? context.query?.match(trigger) : null;
@@ -675,9 +676,7 @@ let Bot = (() => {
675
676
  if ((typeof trigger === "string" && context.query === trigger) ||
676
677
  // @ts-expect-error
677
678
  (typeof trigger === "function" && trigger(context)) ||
678
- (trigger instanceof RegExp &&
679
- context.query &&
680
- trigger.test(context.query))) {
679
+ (trigger instanceof RegExp && trigger.test(context.query))) {
681
680
  //@ts-expect-error
682
681
  context.args =
683
682
  trigger instanceof RegExp ? context.query?.match(trigger) : null;
@@ -697,15 +696,13 @@ let Bot = (() => {
697
696
  */
698
697
  hears(trigger, handler) {
699
698
  return this.on("message", (context, next) => {
700
- if ((typeof trigger === "string" && context.text === trigger) ||
699
+ const text = context.text ?? context.caption;
700
+ if ((typeof trigger === "string" && text === trigger) ||
701
701
  // @ts-expect-error
702
702
  (typeof trigger === "function" && trigger(context)) ||
703
- (trigger instanceof RegExp &&
704
- context.text &&
705
- trigger.test(context.text))) {
703
+ (trigger instanceof RegExp && text && trigger.test(text))) {
706
704
  //@ts-expect-error
707
- context.args =
708
- trigger instanceof RegExp ? context.text?.match(trigger) : null;
705
+ context.args = trigger instanceof RegExp ? text?.match(trigger) : null;
709
706
  // TODO: remove
710
707
  //@ts-expect-error
711
708
  return handler(context);
package/dist/updates.js CHANGED
@@ -4,7 +4,6 @@ exports.Updates = void 0;
4
4
  const promises_1 = require("node:timers/promises");
5
5
  const contexts_1 = require("@gramio/contexts");
6
6
  const composer_1 = require("./composer");
7
- const errors_1 = require("./errors");
8
7
  class Updates {
9
8
  bot;
10
9
  isStarted = false;
@@ -65,20 +64,20 @@ class Updates {
65
64
  }
66
65
  async startFetchLoop(params = {}) {
67
66
  while (this.isStarted) {
68
- const updates = await this.bot.api.getUpdates({
69
- ...params,
70
- offset: this.offset,
71
- suppress: true,
72
- });
73
- if (updates instanceof errors_1.TelegramError || typeof updates === "undefined") {
74
- await promises_1.scheduler.wait(this.bot.options.api.retryGetUpdatesWait);
75
- }
76
- else {
67
+ try {
68
+ const updates = await this.bot.api.getUpdates({
69
+ ...params,
70
+ offset: this.offset,
71
+ });
77
72
  for await (const update of updates) {
78
73
  //TODO: update errors
79
74
  await this.handleUpdate(update).catch(console.error);
80
75
  }
81
76
  }
77
+ catch (error) {
78
+ console.error("Error received when fetching updates", error);
79
+ await promises_1.scheduler.wait(this.bot.options.api.retryGetUpdatesWait);
80
+ }
82
81
  }
83
82
  }
84
83
  stopPolling() {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gramio",
3
3
  "type": "commonjs",
4
- "version": "0.0.49",
4
+ "version": "0.0.50",
5
5
  "description": "Powerful, extensible and really type-safe Telegram Bot API framework",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
@@ -27,11 +27,11 @@
27
27
  "author": "kravets",
28
28
  "license": "MIT",
29
29
  "devDependencies": {
30
- "@biomejs/biome": "1.8.3",
31
- "@types/bun": "^1.1.8",
30
+ "@biomejs/biome": "1.9.1",
31
+ "@types/bun": "^1.1.9",
32
32
  "@types/debug": "^4.1.12",
33
- "pkgroll": "^2.4.2",
34
- "typescript": "^5.5.4"
33
+ "pkgroll": "^2.5.0",
34
+ "typescript": "^5.6.2"
35
35
  },
36
36
  "dependencies": {
37
37
  "@gramio/callback-data": "^0.0.3",
@@ -39,7 +39,7 @@
39
39
  "@gramio/files": "^0.0.12",
40
40
  "@gramio/format": "^0.1.3",
41
41
  "@gramio/keyboards": "^0.3.3",
42
- "@gramio/types": "^7.10.0",
42
+ "@gramio/types": "^7.10.1",
43
43
  "debug": "^4.3.7",
44
44
  "inspectable": "^3.0.2",
45
45
  "middleware-io": "^2.8.1"