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
  • What it is - "iteration"?
  • Extra Points
  • How to get more iterations?
  • How to reduce iterations count?
  • Beware of endless loops
  • Beware of big loops

Was this helpful?

Iterations. How to reduce theys?

PreviousAutomatic importing on Git pushNextLimitations

Last updated 1 year ago

Was this helpful?

All iterations on Bots.Business are paid. You can choose payment plan with different iterations count.

What it is - "iteration"?

Each payment plan has its own iteration limit.

1 iteration it is:

  • income message to bot

  • (command) or Bot.run in the BJS spent 1 iteration

  • Bot.run with run_after spent 2 iterations (1 upon installation and 1 on execution)

  • Pressing the keyboard button

  • Pressing the inline keyboard button

  • 1 Auto Retry - it is 1 iteration

  • 1 received webhook - it is 1 iteration

  • 1 chats in command - 1 iteration

  • 1 sended message on mass broadcasting - 1 iteration

  • 5 chats on (in Bot dashboard) - spend 1 iteration

  • 100 incoming messages in blocked chat with method Bot.blockChat(chat.id)

5 iterations it is:

Single command execution - 1 iteration

Iterations are restored every month. Each payment plan has its own iteration limit.

Extra Points

  • If you do not have enough iterations, Extra Points are spent.

  • Unused Extra Points remain for the next month.

How to get more iterations?

You can upgrade your Plan, buy Extra Points or order BB Cloud with unlimited iterations.

How to reduce iterations count?

Reduce income messages to bot:

  • remove it from super groups

  • remove un useful commands

Reduce Bot.runCommand in BJS

Beware of endless loops

Use Bot.runCommand, Bot.run, Bot.runAll carefully.

Example 1

Bad code example. Command /check

Bot.runCommand("/task")

Command /task

...
Bot.runCommand("/check")
...

So we have now scheduled /task in /check. But /task also have run for /check

You will end up in an infinite loop and your iterations will quickly end

Example 2

Bad code example. Command /check

Bot.run(command: "/task", run_after: 60*60)  // 1 hour delay

Command /task

...
Bot.runCommand("/check")
...

So we have now scheduled /task in /check with delay for 1 hour. But /task also have run for /check

But here we have delay for 1 hour. So we have 1 task per hour (and per user!). Is it good?

No! Because user can run /check command several times. For example 6 times in one minute. You will be have 6 background tasks during 1 hour instead of 1 tasks. Also any users can execute this command for several times.

You will end up in an infinite loop and your iterations will quickly end

Be very careful with Bot.run methods

Beware of big loops

Very bad example:

Command check:

var user = options.result.status
User.setProperty("status", user, "string")
if ((user == "member") | (user == "administrator") | (user == "creator")) {
  Bot.runCommand("join2")
  User.addToGroup("user")
}

if (user == "left") {
  Bot.sendMessage("*⚠️ Not Joined :- @Kjtricks_Official *")
}

Command join2

var channel = "@MyChanell1"
let id = user.telegramid;

Api.getChatMember({ chat_id: channel, user_id: id, on_result: "check2" })

Command check2

var user = options.result.status
User.setProperty("status", user, "string")
if ((user == "member") | (user == "administrator") | (user == "creator")) {
  Bot.runCommand("join3")
  User.addToGroup("user")
}

if (user == "left") {
  Bot.sendMessage("*⚠️ Not Joined :- @Kjtricks_Official *")
}

and etc!

join1 > check1 > join2 > check2 > .... join10 > check10

What is problem?

  • each Api.getChatMember spent 1 - 3 sec for execution

  • Bot.runCommand run new BJS immediately!

We have 10 join + 10 check. So it will be 10 - 30 secs per 1 message from 1 user.

  • On Nano Cloud second user must wait this 30 secs! Also even Business Cloud is completely down!

  • each Bot.runCommand burn 1 iterations. We have 20 iterations here!

Fix

  • Do not use Bot.run in chain. It is not good.

- spend 5 iterations

Git / - spend 5 iterations

You can get Extra Points for 💎 BB Points or .

Reduce calls

Use

Use with run_after. It run task in background (Users don't have to wait)

Bot.runCommand
Bot.runAll
Information refreshing
CSV import
import
export
buy them
Auto Retry
MCLib
Bot.run