grammy 1.16.1 → 1.16.2

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
@@ -68,7 +68,7 @@ Congrats! You just wrote a Telegram bot :)
68
68
 
69
69
  ## Going Further
70
70
 
71
- grammY has an excellent [documentation](https://grammy.dev), and an [API Reference](https://doc.deno.land/https://deno.land/x/grammy/mod.ts). It even integrates with your code editor, e.g. [VSCode](https://code.visualstudio.com/). You can hover over any element of grammY to get a detailed description of what that thing does or means.
71
+ grammY has an excellent [documentation](https://grammy.dev), and an [API Reference](https://doc.deno.land/https://deno.land/x/grammy/mod.ts). It even integrates with your code editor, e.g. [VS Code](https://code.visualstudio.com/). You can hover over any element of grammY to get a detailed description of what that thing does or means.
72
72
 
73
73
  If you are still stuck, just join the [Telegram chat](https://t.me/grammyjs) and ask for help. People are nice there and we appreciate your question, no matter what it is :)
74
74
 
@@ -161,7 +161,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
161
161
  </tr>
162
162
  <tr>
163
163
  <td align="center" valign="top" width="14.28%"><a href="https://lungers.com/"><img src="https://avatars.githubusercontent.com/u/32808683?v=4?s=100" width="100px;" alt="Andrew Lane"/><br /><sub><b>Andrew Lane</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/issues?q=author%3AAndrewLaneX" title="Bug reports">🐛</a> <a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3AAndrewLaneX" title="Reviewed Pull Requests">👀</a></td>
164
- <td align="center" valign="top" width="14.28%"><a href="https://github.com/code-withAshish"><img src="https://avatars.githubusercontent.com/u/73625149?v=4?s=100" width="100px;" alt="code-withAshish"/><br /><sub><b>code-withAshish</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=code-withAshish" title="Documentation">📖</a> <a href="#question-code-withAshish" title="Answering Questions">💬</a></td>
164
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/code-withAshish"><img src="https://avatars.githubusercontent.com/u/73625149?v=4?s=100" width="100px;" alt="code-withAshish"/><br /><sub><b>code-withAshish</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=code-withAshish" title="Documentation">📖</a> <a href="#question-code-withAshish" title="Answering Questions">💬</a> <a href="https://github.com/grammyjs/grammY/issues?q=author%3Acode-withAshish" title="Bug reports">🐛</a> <a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3Acode-withAshish" title="Reviewed Pull Requests">👀</a></td>
165
165
  <td align="center" valign="top" width="14.28%"><a href="https://beta.ku-di.com/waptik"><img src="https://avatars.githubusercontent.com/u/1687551?v=4?s=100" width="100px;" alt="Stephane Mensah"/><br /><sub><b>Stephane Mensah</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/issues?q=author%3Awaptik" title="Bug reports">🐛</a> <a href="#plugin-waptik" title="Plugin/utility libraries">🔌</a></td>
166
166
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/Asaku01"><img src="https://avatars.githubusercontent.com/u/29716396?v=4?s=100" width="100px;" alt="Asaku01"/><br /><sub><b>Asaku01</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=Asaku01" title="Documentation">📖</a></td>
167
167
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/ppsimn"><img src="https://avatars.githubusercontent.com/u/88509883?v=4?s=100" width="100px;" alt="ppsimn"/><br /><sub><b>ppsimn</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/issues?q=author%3Appsimn" title="Bug reports">🐛</a></td>
@@ -270,6 +270,10 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
270
270
  <tr>
271
271
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/AbbassAlmusawi"><img src="https://avatars.githubusercontent.com/u/73327881?v=4?s=100" width="100px;" alt="Abbass Al-Musawi"/><br /><sub><b>Abbass Al-Musawi</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=AbbassAlmusawi" title="Documentation">📖</a></td>
272
272
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/inji-gg"><img src="https://avatars.githubusercontent.com/u/5071242?v=4?s=100" width="100px;" alt="ArunR"/><br /><sub><b>ArunR</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/issues?q=author%3Ainji-gg" title="Bug reports">🐛</a> <a href="https://github.com/grammyjs/grammY/commits?author=inji-gg" title="Code">💻</a></td>
273
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/ndatg"><img src="https://avatars.githubusercontent.com/u/108090198?v=4?s=100" width="100px;" alt="NDA"/><br /><sub><b>NDA</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/issues?q=author%3Andatg" title="Bug reports">🐛</a> <a href="#ideas-ndatg" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/grammyjs/grammY/commits?author=ndatg" title="Code">💻</a></td>
274
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/MatyiFKBT"><img src="https://avatars.githubusercontent.com/u/6183867?v=4?s=100" width="100px;" alt="MatyiFKBT"/><br /><sub><b>MatyiFKBT</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=MatyiFKBT" title="Documentation">📖</a></td>
275
+ <td align="center" valign="top" width="14.28%"><a href="https://chrisandrew.cl"><img src="https://avatars.githubusercontent.com/u/368831?v=4?s=100" width="100px;" alt="Chris Andrew C. L."/><br /><sub><b>Chris Andrew C. L.</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/issues?q=author%3Achrisandrewcl" title="Bug reports">🐛</a> <a href="https://github.com/grammyjs/grammY/commits?author=chrisandrewcl" title="Code">💻</a></td>
276
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/kiyasov"><img src="https://avatars.githubusercontent.com/u/16527461?v=4?s=100" width="100px;" alt="Islam Kiiasov"/><br /><sub><b>Islam Kiiasov</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=kiyasov" title="Code">💻</a></td>
273
277
  </tr>
274
278
  </tbody>
275
279
  </table>
package/out/composer.d.ts CHANGED
@@ -155,7 +155,7 @@ export declare class Composer<C extends Context> implements MiddlewareObj<C> {
155
155
  * bot.on('::url', ctx => { ... })
156
156
  * ```
157
157
  *
158
- * You can use autocomplete in VSCode to see all available filter queries.
158
+ * You can use autocomplete in VS Code to see all available filter queries.
159
159
  * Check out the
160
160
  * [documentation](https://grammy.dev/guide/filter-queries.html) on the
161
161
  * website to learn more about filter queries in grammY.
@@ -226,7 +226,7 @@ export declare class Composer<C extends Context> implements MiddlewareObj<C> {
226
226
  * via `ctx.match`.
227
227
  *
228
228
  * > **Did you know?** You can use deep linking
229
- * > (https://core.telegram.org/bots#deep-linking) to let users start your
229
+ * > (https://core.telegram.org/bots/features#deep-linking) to let users start your
230
230
  * > bot with a custom payload. As an example, send someone the link
231
231
  * > https://t.me/name-of-your-bot?start=custom-payload and register a start
232
232
  * > command handler on your bot with grammY. As soon as the user starts
package/out/composer.js CHANGED
@@ -156,7 +156,7 @@ class Composer {
156
156
  * bot.on('::url', ctx => { ... })
157
157
  * ```
158
158
  *
159
- * You can use autocomplete in VSCode to see all available filter queries.
159
+ * You can use autocomplete in VS Code to see all available filter queries.
160
160
  * Check out the
161
161
  * [documentation](https://grammy.dev/guide/filter-queries.html) on the
162
162
  * website to learn more about filter queries in grammY.
@@ -231,7 +231,7 @@ class Composer {
231
231
  * via `ctx.match`.
232
232
  *
233
233
  * > **Did you know?** You can use deep linking
234
- * > (https://core.telegram.org/bots#deep-linking) to let users start your
234
+ * > (https://core.telegram.org/bots/features#deep-linking) to let users start your
235
235
  * > bot with a custom payload. As an example, send someone the link
236
236
  * > https://t.me/name-of-your-bot?start=custom-payload and register a start
237
237
  * > command handler on your bot with grammY. As soon as the user starts
@@ -55,6 +55,7 @@ export declare const adapters: {
55
55
  http: FrameworkAdapter;
56
56
  https: FrameworkAdapter;
57
57
  "aws-lambda": FrameworkAdapter;
58
+ "aws-lambda-async": FrameworkAdapter;
58
59
  azure: FrameworkAdapter;
59
60
  "next-js": FrameworkAdapter;
60
61
  sveltekit: FrameworkAdapter;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.adapters = void 0;
4
4
  const SECRET_HEADER = "X-Telegram-Bot-Api-Secret-Token";
5
+ const SECRET_HEADER_LOWERCASE = SECRET_HEADER.toLowerCase();
5
6
  const WRONG_TOKEN_ERROR = "secret token is wrong";
6
7
  const ok = () => new Response(null, { status: 200 });
7
8
  const okJson = (json) => new Response(json, {
@@ -43,7 +44,7 @@ const koa = (ctx) => ({
43
44
  /** fastify web framework */
44
45
  const fastify = (req, reply) => ({
45
46
  update: Promise.resolve(req.body),
46
- header: req.headers[SECRET_HEADER.toLowerCase()],
47
+ header: req.headers[SECRET_HEADER_LOWERCASE],
47
48
  end: () => reply.status(200).send(),
48
49
  respond: (json) => reply.send(json),
49
50
  unauthorized: () => reply.code(401).send(WRONG_TOKEN_ERROR),
@@ -95,7 +96,7 @@ const oak = (ctx) => ({
95
96
  });
96
97
  /** Node.js native 'http' and 'https' modules */
97
98
  const http = (req, res) => {
98
- const secretHeaderFromRequest = req.headers[SECRET_HEADER.toLowerCase()];
99
+ const secretHeaderFromRequest = req.headers[SECRET_HEADER_LOWERCASE];
99
100
  return {
100
101
  update: new Promise((resolve, reject) => {
101
102
  const chunks = [];
@@ -120,11 +121,33 @@ const http = (req, res) => {
120
121
  /** AWS lambda serverless functions */
121
122
  const awsLambda = (event, _context, callback) => ({
122
123
  update: JSON.parse(event.body),
123
- header: event.headers[SECRET_HEADER],
124
+ header: event.headers[SECRET_HEADER_LOWERCASE],
124
125
  end: () => callback(null, { statusCode: 200 }),
125
- respond: (json) => callback(null, { statusCode: 200, body: json }),
126
+ respond: (json) => callback(null, {
127
+ statusCode: 200,
128
+ headers: { "Content-Type": "application/json" },
129
+ body: json,
130
+ }),
126
131
  unauthorized: () => callback(null, { statusCode: 401 }),
127
132
  });
133
+ /** AWS lambda async/await serverless functions */
134
+ const awsLambdaAsync = (event, _context) => {
135
+ let resolveResponse;
136
+ return {
137
+ update: JSON.parse(event.body),
138
+ header: event.headers[SECRET_HEADER_LOWERCASE],
139
+ end: () => resolveResponse({ statusCode: 200 }),
140
+ respond: (json) => resolveResponse({
141
+ statusCode: 200,
142
+ headers: { "Content-Type": "application/json" },
143
+ body: json,
144
+ }),
145
+ unauthorized: () => resolveResponse({ statusCode: 401 }),
146
+ handlerReturn: new Promise((resolve) => {
147
+ resolveResponse = resolve;
148
+ }),
149
+ };
150
+ };
128
151
  /** Azure Functions */
129
152
  const azure = (context, req) => ({
130
153
  update: Promise.resolve(req.body),
@@ -144,7 +167,7 @@ const azure = (context, req) => ({
144
167
  /** Next.js Serverless Functions */
145
168
  const nextJs = (req, res) => ({
146
169
  update: Promise.resolve(req.body),
147
- header: req.headers[SECRET_HEADER.toLowerCase()],
170
+ header: req.headers[SECRET_HEADER_LOWERCASE],
148
171
  end: () => res.end(),
149
172
  respond: (json) => res.status(200).json(json),
150
173
  unauthorized: () => res.status(401).send(WRONG_TOKEN_ERROR),
@@ -254,6 +277,7 @@ exports.adapters = {
254
277
  http,
255
278
  https: http,
256
279
  "aws-lambda": awsLambda,
280
+ "aws-lambda-async": awsLambdaAsync,
257
281
  azure,
258
282
  "next-js": nextJs,
259
283
  sveltekit,
@@ -1,7 +1,7 @@
1
1
  import { type InlineKeyboardButton, type KeyboardButton, type KeyboardButtonRequestChat, type KeyboardButtonRequestUser, type LoginUrl, type SwitchInlineQueryChosenChat } from "../types.js";
2
2
  /**
3
3
  * Use this class to simplify building a custom keyboard (something like this:
4
- * https://core.telegram.org/bots#keyboards).
4
+ * https://core.telegram.org/bots/features#keyboards).
5
5
  *
6
6
  * ```ts
7
7
  * // Build a custom keyboard:
@@ -206,7 +206,7 @@ export declare class Keyboard {
206
206
  }
207
207
  /**
208
208
  * Use this class to simplify building an inline keyboard (something like this:
209
- * https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating).
209
+ * https://core.telegram.org/bots/features#inline-keyboards).
210
210
  *
211
211
  * ```ts
212
212
  * // Build an inline keyboard:
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InlineKeyboard = exports.Keyboard = void 0;
4
4
  /**
5
5
  * Use this class to simplify building a custom keyboard (something like this:
6
- * https://core.telegram.org/bots#keyboards).
6
+ * https://core.telegram.org/bots/features#keyboards).
7
7
  *
8
8
  * ```ts
9
9
  * // Build a custom keyboard:
@@ -232,7 +232,7 @@ class Keyboard {
232
232
  exports.Keyboard = Keyboard;
233
233
  /**
234
234
  * Use this class to simplify building an inline keyboard (something like this:
235
- * https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating).
235
+ * https://core.telegram.org/bots/features#inline-keyboards).
236
236
  *
237
237
  * ```ts
238
238
  * // Build an inline keyboard:
package/out/core/api.d.ts CHANGED
@@ -844,7 +844,7 @@ export declare class Api<R extends RawApi = RawApi> {
844
844
  */
845
845
  getMyName(other?: Other<R, "getMyName">, signal?: AbortSignal): Promise<import("@grammyjs/types/settings.js").BotName>;
846
846
  /**
847
- * Use this method to change the list of the bot's commands. See https://core.telegram.org/bots#commands for more details about bot commands. Returns True on success.
847
+ * Use this method to change the list of the bot's commands. See https://core.telegram.org/bots/features#commands for more details about bot commands. Returns True on success.
848
848
  *
849
849
  * @param commands A list of bot commands to be set as the list of the bot's commands. At most 100 commands can be specified.
850
850
  * @param other Optional remaining parameters, confer the official reference below
package/out/core/api.js CHANGED
@@ -955,7 +955,7 @@ class Api {
955
955
  return this.raw.getMyName(other !== null && other !== void 0 ? other : {}, signal);
956
956
  }
957
957
  /**
958
- * Use this method to change the list of the bot's commands. See https://core.telegram.org/bots#commands for more details about bot commands. Returns True on success.
958
+ * Use this method to change the list of the bot's commands. See https://core.telegram.org/bots/features#commands for more details about bot commands. Returns True on success.
959
959
  *
960
960
  * @param commands A list of bot commands to be set as the list of the bot's commands. At most 100 commands can be specified.
961
961
  * @param other Optional remaining parameters, confer the official reference below
@@ -13,12 +13,27 @@ Object.defineProperty(exports, "debug", { enumerable: true, get: function () { r
13
13
  const itrToStream = (itr) => stream_1.Readable.from(itr, { objectMode: false });
14
14
  exports.itrToStream = itrToStream;
15
15
  // === Base configuration for `fetch` calls
16
+ const httpAgents = new Map();
17
+ const httpsAgents = new Map();
18
+ function getCached(map, key, otherwise) {
19
+ let value = map.get(key);
20
+ if (value === undefined) {
21
+ value = otherwise();
22
+ map.set(key, value);
23
+ }
24
+ return value;
25
+ }
16
26
  function baseFetchConfig(apiRoot) {
17
27
  if (apiRoot.startsWith("https:")) {
18
- return { compress: true, agent: new https_1.Agent({ keepAlive: true }) };
28
+ return {
29
+ compress: true,
30
+ agent: getCached(httpsAgents, apiRoot, () => new https_1.Agent({ keepAlive: true })),
31
+ };
19
32
  }
20
33
  else if (apiRoot.startsWith("http:")) {
21
- return { agent: new http_1.Agent({ keepAlive: true }) };
34
+ return {
35
+ agent: getCached(httpAgents, apiRoot, () => new http_1.Agent({ keepAlive: true })),
36
+ };
22
37
  }
23
38
  else
24
39
  return {};
package/out/web.mjs CHANGED
@@ -4825,6 +4825,7 @@ export { lazySession as lazySession };
4825
4825
  export { enhanceStorage as enhanceStorage };
4826
4826
  export { MemorySessionStorage as MemorySessionStorage };
4827
4827
  const SECRET_HEADER = "X-Telegram-Bot-Api-Secret-Token";
4828
+ const SECRET_HEADER_LOWERCASE = SECRET_HEADER.toLowerCase();
4828
4829
  const WRONG_TOKEN_ERROR = "secret token is wrong";
4829
4830
  const ok = ()=>new Response(null, {
4830
4831
  status: 200
@@ -4867,7 +4868,7 @@ const koa = (ctx)=>({
4867
4868
  });
4868
4869
  const fastify = (req, reply)=>({
4869
4870
  update: Promise.resolve(req.body),
4870
- header: req.headers[SECRET_HEADER.toLowerCase()],
4871
+ header: req.headers[SECRET_HEADER_LOWERCASE],
4871
4872
  end: ()=>reply.status(200).send(),
4872
4873
  respond: (json)=>reply.send(json),
4873
4874
  unauthorized: ()=>reply.code(401).send(WRONG_TOKEN_ERROR)
@@ -4915,7 +4916,7 @@ const oak = (ctx)=>({
4915
4916
  }
4916
4917
  });
4917
4918
  const http = (req, res)=>{
4918
- const secretHeaderFromRequest = req.headers[SECRET_HEADER.toLowerCase()];
4919
+ const secretHeaderFromRequest = req.headers[SECRET_HEADER_LOWERCASE];
4919
4920
  return {
4920
4921
  update: new Promise((resolve, reject)=>{
4921
4922
  const chunks = [];
@@ -4934,18 +4935,44 @@ const http = (req, res)=>{
4934
4935
  };
4935
4936
  const awsLambda = (event, _context, callback)=>({
4936
4937
  update: JSON.parse(event.body),
4937
- header: event.headers[SECRET_HEADER],
4938
+ header: event.headers[SECRET_HEADER_LOWERCASE],
4938
4939
  end: ()=>callback(null, {
4939
4940
  statusCode: 200
4940
4941
  }),
4941
4942
  respond: (json)=>callback(null, {
4942
4943
  statusCode: 200,
4944
+ headers: {
4945
+ "Content-Type": "application/json"
4946
+ },
4943
4947
  body: json
4944
4948
  }),
4945
4949
  unauthorized: ()=>callback(null, {
4946
4950
  statusCode: 401
4947
4951
  })
4948
4952
  });
4953
+ const awsLambdaAsync = (event, _context)=>{
4954
+ let resolveResponse;
4955
+ return {
4956
+ update: JSON.parse(event.body),
4957
+ header: event.headers[SECRET_HEADER_LOWERCASE],
4958
+ end: ()=>resolveResponse({
4959
+ statusCode: 200
4960
+ }),
4961
+ respond: (json)=>resolveResponse({
4962
+ statusCode: 200,
4963
+ headers: {
4964
+ "Content-Type": "application/json"
4965
+ },
4966
+ body: json
4967
+ }),
4968
+ unauthorized: ()=>resolveResponse({
4969
+ statusCode: 401
4970
+ }),
4971
+ handlerReturn: new Promise((resolve)=>{
4972
+ resolveResponse = resolve;
4973
+ })
4974
+ };
4975
+ };
4949
4976
  const azure = (context, req)=>({
4950
4977
  update: Promise.resolve(req.body),
4951
4978
  header: context.res.headers[SECRET_HEADER],
@@ -4963,7 +4990,7 @@ const azure = (context, req)=>({
4963
4990
  });
4964
4991
  const nextJs = (req, res)=>({
4965
4992
  update: Promise.resolve(req.body),
4966
- header: req.headers[SECRET_HEADER.toLowerCase()],
4993
+ header: req.headers[SECRET_HEADER_LOWERCASE],
4967
4994
  end: ()=>res.end(),
4968
4995
  respond: (json)=>res.status(200).json(json),
4969
4996
  unauthorized: ()=>res.status(401).send(WRONG_TOKEN_ERROR)
@@ -5064,6 +5091,7 @@ const adapters = {
5064
5091
  http,
5065
5092
  https: http,
5066
5093
  "aws-lambda": awsLambda,
5094
+ "aws-lambda-async": awsLambdaAsync,
5067
5095
  azure,
5068
5096
  "next-js": nextJs,
5069
5097
  sveltekit,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "grammy",
3
3
  "description": "The Telegram Bot Framework.",
4
- "version": "1.16.1",
4
+ "version": "1.16.2",
5
5
  "author": "KnorpelSenf",
6
6
  "license": "MIT",
7
7
  "engines": {