Bale: disabled buttons, topic chats and Mini Apps

Disabled inline buttons

Bale can show an inline button dimmed and inert: pressing it does nothing and no callback query is sent. In Bale’s wire format this is the presence of "disabled": {} on the button; peyk never sends null for unset fields, so a normal button is never disabled by accident.

from peyk.keyboard import InlineKeyboardBuilder

kb = (
    InlineKeyboardBuilder()
    .button(text="Buy", callback_data="buy")
    .button(text="Sold out", callback_data="x", disabled=True)
    .as_markup()
)
await bot.send_message(chat_id, "Shop", reply_markup=kb)

With the Bale client directly use InlineKeyboardButton(text=..., disabled=DisabledButton()).

Topic chats (forum topics)

Bale bots can talk to a user inside separate topics of the private chat (the bot’s topic chat mode must be enabled). A topic id is the message_thread_id of its messages.

topic = await bot.create_forum_topic(chat_id, "Support")      # Bale and Telegram
await bot.send_message(chat_id, "Hello!", message_thread_id=topic.message_thread_id)
await bot.edit_forum_topic(chat_id, topic.message_thread_id, "Help desk")
await bot.delete_forum_topic(chat_id, topic.message_thread_id)
  • Incoming messages expose message.message_thread_id (and on the raw Bale Message: forum_topic_created).

  • message.answer(), answer_photo() … automatically reply inside the same topic; pass message_thread_id= to override.

  • message_thread_id is accepted by the Bale send methods (text, photo, video, audio, voice, document, animation, media group, location, contact).

Mini Apps

The Mini App sends Bale.WebApp.initData to your backend. Verify the signature before trusting anything in it:

from peyk.platforms.bale.miniapp import verify_init_data, InvalidInitDataError

try:
    data = verify_init_data(init_data, BOT_TOKEN, max_age=3600)
except InvalidInitDataError:
    ...  # reject the request
user_id = data.user["id"]
start_param = data.start_param

The signature follows Bale’s documented scheme: secret = HMAC_SHA256(key="WebAppData", message=bot_token) and hash = hex(HMAC_SHA256(key=secret, message=data_check_string)) where data_check_string is every field except hash as sorted key=value lines.

Open the Mini App from a button with web_app:

InlineKeyboardBuilder().button(text="Open", web_app_url="https://example.com/app")

User.has_main_web_app (from get_me) tells whether the bot has a main Mini App.