grammy 1.8.0 → 1.8.1

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 -->
@@ -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
@@ -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://
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.1",
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"