Always running commands

Sometimes code execution is always required.

Master command

This command executed only when there are no others commands or on updatesarrow-up-right for Telegram bot.

Use * in command name.

All Updates

circle-check

For inspect data you can use:

throw new Error(inspect(request))

then go to Error Tab and see data. Now you can use it via request.xxx.yyy

Example

Command *

// you can track any message here
if(message&&chat){
   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

BeforeAll and AfterAll commands

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 name

For AfterAll command use @@ in command name

triangle-exclamation
circle-info

You can share functions, variables and etc with BeforeAll and AfterAll commands. It is effective for common code parts.

triangle-exclamation

Last updated