Create an Admin Panel with BJS
Create a Bots.Business Admin Panel with BJS, preserve saved values, read fields with getFieldValue or getPanelValues, and run a command after saving.
An Admin Panel is a form the bot owner can open in the app. Define its fields with BJS, then read the saved settings in your commands. If you only need to fill an existing form, start with using an Admin Panel.
Define new Admin Panel
Create a setup command /setup-panel on a bot you control. Run it once from a controlled owner/test context; do not expose configuration-reset commands to every user.
AdminPanel.setPanel({
panel_name: "welcome",
data: {
title: "Welcome settings",
description: "Text used by the welcome command.",
index: 0,
button_title: "Save",
fields: [
{
name: "welcome_text",
title: "Welcome message",
type: "string",
placeholder: "Enter a short greeting",
value: "Welcome!"
},
{
name: "show_help",
title: "Show the help command",
type: "checkbox",
value: true
}
]
}
});
Bot.sendMessage("Open Admin Panel in the app to edit the welcome settings.");Open the bot's Admin Panel in the app, change the text, and save. Then use a separate /welcome command to read it.
Panel and field options
panel_name
Stable internal panel name used by BJS reads
data.title, data.description
User-facing title and explanation
data.index
Ordering hint for the panel
data.button_title
Save/action button label
data.fields
Array of field definitions
Field name
Stable key used by getFieldValue
Field title, description, placeholder
Explain what the owner should enter
Field value
Initial value, or replacement value when forced
Field type
string, text, integer, float, password, or checkbox
Field hidden
Hide the field from the form; not an access-control rule
A checkbox is an on/off control. Integer/float fields accept numeric input; a password field masks its displayed value. Masking does not make it safe to publish the value in bot messages or share access to the whole bot.
Force
AdminPanel.setPanel preserves existing values for fields with the same name unless you pass force: true. This lets you change labels or add a field without resetting the owner's settings.
Use force: true only for an intentional reset. Renaming a field creates a different key, so migrate its saved value deliberately. Saving a single field is usually safer than replacing the whole panel.
Setting field value to Panel
An existing field returns true when its update action is created. This method does not create a missing panel or a missing field. Read the value in a later command when checking durable storage.
AdminPanel.getPanel("welcome") returns the full panel definition. AdminPanel.getPanelField({panel_name: "welcome", field_name: "welcome_text"}) returns a field definition. Do not expose these whole objects when a panel contains secrets.
Run a command on saving
Add on_saving inside data when defining the panel:
Create /refresh-welcome:
This fragment belongs in the full data object above. The save action runs the named command after storing the panel. If the command needs a user, provide that user's internal user_id in on_saving. Do not assume an app save has the same Telegram context as a chat message.
Troubleshooting
If the form is missing, verify the setup command ran successfully and the correct bot is open. If a new default did not appear, existing values were probably preserved intentionally. If a read is undefined, compare panel_name and field name, including case. If save succeeds but follow-up work fails, check the callback command and its required context in BJS errors.
Next: properties, caching, or the distinct BBAdmin API.
Last updated
Was this helpful?