Always running commands
Sometimes code execution is always required.
Just use
*
in command name. Example.
Command
*
// you can track any message here
if(message){
Bot.sendMessage("Sorry, bot don't have this command: " + message);
return
}
// you can see all updated data by:
// Bot.inspect(request);
if(request.edit_date){
// user edited message
Bot.sendMessage("Text edited to:" + request.new_text);
// Please note:
// we have request.new_text not request.text here
// for backward compatibility
// request.text will be nil!
}
// chat title changed
if(request.new_chat_title){
Bot.sendMessage("New chat title is:" + request.new_chat_title);
}
// another possible updates in:
// https://core.telegram.org/bots/api#message
Code of this commands executed always before (and after) all others commands codes.
Example. You need add important alert in all commands. You can create only one BeforeAll command with code
Bot.sendMessage("Important alert")
For
BeforeAll
command use @
in command nameFor
AfterAll
command use @@
in command namePlease note. Only BJS for
BeforeAll
and AfterAll
commands runned. No any answer and keyboard here.You can share functions, variables and etc with
BeforeAll
and AfterAll
commands. It is effective for common code parts.// code for @ BeforeAll command
function myName(){
return "Peter"
}
// code for /test command
Bot.sendMessage(
myName() // result will be "Peter"
)
// myName is defined in BeforeAll command
Please note. If you need
*
, @
, @@ as command names you can use it in aliases
Last modified 1mo ago