@monixlite/grammy-scenes 1.1.0 → 1.2.0

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.
Files changed (3) hide show
  1. package/README.md +27 -14
  2. package/package.json +1 -1
  3. package/src/index.js +12 -2
package/README.md CHANGED
@@ -41,9 +41,6 @@ const bot = new Bot("..."); {
41
41
  bot.use(session({
42
42
  initial: () => ({
43
43
  scene: null,
44
- step: null,
45
- name: null,
46
- age: null,
47
44
  }),
48
45
  }));
49
46
  };
@@ -179,6 +176,7 @@ Each scene step is described by the following structure:
179
176
 
180
177
  callbacks: {
181
178
  enter?: (ctx) => Promise<void>,
179
+ update?: (ctx) => Promise<SceneResult | void>,
182
180
  message?: (ctx) => Promise<SceneResult | void>,
183
181
  query?: Array<{
184
182
  match: RegExp,
@@ -207,20 +205,22 @@ Details:
207
205
 
208
206
  ---
209
207
 
210
- ### callbacks.message(ctx)
208
+ ### callbacks.update(ctx)
211
209
 
212
- Triggered when a text message is received while the step is active.
210
+ Triggered on **any update** while the step is active.
213
211
 
214
- The return value controls navigation:
212
+ Details:
215
213
 
216
- • `undefined` or `"next"` → move to the next step
217
- `"stop" | "exit" | "!"` → terminate the scene
218
- `"<" | "prev"` move to the previous step
219
- `">" | "next"` move to the next step
220
- • `"^step"` → jump to a step within the current scene
221
- • `"^scene:step"` → jump to another scene
222
- • `{ step: "..." }` → jump to a specific step
223
- `{ scene: { title, step } }` → jump to another scene
214
+ Executed before `message` and `query`
215
+ Receives the raw grammY context
216
+ Can be used for global step logic (timeouts, guards, media handling)
217
+ Return value controls navigation using standard SceneResult rules
218
+
219
+ ---
220
+
221
+ ### callbacks.message(ctx)
222
+
223
+ Triggered when a text message is received while the step is active.
224
224
 
225
225
  ---
226
226
 
@@ -305,6 +305,19 @@ Transitions are determined by the value returned from callbacks.
305
305
 
306
306
  ---
307
307
 
308
+ ### All Transitions
309
+
310
+ • `undefined` or `"next"` → move to the next step
311
+ • `"stop" | "exit" | "!"` → terminate the scene
312
+ • `"<" | "prev"` → move to the previous step
313
+ • `">" | "next"` → move to the next step
314
+ • `"^step"` → jump to a step within the current scene
315
+ • `"^scene:step"` → jump to another scene
316
+ • `{ step: "..." }` → jump to a specific step
317
+ • `{ scene: { title, step } }` → jump to another scene
318
+
319
+ ---
320
+
308
321
  ### Relative Transitions
309
322
 
310
323
  • `undefined` / `"next"` / `">"` → next step
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monixlite/grammy-scenes",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Scene middleware for grammY with step-based navigation",
5
5
  "main": "src/index.js",
6
6
  "type": "commonjs",
package/src/index.js CHANGED
@@ -171,14 +171,24 @@ class ScenesMiddleware {
171
171
  };
172
172
 
173
173
 
174
- if (ctx.message && current.callbacks.message) {
174
+ if (ctx?.update && current.callbacks?.update) {
175
+ const result = await current.callbacks.update(ctx);
176
+
177
+ return await this.handle(ctx, scene, result);
178
+ };
179
+
180
+
181
+ if (ctx?.message && current.callbacks?.message) {
182
+ if (ctx?.message?.caption) ctx.message.text ??= ctx.message.caption;
183
+
184
+
175
185
  const result = await current.callbacks.message(ctx);
176
186
 
177
187
  return await this.handle(ctx, scene, result);
178
188
  };
179
189
 
180
190
 
181
- if (ctx.callbackQuery && current.callbacks.query) {
191
+ if (ctx?.callbackQuery && current.callbacks?.query) {
182
192
  const data = ctx.callbackQuery.data;
183
193
 
184
194