gramio 0.0.48 → 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Kravets
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  <div align="center">
4
4
 
5
- [![Bot API](https://img.shields.io/badge/Bot%20API-7.9-blue?logo=telegram&style=flat&labelColor=000&color=3b82f6)](https://core.telegram.org/bots/api)
5
+ [![Bot API](https://img.shields.io/badge/Bot%20API-7.10-blue?logo=telegram&style=flat&labelColor=000&color=3b82f6)](https://core.telegram.org/bots/api)
6
6
  [![npm](https://img.shields.io/npm/v/gramio?logo=npm&style=flat&labelColor=000&color=3b82f6)](https://www.npmjs.org/package/@gramio/core)
7
7
  [![JSR](https://jsr.io/badges/@gramio/core)](https://jsr.io/@gramio/core)
8
8
  [![JSR Score](https://jsr.io/badges/@gramio/core/score)](https://jsr.io/@gramio/core)
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);
@@ -750,7 +747,15 @@ let Bot = (() => {
750
747
  */
751
748
  async init() {
752
749
  await Promise.all(this.lazyloadPlugins.map(async (plugin) => this.extend(await plugin)));
753
- this.info = await this.api.getMe();
750
+ const info = await this.api.getMe({
751
+ suppress: true,
752
+ });
753
+ if (info instanceof errors_1.TelegramError) {
754
+ if (info.code === 404)
755
+ info.message = "The bot token is incorrect. Check it in BotFather.";
756
+ throw info;
757
+ }
758
+ this.info = info;
754
759
  }
755
760
  /**
756
761
  * Start receive updates via long-polling or webhook
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.48",
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",
@@ -25,22 +25,22 @@
25
25
  "try-deno": "deno publish --unstable-sloppy-imports --dry-run --allow-slow-types --allow-dirty"
26
26
  },
27
27
  "author": "kravets",
28
- "license": "ISC",
28
+ "license": "MIT",
29
29
  "devDependencies": {
30
- "@biomejs/biome": "1.8.3",
31
- "@types/bun": "^1.1.6",
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",
38
- "@gramio/contexts": "^0.0.22",
38
+ "@gramio/contexts": "^0.0.23",
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.9.0",
43
- "debug": "^4.3.6",
42
+ "@gramio/types": "^7.10.1",
43
+ "debug": "^4.3.7",
44
44
  "inspectable": "^3.0.2",
45
45
  "middleware-io": "^2.8.1"
46
46
  },