Bot functions
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:Total score: <TotalScore>!
in BJS:
And you can use it inBot.sendMessage("<TotalScore>")
Bot.run(params)
Run other command
1
Bot.run(params)
Copied!
Example 1. Run another command
/balance
with delay 1 hour for current user1
Bot.run( {
2
command: "/balance",
3
run_after: 1*60*60, // 1 hour delay
4
// label: "runBalance" // label can be used for remove future calling
5
} )
Copied!
Example 2. Run another command
/balance
with delay 5 days for this user1
Bot.run( {
2
command: "/balance",
3
run_after: 60*60*24*5, // 5 days delay
4
// options: { amount: 5, currency: "BTC" } // you can pass data
5
chat_id: chat.id // or use another chat_id
6
user_id: user.id // or use another user.id
7
// bot_id: ANOTHER_BOT_ID // to run command for your another bot
8
} )
Copied!
You can not use chat.chatid and user.telegramid with Bot.run method.
Only chat.id or user.id
Store another chat.id or user.id to propertis if you can not pass it imeditally.
Bot.clearRunAfter(options)
Can clear future command(s) execution setted by Bot.run
Use this function if future command calling not needed already
1
// delete all future commands executions
2
Bot.clearRunAfter()
Copied!
1
// delete all future commands executions with label "myLabel"
2
Bot.clearRunAfter({ label: "myLabel"})
Copied!
Example 1. Run another command
/work
with delay 5 days. And remove that delay (for example on 3th day)1
Bot.run( {
2
command: "/balance",
3
run_after: 60*60*24*5, // 5 days delay
4
label: "myLabel"
5
} )
Copied!
On the third day we learned that the call is no longer needed:
1
// remove all future executions with label "mylabel"
2
Bot.clearRunAfter( {
3
label: "myLabel"
4
} )
Copied!
Bot.runAll(options)
Run other command for all chats
Use this command for broadcasting any information: message, photo, video, keyboard and etc
Bot.runAll works for worked bots only.
1
Bot.runAll(params)
Copied!
Example:
Command:
/news
1
Bot.runAll( {
2
// this command will be executed
3
// for each private chat (user)
4
command: "/broadcast",
5
for_chats: "private-chats",
6
on_create: "on_new_brodcast_task",
7
// options: { any_data: "here" }
8
} )
Copied!
Command:
/broadcast
1
// it have user and chat object!
2
// so we can send any information now: message, keyboard, photo and etc
3
4
Bot.sendKeyboard("New news", "hello!")
5
6
// we can get brodcast task info
7
/*
8
let task = options.task;
9
Bot.sendMessage(
10
"Task progress: " + task.progress +
11
"\n total: " + task.total +
12
"\n cur index: " + task.cur_position +
13
"\n status: " + task.status +
14
"\n errors: " + task.errors_count
15
)
16
*/
Copied!
Command:
on_new_brodcast_task
1
var task = options.run_all_task;
2
Bot.sendMessage(
3
"Task for brodcasting created. Task id: " + task.id
4
);
5
6
// save task id:
7
Bot.setProperty("curBrodcastTaskID", task.id, "integer")
8
9
// Bot.inspect(options.run_all_task);
Copied!
Command:
/progress
1
// show current runAll progress
2
3
var taskID = Bot.getProperty("curBrodcastTaskID");
4
var task = new RunAllTask({ id: taskID });
5
// Bot.inspect(task) // you can check all fields
6
7
if(!task.status){
8
Bot.sendMessage("This task not found")
9
return
10
}
11
12
Bot.sendMessage(
13
"Current brodcast: " +
14
"/n Status: " + task.status + " " + task.progress + "%" +
15
"/n Progress:" + task.cur_position + "/" + task.total
16
)
17
0 Comments