grammy 1.8.0 → 1.8.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
@@ -10,7 +10,7 @@ _<h2 align="center"> [:mag: Documentation](https://grammy.dev) | [:page_with_cur
10
10
 
11
11
  <!-- deno-fmt-ignore-start -->
12
12
 
13
- [![Bot API](https://img.shields.io/badge/Bot%20API-5.7-blue?logo=telegram&style=flat-square)](https://core.telegram.org/bots/api)
13
+ [![Bot API](https://img.shields.io/badge/Bot%20API-6.0-blue?logo=telegram&style=flat-square)](https://core.telegram.org/bots/api)
14
14
  [![npm](https://img.shields.io/npm/v/grammy?logo=npm&style=flat-square)](https://www.npmjs.org/package/grammy) <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
15
15
  [![All Contributors](https://img.shields.io/badge/all_contributors-54-orange.svg?style=flat-square)](#contributors-)
16
16
  <!-- ALL-CONTRIBUTORS-BADGE:END -->
package/out/composer.d.ts CHANGED
@@ -553,10 +553,10 @@ export declare class Composer<C extends Context> implements MiddlewareObj<C> {
553
553
  */
554
554
  errorBoundary(errorHandler: (error: BotError<C>, next: NextFunction) => MaybePromise<unknown>, ...middleware: Array<Middleware<C>>): Composer<C>;
555
555
  }
556
- declare type HearsContext<C extends Context> = Filter<C & {
557
- match: string | RegExpMatchArray;
556
+ declare type HearsContext<C extends Context> = Filter<Omit<C, "match"> & {
557
+ match: Extract<C["match"], string | RegExpMatchArray>;
558
558
  }, ":text" | ":caption">;
559
- declare type CommandContext<C extends Context> = Filter<C & {
560
- match: string;
559
+ declare type CommandContext<C extends Context> = Filter<Omit<C, "match"> & {
560
+ match: Extract<C["match"], string>;
561
561
  }, ":entities:bot_command">;
562
562
  export {};
@@ -64,13 +64,15 @@ function session(options = {}) {
64
64
  Object.defineProperty(ctx, "session", {
65
65
  get() {
66
66
  if (key === undefined) {
67
- throw new Error("Cannot access session data because the session key was undefined!");
67
+ const msg = undef("access", getSessionKey);
68
+ throw new Error(msg);
68
69
  }
69
70
  return value;
70
71
  },
71
72
  set(v) {
72
73
  if (key === undefined) {
73
- throw new Error("Cannot assign session data because the session key was undefined!");
74
+ const msg = undef("assign", getSessionKey);
75
+ throw new Error(msg);
74
76
  }
75
77
  value = v;
76
78
  },
@@ -132,7 +134,8 @@ function lazySession(options = {}) {
132
134
  async function load() {
133
135
  var _a;
134
136
  if (key === undefined) {
135
- throw new Error("Cannot access lazy session data because the session key was undefined!");
137
+ const msg = undef("access", getSessionKey, { lazy: true });
138
+ throw new Error(msg);
136
139
  }
137
140
  let v = await storage.read(key);
138
141
  if (!fetching)
@@ -162,7 +165,8 @@ function lazySession(options = {}) {
162
165
  },
163
166
  set(v) {
164
167
  if (key === undefined) {
165
- throw new Error("Cannot assign lazy session data because the session key was undefined!");
168
+ const msg = undef("assign", getSessionKey, { lazy: true });
169
+ throw new Error(msg);
166
170
  }
167
171
  wrote = true;
168
172
  fetching = false;
@@ -184,10 +188,20 @@ function lazySession(options = {}) {
184
188
  };
185
189
  }
186
190
  exports.lazySession = lazySession;
191
+ /** Stores session data per chat by default */
187
192
  function defaultGetSessionKey(ctx) {
188
193
  var _a;
189
194
  return (_a = ctx.chat) === null || _a === void 0 ? void 0 : _a.id.toString();
190
195
  }
196
+ /** Returns a useful error message for when the session key is undefined */
197
+ function undef(op, getSessionKey, opts = {}) {
198
+ var _a;
199
+ const lazy = (_a = opts.lazy) !== null && _a !== void 0 ? _a : false;
200
+ const reason = getSessionKey === defaultGetSessionKey
201
+ ? "this update does not belong to a chat, so the session key is undefined"
202
+ : "the custom `getSessionKey` function returned undefined for this update";
203
+ return `Cannot ${op} ${lazy ? "lazy " : ""}session data because ${reason}!`;
204
+ }
191
205
  /**
192
206
  * The memory session storage is a built-in storage adapter that saves your
193
207
  * session data in RAM using a regular JavaScript `Map` object. If you use this
@@ -23,8 +23,7 @@ export interface WebhookReplyEnvelope {
23
23
  * Type of a function that can perform an API call. Used for Transformers.
24
24
  */
25
25
  export declare type ApiCallFn<R extends RawApi = RawApi> = <M extends Methods<R>>(method: M, payload: Payload<M, R>, signal?: AbortSignal) => Promise<ApiResponse<ApiCallResult<M, R>>>;
26
- declare type ApiCallResult<M extends Methods<R>, R extends RawApi> = R[M] extends (...args: unknown[]) => unknown ? Await<ReturnType<R[M]>> : never;
27
- declare type Await<T> = T extends PromiseLike<infer V> ? V : T;
26
+ declare type ApiCallResult<M extends Methods<R>, R extends RawApi> = R[M] extends (...args: unknown[]) => unknown ? Awaited<ReturnType<R[M]>> : never;
28
27
  /**
29
28
  * API call transformers are functions that can access and modify the method and
30
29
  * payload of an API call on the fly. This can be useful if you want to
@@ -18,7 +18,7 @@ class ApiClient {
18
18
  this.installedTransformers = [];
19
19
  this.call = async (method, p, signal) => {
20
20
  const payload = p !== null && p !== void 0 ? p : {};
21
- debug("Calling", method);
21
+ debug(`Calling ${method}`);
22
22
  // General config
23
23
  const opts = this.options;
24
24
  const formDataRequired = (0, payload_js_1.requiresFormDataUpload)(payload);
@@ -119,7 +119,7 @@ async function* payloadToMultipartItr(payload, boundary) {
119
119
  first = false;
120
120
  }
121
121
  // End multipart/form-data protocol
122
- yield enc.encode(`\r\n--${boundary}--`);
122
+ yield enc.encode(`\r\n--${boundary}--\r\n`);
123
123
  }
124
124
  /**
125
125
  * Replaces all instances of `InputFile` in a given payload by attach://
@@ -164,7 +164,7 @@ or newline (\\n) characters! Filename for property '${origin}' was:
164
164
  ${filename}
165
165
  """`);
166
166
  }
167
- yield enc.encode(`content-disposition:form-data;name="${id}";filename=${filename}\r\n\r\n`);
167
+ yield enc.encode(`content-disposition:form-data;name="${id}";filename=${filename}\r\ncontent-type:application/octet-stream\r\n\r\n`);
168
168
  const data = await input[platform_node_js_1.toRaw]();
169
169
  if (data instanceof Uint8Array)
170
170
  yield data;
@@ -22,7 +22,7 @@ export declare function baseFetchConfig(apiRoot: string): {
22
22
  /** Something that looks like a URL. */
23
23
  interface URLLike {
24
24
  /**
25
- * Identifier of the resouce. Must be in a format that can be parsed by the
25
+ * Identifier of the resource. Must be in a format that can be parsed by the
26
26
  * URL constructor.
27
27
  */
28
28
  url: string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "grammy",
3
3
  "description": "The Telegram Bot Framework.",
4
- "version": "1.8.0",
4
+ "version": "1.8.3",
5
5
  "author": "KnorpelSenf",
6
6
  "license": "MIT",
7
7
  "engines": {
@@ -30,7 +30,7 @@
30
30
  },
31
31
  "devDependencies": {
32
32
  "@types/debug": "^4.1.7",
33
- "@types/node": "^12.20.47",
33
+ "@types/node": "^12.20.50",
34
34
  "@types/node-fetch": "^2.6.1",
35
35
  "all-contributors-cli": "^6.20.0",
36
36
  "deno2node": "^1.3.0"