Protected
constructorOptional
client: TelegramClientOptional
params: DispatcherParamsGet the dependencies injected into this dispatcher.
Get parent dispatcher if current dispatcher is a child.
Otherwise, return null
For scene dispatchers, name of the scene
Add a child dispatcher.
Child dispatchers are called when dispatching updates
just like normal, except they can be controlled
externally. Additionally, child dispatcher have their own
independent handler grouping that does not interfere with parent's,
including StopPropagation
(i.e. returning StopPropagation
will
still call children. To entirely stop, use StopChildrenPropagation
)
Note that child dispatchers share the same TelegramClient and storage binding as the parent, don't bind them manually.
Other dispatcher
Add a dispatcher as a scene with a non-scoped state.
Scoped storage for a scene means that the scene will have its own storage, that is only available within the scene and does not interfere with global state. Non-scoped, on the other hand, is the same state as the one used for the root dispatcher
Dispatcher representing the scene
Whether to use scoped FSM storage for the scene
Add a dispatcher as a scene with a scoped state
Scoped storage for a scene means that the scene will have its own storage, that is only available within the scene and does not interfere with global state. Non-scoped, on the other hand, is the same state as the one used for the root dispatcher
Dispatcher representing the scene
Optional
scoped: trueWhether to use scoped FSM storage for the scene (defaults to true
)
Add an update handler to a given handlers group
Update handler
Handler group index
Bind the dispatcher to the client.
Called by the constructor automatically if
client
was passed.
Dispatcher also uses bound client to throw errors
Create a clone of this dispatcher, that has the same handlers, but is not bound to a client or to a parent dispatcher.
Custom Storage and key delegate are copied too.
By default, child dispatchers (and scenes) are ignored, since that requires cloning every single one of them recursively and then binding them back.
Whether to also clone children and scenes
Process a raw update with this dispatcher. Calling this method without bound client will not work.
Under the hood asynchronously calls dispatchRawUpdateNow with error handler set to client's one.
Update to process
Peers index
Process a raw update right now in the current stack.
Unlike dispatchRawUpdate, this does not schedule
the update to be dispatched, but dispatches it immediately,
and after await
ing this method you can be certain that the update
was fully processed by all the registered handlers, including children.
Update to process
Peers map
Whether the update was handled
Process an update with this dispatcher. Calling this method without bound client will not work.
Under the hood asynchronously calls dispatchUpdateNow with error handler set to client's one.
Update to process
Process an update right now in the current stack.
Unlike dispatchUpdate, this does not schedule
the update to be dispatched, but dispatches it immediately,
and after await
ing this method you can be certain that the update
was fully processed by all the registered handlers, including children.
Update to process
Whether the update was handled
Extend current dispatcher by copying other dispatcher's handlers and children to the current.
This might be more efficient for simple cases, but do note that the handler
groups, children and scenes will get merged (unlike addChild,
where they are independent). Also note that unlike with children,
when adding handlers to other
after you extended
the current dispatcher, changes will not be applied.
Other dispatcher
Get global state.
This will load the state for the given object ignoring local custom storage, key delegate and scene scope.
Get update state object for the given key.
For custom keys, use prefix starting with $
to avoid
clashing with other keys (scene name can't start with $
)
State type, defaults to dispatcher's state type. Only checked at compile-time
State storage key
Get update state object for the given object.
Equivalent to getState(string)
, but derives
the key with the registered StateKeyDelegate,
and since it could be async, this method is async too.
State type, defaults to dispatcher's state type. Only checked at compile-time
Object for which the state should be fetched
Inject a dependency to be available in this dispatcher and all its children.
Note: This is only available for the root dispatcher.
Inject dependencies to be available in this dispatcher and all its children.
Note: This is only available for the root dispatcher.
Register an error handler.
This is used locally within this dispatcher (does not affect children/parent) whenever an error is thrown inside an update handler. Not used for raw update handlers
When an error is thrown, but there is no error
handler, it is propagated to TelegramClient
.
There can be at most one error handler.
Pass null
to remove it.
Error handler
Register post-update middleware.
This is used locally within this dispatcher (does not affect children/parent) after successfully processing an update, and can be used for stats.
There can be at most one post-update middleware.
Pass null
to remove it.
Pre-update middleware
Register pre-update middleware.
This is used locally within this dispatcher (does not affect children/parent) before processing an update, and can be used to skip this update.
There can be at most one pre-update middleware.
Pass null
to remove it.
Pre-update middleware
Register a scene transition handler
This handler is called whenever a scene transition occurs in the context of the scene that is being entered, and before any of the its own handlers are called, and can be used to customize the transition behavior:
Stop
to prevent dispatching the update any further even if ToScene/ToRoot was usedContinue
same as Stop, but still dispatch the update to childrenToScene
to prevent the transition and dispatch the update to the scene entered in the transition handlerNote: if multiple
state.enter()
calls were made within the same update, this handler will only be called for the last one.
Raw update handler
Set error handler that will propagate the error to the parent dispatcher
Optional
state: UpdateState<State>Remove a child dispatcher.
Removing child dispatcher will also remove child dispatcher's client binding.
If the provided dispatcher is not a child of current, this function will silently fail.
Other dispatcher
Remove an update handler (or handlers) from a given handler group.
Update handler to remove, its name or 'all'
to remove all
Handler group index (null to affect all groups)
Static
childCreate a new child dispatcher.
Optional
params: DispatcherParamsStatic
forCreate a new dispatcher and bind it to the client.
Rest
...args: [State] extends [never]Static
sceneCreate a new scene dispatcher
Optional
params: Omit<DispatcherParams, "sceneName">
Updates dispatcher