Skip to content

Commit c7f4425

Browse files
committed
docs(readme): document UseOuter middleware and updated Predicate signature
Added a dedicated section for "Outer Middleware" in the README to explain the middleware lifecycle and pipeline execution order. BREAKING CHANGE: Updated examples and documentation to reflect that `Predicate` now accepts `*Context` instead of `*Update`.
1 parent 69faa52 commit c7f4425

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

docs/guide.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,27 @@ bot.Use(botapi.Recover(), botapi.Timeout(30*time.Second), botapi.Logging())
280280

281281
Built-ins: `Recover` (turns panics into errors), `Timeout`, `Logging`.
282282

283+
## Outer Middleware
284+
285+
An `OuterMiddleware` is also a `func(Handler) Handler`. Register global middleware
286+
that runs before route matching with `UseOuter`:
287+
```go
288+
bot.UseOuter(botapi.Recover(), ChatConfigMiddleware())
289+
```
290+
291+
See [`examples/middleware`](../examples/middleware) for a complete example
292+
showing how data flows from outer middleware to predicates and handlers.
293+
294+
### Pipeline Execution Order
295+
296+
Middlewares and handlers execute in a distinct lifecycle layer (from the outside in).
297+
The visualization below demonstrates how an update travels through the bot:
298+
299+
1. **`UseOuter`** (Always runs first; can short-circuit or inject data into `Context`).
300+
2. **`Predicate` matching** (Evaluates route guards; has access to data from `UseOuter`).
301+
3. **`Use`** (Runs only if a route matches; ideal for logging, telemetry, or lazy-loading user sessions).
302+
4. **`Handler`** (Your core business logic).
303+
283304
## Groups
284305

285306
`Group` scopes shared predicates and middleware to a subset of handlers:

0 commit comments

Comments
 (0)