grammy 1.19.2 → 1.19.3

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/README.md CHANGED
@@ -280,6 +280,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
280
280
  <td align="center" valign="top" width="11.11%"><a href="https://github.com/shaunnope"><img src="https://avatars.githubusercontent.com/u/19631195?v=4?s=100" width="100px;" alt="Sean Yap"/><br /><sub><b>Sean Yap</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/issues?q=author%3Ashaunnope" title="Bug reports">🐛</a> <a href="https://github.com/grammyjs/grammY/commits?author=shaunnope" title="Code">💻</a></td>
281
281
  <td align="center" valign="top" width="11.11%"><a href="https://sergeysolovev.com"><img src="https://avatars.githubusercontent.com/u/5831301?v=4?s=100" width="100px;" alt="Sergey Solovev"/><br /><sub><b>Sergey Solovev</b></sub></a><br /><a href="#ideas-sergeysolovev" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3Asergeysolovev" title="Reviewed Pull Requests">👀</a></td>
282
282
  <td align="center" valign="top" width="11.11%"><a href="https://github.com/HeySreelal"><img src="https://avatars.githubusercontent.com/u/94184909?v=4?s=100" width="100px;" alt="Sree (Taylor's Version)"/><br /><sub><b>Sree (Taylor's Version)</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/issues?q=author%3AHeySreelal" title="Bug reports">🐛</a> <a href="https://github.com/grammyjs/grammY/commits?author=HeySreelal" title="Code">💻</a></td>
283
+ <td align="center" valign="top" width="11.11%"><a href="http://linkedin.com/in/thecoorum"><img src="https://avatars.githubusercontent.com/u/32096016?v=4?s=100" width="100px;" alt="Yaroslav Vovchenko"/><br /><sub><b>Yaroslav Vovchenko</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/issues?q=author%3Athecoorum" title="Bug reports">🐛</a></td>
283
284
  </tr>
284
285
  </tbody>
285
286
  </table>
@@ -64,6 +64,19 @@ export interface ApiClientOptions {
64
64
  * https://api.telegram.org
65
65
  */
66
66
  apiRoot?: string;
67
+ /**
68
+ * Specifies whether to use the [test
69
+ * environment](https://core.telegram.org/bots/webapps#using-bots-in-the-test-environment).
70
+ * Can be either `"prod"` (default) or `"test"`.
71
+ *
72
+ * The testing infrastructure is separate from the regular production
73
+ * infrastructure. No chats, accounts, or other data is shared between them.
74
+ * If you set this option to `"test"`, you will need to make your Telegram
75
+ * client connect to the testing data centers of Telegram, register your
76
+ * phone number again, open a new chat with @BotFather, and create a
77
+ * separate bot.
78
+ */
79
+ environment?: "prod" | "test";
67
80
  /**
68
81
  * URL builder function for API calls. Can be used to modify which API
69
82
  * server should be called.
@@ -71,9 +84,10 @@ export interface ApiClientOptions {
71
84
  * @param root The URL that was passed in `apiRoot`, or its default value
72
85
  * @param token The bot's token that was passed when creating the bot
73
86
  * @param method The API method to be called, e.g. `getMe`
87
+ * @param env The value that was passed in `environment`, or its default value
74
88
  * @returns The URL that will be fetched during the API call
75
89
  */
76
- buildUrl?: (root: string, token: string, method: string) => string | URL;
90
+ buildUrl?: (root: string, token: string, method: string, env: "prod" | "test") => string | URL;
77
91
  /**
78
92
  * Maximum number of seconds that a request to the Bot API server may take.
79
93
  * If a request has not completed before this time has elapsed, grammY
@@ -11,7 +11,7 @@ function concatTransformer(prev, trans) {
11
11
  }
12
12
  class ApiClient {
13
13
  constructor(token, options = {}, webhookReplyEnvelope = {}) {
14
- var _a, _b, _c, _d, _e;
14
+ var _a, _b, _c, _d, _e, _f;
15
15
  this.token = token;
16
16
  this.webhookReplyEnvelope = webhookReplyEnvelope;
17
17
  this.hasUsedWebhookReply = false;
@@ -39,7 +39,7 @@ class ApiClient {
39
39
  const timeout = createTimeout(controller, opts.timeoutSeconds, method);
40
40
  const streamErr = createStreamError(controller);
41
41
  // Build request URL and config
42
- const url = opts.buildUrl(opts.apiRoot, this.token, method);
42
+ const url = opts.buildUrl(opts.apiRoot, this.token, method, opts.environment);
43
43
  const config = formDataRequired
44
44
  ? (0, payload_js_1.createFormDataPayload)(payload, (err) => streamErr.catch(err))
45
45
  : (0, payload_js_1.createJsonPayload)(payload);
@@ -60,16 +60,18 @@ class ApiClient {
60
60
  }
61
61
  };
62
62
  const apiRoot = (_a = options.apiRoot) !== null && _a !== void 0 ? _a : "https://api.telegram.org";
63
+ const environment = (_b = options.environment) !== null && _b !== void 0 ? _b : "prod";
63
64
  this.options = {
64
65
  apiRoot,
65
- buildUrl: (_b = options.buildUrl) !== null && _b !== void 0 ? _b : ((root, token, method) => `${root}/bot${token}/${method}`),
66
- timeoutSeconds: (_c = options.timeoutSeconds) !== null && _c !== void 0 ? _c : 500,
66
+ environment,
67
+ buildUrl: (_c = options.buildUrl) !== null && _c !== void 0 ? _c : defaultBuildUrl,
68
+ timeoutSeconds: (_d = options.timeoutSeconds) !== null && _d !== void 0 ? _d : 500,
67
69
  baseFetchConfig: {
68
70
  ...(0, platform_node_js_1.baseFetchConfig)(apiRoot),
69
71
  ...options.baseFetchConfig,
70
72
  },
71
- canUseWebhookReply: (_d = options.canUseWebhookReply) !== null && _d !== void 0 ? _d : (() => false),
72
- sensitiveLogs: (_e = options.sensitiveLogs) !== null && _e !== void 0 ? _e : false,
73
+ canUseWebhookReply: (_e = options.canUseWebhookReply) !== null && _e !== void 0 ? _e : (() => false),
74
+ sensitiveLogs: (_f = options.sensitiveLogs) !== null && _f !== void 0 ? _f : false,
73
75
  };
74
76
  if (this.options.apiRoot.endsWith("/")) {
75
77
  throw new Error(`Remove the trailing '/' from the 'apiRoot' option (use '${this.options.apiRoot.substring(0, this.options.apiRoot.length - 1)}' instead of '${this.options.apiRoot}')`);
@@ -124,6 +126,10 @@ function createRawApi(token, options, webhookReplyEnvelope) {
124
126
  return api;
125
127
  }
126
128
  exports.createRawApi = createRawApi;
129
+ const defaultBuildUrl = (root, token, method, env) => {
130
+ const prefix = env === "test" ? "test/" : "";
131
+ return `${root}/bot${token}/${prefix}${method}`;
132
+ };
127
133
  const proxyMethods = {
128
134
  set() {
129
135
  return false;
@@ -4,8 +4,7 @@
4
4
  import { Agent as HttpAgent } from "http";
5
5
  import { Agent as HttpsAgent } from "https";
6
6
  import { Readable } from "stream";
7
- import { debug as d } from "debug";
8
- export { d as debug };
7
+ export { debug } from "debug";
9
8
  export declare const itrToStream: (itr: AsyncIterable<Uint8Array>) => Readable;
10
9
  export declare function baseFetchConfig(apiRoot: string): {
11
10
  compress: boolean;
@@ -6,7 +6,7 @@ const http_1 = require("http");
6
6
  const https_1 = require("https");
7
7
  const stream_1 = require("stream");
8
8
  // === Export debug
9
- const debug_1 = require("debug");
9
+ var debug_1 = require("debug");
10
10
  Object.defineProperty(exports, "debug", { enumerable: true, get: function () { return debug_1.debug; } });
11
11
  // === Export system-specific operations
12
12
  // Turn an AsyncIterable<Uint8Array> into a stream
package/out/web.mjs CHANGED
@@ -1919,7 +1919,7 @@ class ApiClient {
1919
1919
  const controller = createAbortControllerFromSignal(signal);
1920
1920
  const timeout = createTimeout(controller, opts.timeoutSeconds, method);
1921
1921
  const streamErr = createStreamError(controller);
1922
- const url = opts.buildUrl(opts.apiRoot, this.token, method);
1922
+ const url = opts.buildUrl(opts.apiRoot, this.token, method, opts.environment);
1923
1923
  const config = formDataRequired ? createFormDataPayload(payload, (err)=>streamErr.catch(err)) : createJsonPayload(payload);
1924
1924
  const sig = controller.signal;
1925
1925
  const options = {
@@ -1941,9 +1941,11 @@ class ApiClient {
1941
1941
  }
1942
1942
  };
1943
1943
  const apiRoot = options.apiRoot ?? "https://api.telegram.org";
1944
+ const environment = options.environment ?? "prod";
1944
1945
  this.options = {
1945
1946
  apiRoot,
1946
- buildUrl: options.buildUrl ?? ((root, token, method)=>`${root}/bot${token}/${method}`),
1947
+ environment,
1948
+ buildUrl: options.buildUrl ?? defaultBuildUrl,
1947
1949
  timeoutSeconds: options.timeoutSeconds ?? 500,
1948
1950
  baseFetchConfig: {
1949
1951
  ...baseFetchConfig(apiRoot),
@@ -1988,6 +1990,10 @@ function createRawApi(token, options, webhookReplyEnvelope) {
1988
1990
  };
1989
1991
  return api;
1990
1992
  }
1993
+ const defaultBuildUrl = (root, token, method, env)=>{
1994
+ const prefix = env === "test" ? "test/" : "";
1995
+ return `${root}/bot${token}/${prefix}${method}`;
1996
+ };
1991
1997
  const proxyMethods = {
1992
1998
  set () {
1993
1999
  return false;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "grammy",
3
3
  "description": "The Telegram Bot Framework.",
4
- "version": "1.19.2",
4
+ "version": "1.19.3",
5
5
  "author": "KnorpelSenf",
6
6
  "license": "MIT",
7
7
  "engines": {