Bots.Business - Help
  • Welcome
  • Getting started
  • Create bot from Google Table
  • App
    • Reset or Update Your Password
  • Commands
    • Answer
    • Aliases
    • Keyboard
    • Groups
    • Wait for answer
    • Auto Retry (AR)
  • Coding: BJS
    • Variables
    • Bot functions
    • Message broadcasting and editing
    • User functions
    • Properties
    • Always running commands
    • Error command: "!"
    • Lists
      • Migration from properties to list
    • Api functions
    • BB Admin functions
    • Admin Panel
    • Send HTTP request
    • Web App
    • Caching
    • Inline Bot
    • BJS Security
    • Good coding practices
    • Top errors
  • Git
    • Import bot from Git repository
    • Export bot to Git repository
    • Repository structure
    • File: bot.json
    • Automatic importing on Git push
  • Iterations. How to reduce theys?
  • Limitations
  • Cloud
  • Reports
  • Deep Linking - pass any params on Bot starting
  • How to link chat account with BB account?
  • BB Inspection
  • Protected bot
  • VS Code
  • How to...
  • Smart Bot
    • Overview
    • Lang File
    • SmartBot
    • SmartTasker
    • Amount Dialog
  • Libs
    • What it is - Libs?
    • Libs development
    • RefferalLib
    • ResourcesLib
    • Random
    • MembershipChecker (MCL)
    • Cooldown Lib
    • CurrencyConverter
    • Lang
    • TopBoardLib
    • QiwiPayments
    • Coinbase (CB)
    • CoinPayments (CP)
    • OxaPay
    • CryptoJS
    • CurrencyQuote
    • GoogleApp
    • GoogleTableSync
    • Guard
    • Webhooks lib
    • DateTimeFormat Lib
  • Store
    • BB Point Bot
    • Welcome bot
    • Help bot
    • SRB Demo Keyboard Tools
Powered by GitBook
On this page
  • Master command
  • All Updates
  • Example
  • BeforeAll and AfterAll commands

Was this helpful?

  1. Coding: BJS

Always running commands

PreviousPropertiesNextError command: "!"

Last updated 9 months ago

Was this helpful?

Sometimes code execution is always required.

Master command

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

Use * in command name.

All Updates

You can handle with Master Command

It is possible via request .

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

Please 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

updates
updates
variable