Class Dispatcher<State>

Updates dispatcher

Type Parameters

  • State extends object = never

Hierarchy (view full)

Constructors

Accessors

Methods

  • 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.

    Parameters

    Returns void

  • 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

    Parameters

    • scene: Dispatcher<State>

      Dispatcher representing the scene

    • scoped: false

      Whether to use scoped FSM storage for the scene

    Returns void

  • 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

    Parameters

    • scene: Dispatcher<any>

      Dispatcher representing the scene

    • Optionalscoped: true

      Whether to use scoped FSM storage for the scene (defaults to true)

    Returns void

  • 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.

    Parameters

    • children: boolean = false

      Whether to also clone children and scenes

    Returns Dispatcher<State>

  • Destroy the dispatcher and all its children.

    When destroying, all the registered handlers are removed, and the underlying storage is freed.

    Returns Promise<void>

  • 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 awaiting this method you can be certain that the update was fully processed by all the registered handlers, including children.

    Parameters

    Returns Promise<boolean>

    Whether the update was handled

  • 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 awaiting this method you can be certain that the update was fully processed by all the registered handlers, including children.

    Parameters

    Returns Promise<boolean>

    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.

    Parameters

    Returns void

  • 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.

    Type Parameters

    • T = {}

    Parameters

    Returns void

  • 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.

    Type Parameters

    • T = {}

    Parameters

    Returns void

  • 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.

    Type Parameters

    • T = {}

    Parameters

    Returns void

  • 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 used
    • Continue same as Stop, but still dispatch the update to children
    • ToScene to prevent the transition and dispatch the update to the scene entered in the transition handler

    Note: if multiple state.enter() calls were made within the same update, this handler will only be called for the last one.

    Parameters

    Returns void

  • 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.

    Parameters

    Returns void

  • Remove an update handler (or handlers) from a given handler group.

    Parameters

    • handler:
          | "poll"
          | "raw"
          | "story"
          | "new_message"
          | "edit_message"
          | "message_group"
          | "delete_message"
          | "chat_member"
          | "inline_query"
          | "chosen_inline_result"
          | "callback_query"
          | "inline_callback_query"
          | "business_callback_query"
          | "poll_vote"
          | "user_status"
          | "user_typing"
          | "history_read"
          | "bot_stopped"
          | "bot_chat_join_request"
          | "chat_join_request"
          | "pre_checkout_query"
          | "delete_story"
          | "bot_reaction"
          | "bot_reaction_count"
          | "business_connection"
          | "new_business_message"
          | "edit_business_message"
          | "business_message_group"
          | "delete_business_message"
          | "all"
          | UpdateHandler

      Update handler to remove, its name or 'all' to remove all

    • group: null | number = 0

      Handler group index (null to affect all groups)

    Returns void