Bot functions
Function | Description |
Bot.runCommand(command, options) | Run other command Bot.runCommand("/contact")
and with options: Bot.runCommand("/contact", {phone: "+15424", email: "[email protected]"})
in second command /contact: Bot.sendMessage("Phone is:" + options.phone); |
Bot.run(options) | |
Bot.clearRunAfter(options) | |
Bot.runAll(options) | |
Bot.sendKeyboard(buttons, message) | send keyboard and message. Message is required Bot.sendKeyboard("about, help,\ncontacts", "send keyboard now") |
Bot.sendInlineKeyboard(buttons, message) | Send inline keyboard and message. Message is required. Buttons is array. Button must have text fields: title(required), url or command. Bot.sendInlineKeyboard([ {title: "google", url: "http://google.com" }, {title: "other command", command: "/othercommand"} ], "Please make a choice.") |
Bot.sendInlineKeyboardToChatWithId(chat_id, buttons, message) | Send inline keyboard and message to chat with chat_id Bot.sendInlineKeyboard('852378745487', [ {title: "google", url: "http://google.com" }, {title: "other command", command: "/othercommand"} ], "Please make a choice.") |
Bot.editInlineKeyboard(buttons) | Edit exist inline keyboard after executing the command that was called by its button Bot.editInlineKeyboard([ {title: "google", url: "http://google.com" } ]) |
Bot.editInlineKeyboard(buttons, message_id, chat_id) | Edit exist inline keyboard for message with message_id in the chat with chat_id. If chat_id is blank current chat is used Bot.editInlineKeyboard([ {title: "google", url: "http://google.com" } ], request.message.message_id, chat.id) |
Bot.setProperty(name, value, type) | Bot.setProperty("TotalScore", 100, "integer") Type can be: integer, float, string, text, json, datetime |
Bot.getProperty(name) | Bot.getProperty("TotalScore") can get property with default value for non exist property: Bot.getProperty("TotalScore", 100)
can get property of another bot:
Bot.getProperty({ name: "propName", other_bot_id: OTHER_BOT_ID }) |
Bot.importCSV() | |
Bot.blockChat(chat_id) | Block chat: Bot.blockChat(chat.id) |
Bot.unblockChat(chat_id) | Unblock chat: Bot.unblockChat(chat.id) |
Bot.inspect(value) | Send inspected value to chat. Good for debug |
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>")
Run other command
Bot.run(params)
Field | Description |
command | Required. Command for run. For example "/start". Can pass params |
options | json for passing to command. Available through options in this command |
run_after | delay in seconds before command callingName is case sensitive. |
bot_id | bot_id for passing. By default this is current bot.id |
user_id | user_id for passing. By default this is current user.id |
chat_id | chat_id for passing. By default this is current chat.id |
label | can be used for clearing with Bot.clearRunAfter |
Example 1. Run another command
/balance
with delay 1 hour for current userBot.run( {
command: "/balance",
run_after: 1*60*60, // 1 hour delay
// label: "runBalance" // label can be used for remove future calling
} )
Example 2. Run another command
/balance
with delay 5 days for this userBot.run( {
command: "/balance",
run_after: 60*60*24*5, // 5 days delay
// options: { amount: 5, currency: "BTC" } // you can pass data
chat_id: chat.id // or use another chat_id
user_id: user.id // or use another user.id
// bot_id: ANOTHER_BOT_ID // to run command for your another bot
} )
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.
Can clear future command(s) execution setted by Bot.run
Use this function if future command calling not needed already
// delete all future commands executions
Bot.clearRunAfter()
// delete all future commands executions with label "myLabel"
Bot.clearRunAfter({ label: "myLabel"})
Field | Description |
label | Required. Command for clearing. For example "myLabel" |
Example 1. Run another command
/work
with delay 5 days. And remove that delay (for example on 3th day)Bot.run( {
command: "/balance",
run_after: 60*60*24*5, // 5 days delay
label: "myLabel"
} )
On the third day we learned that the call is no longer needed:
// remove all future executions with label "mylabel"
Bot.clearRunAfter( {
label: "myLabel"
} )
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.
Bot.runAll(params)
Field | Description |
command | Required. Command for run. For example "/start". Can pass params |
options | json for passing to command. Available through options in this command |
on_create | run this command on task creation with task information |
for_chats | Command will be runned for this chats type only. Can be: "private-chats" "group-chats" "super-group-chats" "all" - default |
Example:
Command:
/news
Bot.runAll( {
// this command will be executed
// for each private chat (user)
command: "/broadcast",
for_chats: "private-chats",
on_create: "on_new_brodcast_task",
// options: { any_data: "here" }
} )
Command:
/broadcast
// it have user and chat object!
// so we can send any information now: message, keyboard, photo and etc
Bot.sendKeyboard("New news", "hello!")
// we can get brodcast task info
/*
let task = options.task;
Bot.sendMessage(
"Task progress: " + task.progress +
"\n total: " + task.total +
"\n cur index: " + task.cur_position +
"\n status: " + task.status +
"\n errors: " + task.errors_count
)
*/
Command:
on_new_brodcast_task
var task = options.run_all_task;
Bot.sendMessage(
"Task for brodcasting created. Task id: " + task.id
);
// save task id:
Bot.setProperty("curBrodcastTaskID", task.id, "integer")
// Bot.inspect(options.run_all_task);
Command:
/progress
// show current runAll progress
var taskID = Bot.getProperty("curBrodcastTaskID");
var task = new RunAllTask({ id: taskID });
// Bot.inspect(task) // you can check all fields
if(!task.status){
Bot.sendMessage("This task not found")
return
}
Bot.sendMessage(
"Current brodcast: " +
"/n Status: " + task.status + " " + task.progress + "%" +
"/n Progress:" + task.cur_position + "/" + task.total
)
Last modified 1yr ago