Properties
It is possible to save data in bot. Data can be numeric, text, datetime and etc.
For example:
- Bot can have DailyBonus saved in bot prop (it is global for all bot)
- User can have Balance saved in user prop (it is personall)
Properties can be belong for user or for bot.
Properties can be:
- integer, e.g.:
150
- float, e.g.:
5.5
- boolean:
true, false
- string, e.g.:
"Hello world"
- text, e.g.:
"it is very big text ..... 1000 symbols here or more"
- json, e.g.:
{ any: "data", here: "can", be: {used: true}, with: ["array", "too"] }
- datetime, e.g:
new Date()
// set global prop
Bot.setProperty({ name: 'myProp', value: 15 });
// set JSON prop for user
User.setProperty({
name: 'BIO',
value: { email: "[email protected]", age: 10 }
});
- so for global prop use
Bot.xxx
method - for user's prop use
User.xxx
method
also you can use old style:
// set global prop
Bot.setProperty("myProp", 15, "float" });
// set global prop
Bot.setProperty({
name: 'otherUserProp',
value: "test Prop",
// you can pass other user.id for saving user prop for other user
user_id: other_user.id
});
// get global prop
var myProp = Bot.getProperty('myProp');
// get prop for user
var bio = User.getProperty('BIO');
or get prop with default value:
// prop by default will be 15
var myProp = Bot.getProperty('myProp', 15);
You can also use the properties in the command's answer. For example, you can do this with the/hello
command:Hello, <UserRole>!
in BJS:
And you can use it inBot.sendMessage("Hello, <UserRole>")
Your bot must have this user
// get prop for other user
var bio = Bot.getProperty({
name: 'BIO',
// you can pass other user.id for getting other user prop
user_id: other_user_id
});
Your account must have this bot
// get other bot prop for cur user
var bio = Bot.getProperty({
name: 'BIO',
other_bot_id: other_bot_id // available via bot.id
});
Your account must have this bot with this user
// get other bot prop for cur user
var bio = Bot.getProperty({
name: 'BIO',
other_bot_id: other_bot_id // available via bot.id
// you can pass other user.id for getting other user prop
user_id: other_user_id
});
Pass
null
to prop's value for property deleting:// prop "myProp" with null value will be removed
Bot.setProperty("myProp", null, "float" });
Last modified 1yr ago