Documentation - v0.27.2
    Preparing search index...

    Class CallbackDataBuilder<T>

    Callback data builder, inspired by aiogram.

    This can be used to simplify management of different callbacks.

    Learn more in the docs

    Type Parameters

    • T extends string
    Index

    Constructors

    Properties

    Methods

    Constructors

    Properties

    prefix: string

    Prefix for the data. Use something unique across your bot.

    sep: string = ':'

    Methods

    • Create a filter for this callback data.

      You can either pass an object with field names as keys and values as strings or regexes, which will be compiled to a RegExp, or a function that will be called with the parsed data. Note that the strings will be passed to RegExp directly, so you may want to escape them.

      When using a function, you can either return a boolean, or an object with field names as keys and values as strings or regexes. In the latter case, the resulting object will be matched against the parsed data the same way as if you passed it directly.

      Type Parameters

      Parameters

      • params:
            | Partial<Record<T, MaybeArray<string | RegExp>>>
            | (
                (
                    upd: Update,
                    parsed: Record<T, string>,
                ) => MaybePromise<
                    boolean
                    | Partial<Record<T, MaybeArray<string | RegExp>>>,
                >
            ) = {}

      Returns filters.UpdateFilter<Update, { match: Record<T, string> }>

    • Parse callback data to object

      Parameters

      • data: string

        Callback data as string

      • Optionalsafe: false

        If true, will return null instead of throwing on invalid data

      Returns Record<T, string>

    • Parse callback data to object

      Parameters

      • data: string

        Callback data as string

      • safe: true

        If true, will return null instead of throwing on invalid data

      Returns Record<T, string> | null