telebot-ts API Documentation - v1.0.0
    Preparing search index...

    Class Menu

    Index
    • Constructs a new Menu instance.

      Parameters

      • id: string

        Unique string identifier for the menu.

      Returns Menu

    id: string

    Unique string identifier for this menu.

    parent?: Menu

    Reference to the parent Menu if this instance is a submenu.

    • Appends a back button that returns to the parent menu.

      Parameters

      • label: MenuLabel = "Back"

        Button label text (default: "Back").

      • OptionalonNavigate: MenuNavigationHandler

        Optional callback hook executed before navigating back.

      Returns this

      This Menu instance for chaining.

      subMenu.back("Go Back");
      
    • Synchronously builds the InlineKeyboardMarkup for this menu.

      Parameters

      • Optionalctx: CallbackContext<
            Record<string, unknown>,
            Record<string, unknown>,
            Record<string, unknown>,
        >

        Optional CallbackContext for dynamic label resolution.

      Returns InlineKeyboardMarkup

      Constructed inline keyboard markup.

      await ctx.reply("Choose an option:", {
      reply_markup: menu.build(ctx),
      });
    • Finds a menu instance by its identifier anywhere in this menu's hierarchy.

      Parameters

      • menuId: string

        Identifier of the menu to locate.

      • visited: Set<Menu> = ...

        Internal set of visited menus to avoid cycles.

      Returns Menu | undefined

      The matching Menu instance or undefined.

    • Creates a MiddlewareFn that automatically intercepts matching callback queries, dispatches button handlers, and performs in-place menu navigation.

      Returns MiddlewareFn

      A middleware function for use with app.use().

    • Advances the menu builder to start a new row of buttons.

      Returns this

      This Menu instance for chaining.

    • Appends a navigation button leading to a child Menu.

      Parameters

      • label: MenuLabel

        Static string label or dynamic label function.

      • targetMenu: Menu

        The destination submenu to open.

      • OptionalonNavigate: MenuNavigationHandler

        Optional callback hook executed before switching menus.

      Returns this

      This Menu instance for chaining.

      menu.submenu("Preferences", preferencesMenu);
      
    • Appends an interactive callback button with a click handler to the current row.

      Parameters

      • label: MenuLabel

        Static string label or dynamic label function.

      • handler: MenuButtonHandler

        Callback function executed when the button is clicked.

      Returns this

      This Menu instance for chaining.

      menu.text("Click Me", async (ctx) => {
      await ctx.reply("Button clicked!");
      });
    • Appends an external URL button to the current row.

      Parameters

      • label: MenuLabel

        Static string label or dynamic label function.

      • url: string

        HTTP or tg:// URL opened when the button is clicked.

      Returns this

      This Menu instance for chaining.