Preprocess the event. This is where middleware can modify the event before it is processed. Each middleware is called in the order it was added to the app. If a middleware returns an update, the event is not processed and the update is returned. Args:
(self, state: BaseState, event: Event)
| 269 | return self._state_manager |
| 270 | |
| 271 | async def preprocess(self, state: BaseState, event: Event) -> StateUpdate | None: |
| 272 | """Preprocess the event. |
| 273 | |
| 274 | This is where middleware can modify the event before it is processed. |
| 275 | Each middleware is called in the order it was added to the app. |
| 276 | |
| 277 | If a middleware returns an update, the event is not processed and the |
| 278 | update is returned. |
| 279 | |
| 280 | Args: |
| 281 | state: The state to preprocess. |
| 282 | event: The event to preprocess. |
| 283 | |
| 284 | Returns: |
| 285 | An optional state to return. |
| 286 | """ |
| 287 | for middleware in self.middleware: |
| 288 | if asyncio.iscoroutinefunction(middleware.preprocess): |
| 289 | out = await middleware.preprocess(app=self, state=state, event=event) # type: ignore |
| 290 | else: |
| 291 | out = middleware.preprocess(app=self, state=state, event=event) # type: ignore |
| 292 | if out is not None: |
| 293 | return out # type: ignore |
| 294 | |
| 295 | async def postprocess( |
| 296 | self, state: BaseState, event: Event, update: StateUpdate |
no outgoing calls