Properties

Introducing

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.

Types

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 property

1
// set global prop
2
Bot.setProperty({ name: 'myProp', value: 15 });
3
4
// set JSON prop for user
5
User.setProperty({
6
name: 'BIO',
7
value: { email: "[email protected]", age: 10 }
8
});
Copied!
  • so for global prop use Bot.xxx method
  • for user's prop use User.xxx method
also you can use old style:
1
// set global prop
2
Bot.setProperty("myProp", 15, "float" });
Copied!

Set prop for other user

1
// set global prop
2
Bot.setProperty({
3
name: 'otherUserProp',
4
value: "test Prop",
5
// you can pass other user.id for saving user prop for other user
6
user_id: other_user.id
7
});
Copied!

You can save prop in the List

Please read this article

Get property

1
// get global prop
2
var myProp = Bot.getProperty('myProp');
3
4
// get prop for user
5
var bio = User.getProperty('BIO');
Copied!
or get prop with default value:
1
// prop by default will be 15
2
var myProp = Bot.getProperty('myProp', 15);
Copied!

Access to property in answer

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 in Bot.sendMessage("Hello, <UserRole>")

Getting other user's prop:

Your bot must have this user
1
// get prop for other user
2
var bio = Bot.getProperty({
3
name: 'BIO',
4
// you can pass other user.id for getting other user prop
5
user_id: other_user_id
6
});
Copied!

Getting other bot prop for current user:

Your account must have this bot
1
// get other bot prop for cur user
2
var bio = Bot.getProperty({
3
name: 'BIO',
4
other_bot_id: other_bot_id // available via bot.id
5
});
Copied!

Getting other bot prop for other user:

Your account must have this bot with this user
1
// get other bot prop for cur user
2
var bio = Bot.getProperty({
3
name: 'BIO',
4
other_bot_id: other_bot_id // available via bot.id
5
// you can pass other user.id for getting other user prop
6
user_id: other_user_id
7
});
Copied!

Delete property

Pass null to prop's value for property deleting:
1
// prop "myProp" with null value will be removed
2
Bot.setProperty("myProp", null, "float" });
Copied!