gramio 0.0.36 → 0.0.37

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.d.ts CHANGED
@@ -44,8 +44,12 @@ export declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends D
44
44
  /** This instance handle updates */
45
45
  updates: Updates;
46
46
  private hooks;
47
- /** Create new Bot instance */
48
- constructor(token: string, options?: Omit<BotOptions, "token">);
47
+ constructor(token: string, options?: Omit<BotOptions, "token" | "api"> & {
48
+ api?: Partial<BotOptions["api"]>;
49
+ });
50
+ constructor(options: Omit<BotOptions, "api"> & {
51
+ api?: Partial<BotOptions["api"]>;
52
+ });
49
53
  private runHooks;
50
54
  private runImmutableHooks;
51
55
  private _callApi;
package/dist/bot.js CHANGED
@@ -81,7 +81,7 @@ let Bot = (() => {
81
81
  /** @internal. Remap generic */
82
82
  __Derives;
83
83
  /** Options provided to instance */
84
- options = {};
84
+ options;
85
85
  /** Bot data (filled in when calling bot.init/bot.start) */
86
86
  info;
87
87
  /**
@@ -125,11 +125,17 @@ let Bot = (() => {
125
125
  onStart: [],
126
126
  onStop: [],
127
127
  };
128
- /** Create new Bot instance */
129
- constructor(token, options) {
128
+ constructor(tokenOrOptions, options) {
129
+ const token = typeof tokenOrOptions === "string"
130
+ ? tokenOrOptions
131
+ : tokenOrOptions?.token;
130
132
  if (!token || typeof token !== "string")
131
133
  throw new Error(`Token is ${typeof token} but it should be a string!`);
132
- this.options = { ...options, token };
134
+ this.options = {
135
+ ...(typeof tokenOrOptions === "object" ? tokenOrOptions : options),
136
+ token,
137
+ api: { ...options?.api, baseURL: "https://api.telegram.org/bot" },
138
+ };
133
139
  if (!(options?.plugins &&
134
140
  "format" in options.plugins &&
135
141
  !options.plugins.format))
@@ -158,7 +164,7 @@ let Bot = (() => {
158
164
  }
159
165
  }
160
166
  async _callApi(method, params = {}) {
161
- const url = `https://api.telegram.org/bot${this.options.token}/${method}`;
167
+ const url = `${this.options.api.baseURL}${this.options.token}/${method}`;
162
168
  const reqOptions = {
163
169
  method: "POST",
164
170
  };
@@ -214,7 +220,7 @@ let Bot = (() => {
214
220
  }
215
221
  const fileId = typeof attachment === "string" ? attachment : getFileId(attachment);
216
222
  const file = await this.api.getFile({ file_id: fileId });
217
- const url = `https://api.telegram.org/file/bot${this.options.token}/${file.file_path}`;
223
+ const url = `${this.options.api.baseURL.replace("/bot", "/file/bot")}${this.options.token}/${file.file_path}`;
218
224
  const res = await (0, undici_1.request)(url);
219
225
  const buffer = await res.body.arrayBuffer();
220
226
  if (path) {
package/dist/types.d.ts CHANGED
@@ -6,10 +6,26 @@ import type { TelegramError } from "./errors";
6
6
  import type { Plugin } from "./plugin";
7
7
  /** Bot options that you can provide to {@link Bot} constructor */
8
8
  export interface BotOptions {
9
- token?: string;
9
+ /** Bot token */
10
+ token: string;
11
+ /** List of plugins enabled by default */
10
12
  plugins?: {
13
+ /** Pass `false` to disable plugin. @default true */
11
14
  format?: boolean;
12
15
  };
16
+ /** Options to configure how to send requests to the Telegram Bot API */
17
+ api: {
18
+ /** URL which will be used to send requests to. @default "https://api.telegram.org/bot" */
19
+ baseURL: string;
20
+ /**
21
+ * Should we send requests to `test` data center?
22
+ * The test environment is completely separate from the main environment, so you will need to create a new user account and a new bot with `@BotFather`.
23
+ *
24
+ * [Documentation](https://core.telegram.org/bots/webapps#using-bots-in-the-test-environment)
25
+ * @default false
26
+ * */
27
+ useTest?: boolean;
28
+ };
13
29
  }
14
30
  /**
15
31
  * Handler is a function with context and next function arguments
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gramio",
3
- "version": "0.0.36",
3
+ "version": "0.0.37",
4
4
  "description": "Powerful Telegram Bot API framework",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -34,8 +34,8 @@
34
34
  "@gramio/callback-data": "^0.0.3",
35
35
  "@gramio/contexts": "^0.0.15",
36
36
  "@gramio/files": "^0.0.8",
37
- "@gramio/format": "^0.1.1",
38
- "@gramio/keyboards": "^0.3.1",
37
+ "@gramio/format": "^0.1.2",
38
+ "@gramio/keyboards": "^0.3.2",
39
39
  "@gramio/types": "^7.3.4",
40
40
  "inspectable": "^3.0.1",
41
41
  "middleware-io": "^2.8.1",