Admin Panel
​
You can create a custom admin panel.
  • make custom data fields: numeric, text, checkbox, password
  • data fields will be accessible in BJS
  • admin panels can be created via BJS
  • bot run customized command on field saving
  • supports severals panels with titles and differents fields
Benefits:
  • making options for saving any api keys, secure and unsecure data
  • can run any BJS logic from panel. For example: it will be possible create text field with button "Send this message to all chats" from App.
  • make any quick statistic and information. Bot dashboards and etc

Methods

Define new Admin Panel

Admin Panel - this is a combination of several panels. Each panel have title, icon, description and one or more fields:
For adding panel:
AdminPanel.setPanel({ panel_name: PANEL_NAME, data: PANEL_OPTIONS });
PANEL_OPTIONS - it is JSON option for this panel
Example
1
var panel = {
2
// Panel title
3
title: "Admin Information",
4
description: "Please fill here your admin id",
5
// order index
6
index: 0,
7
icon: "key",
8
// save button title - default "SAVE"
9
button_title: "SAVE",
10
// command called on saving
11
// not necessary
12
/* on_saving:{
13
command: "/on-saving",
14
// if you need user
15
user_id: user_id // Get it via Bot.sendMessage(user.id)
16
},
17
*/
18
19
// Fields for this Panel
20
// here 1 field only
21
fields: [
22
{
23
name: "ADMIN_ID",
24
title: "Admin ID",
25
description: "you can get your admin_id with BJS Bot.sendMessage(user.id)",
26
type: "string",
27
placeholder: "your admin id",
28
// value: 100, // default value
29
// hidden: true // if you need hidden field. By default - false
30
}
31
// another fields here
32
// if needed
33
// ...
34
]
35
}
36
​
37
AdminPanel.setPanel({
38
panel_name: "AdminInfo",
39
data: panel
40
// force: true // default false - save fields values
41
});
Copied!

Force

Default is false. All old values for the fields are retained.
If true - all old values for fields are reassigned.

Fields

It is array of fields. One panel can have several fields. It is also possible panel without any field.
Fields can have name, value, title, description, type, placeholder and icon

Field type

Type
Description
checkbox
Text input
integer
Text input
float
Text input
string
Text input
password
Password input
text
Text field

​

Getting field value from Panel

Use this method for getting one value from panel
1
var admin_id = AdminPanel.getFieldValue({
2
panel_name: "AdminInfo", // panel name
3
field_name: "ADMIN_ID" // field name
4
})
5
​
6
Bot.sendMessage(admin_id)
Copied!
​

Setting field value to Panel

Use this method for setting one value to panel
1
var result = AdminPanel.setFieldValue({
2
panel_name: "AdminInfo", // panel name
3
field_name: "ADMIN_ID", // field name
4
value: 15236125
5
})
6
​
7
Bot.sendMessage(result) // true
Copied!

​

Getting all fields values from Panel

Use this method for getting several/all values from panel
1
var values = AdminPanel.getPanelValues("AdminInfo");
2
Bot.inspect(values);
3
// will be like:
4
// { ADMIN_ID: 100 }
Copied!

Getting panel data

1
var panel = AdminPanel.getPanel("AdminInfo")
2
Bot.inspect(panel);
3
​
4
// can modify panel
5
// panel.fields[0].value = 1000
6
// panel.fields[0].tite = "my admin id"
7
// AdminPanel.setPanel("AdminInfo", panel);
Copied!

​

Getting panel field data

1
var panel_field = AdminPanel.getPanelField({
2
panel_name: "AdminInfo", // panel name
3
field_name: "ADMIN_ID" // field name
4
})
5
​
6
Bot.inspect(panel_field);
Copied!

Icons

You can use all icons from https://ionicons.com​
​

Good practices

Use admin panels to create a configuration
Define Admin Panels in /config command with AdminPanel.setPanel method.
Then use AdminPanel.getPanelValue method for getting any field's value
​
Use admin panels to create a bot dashboard
Panel without fields can dispay any informations. Use this.
​
Use admin panels to create admin reactions
You can launch any bot command on panel saving. It is good for making any admin command execution. Use on_saving:
1
var panel = {
2
// Panel title
3
title: "Call secure command",
4
description: "It is secure command",
5
// order index
6
index: 0,
7
icon: "key",
8
// save button title - default "SAVE"
9
button_title: "RUN",
10
// command called on saving
11
// not necessary
12
on_saving: {
13
command: "/secure-command",
14
// if you need user
15
user_id: user_id // Get it via Bot.sendMessage(user.id)
16
}
17
}
18
​
19
AdminPanel.setPanel("SecureCommand", panel);
Copied!
Last modified 1yr ago